Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add created_at Datetime Column To Migrations #53114

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function getMigrationBatches()
*/
public function log($file, $batch)
{
$record = ['migration' => $file, 'batch' => $batch];
$record = ['migration' => $file, 'batch' => $batch, 'created_at' => now()];

$this->table()->insert($record);
}
Expand Down Expand Up @@ -169,6 +169,7 @@ public function createRepository()
$table->increments('id');
$table->string('migration');
$table->integer('batch');
$table->dateTime('created_at');
});
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Database/DatabaseMigrationRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Mockery as m;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -53,12 +54,14 @@ public function testGetLastMigrationsGetsAllMigrationsWithTheLatestBatchNumber()

public function testLogMethodInsertsRecordIntoMigrationTable()
{
Carbon::setTestNow(now());

$repo = $this->getRepository();
$query = m::mock(stdClass::class);
$connectionMock = m::mock(Connection::class);
$repo->getConnectionResolver()->shouldReceive('connection')->with(null)->andReturn($connectionMock);
$repo->getConnection()->shouldReceive('table')->once()->with('migrations')->andReturn($query);
$query->shouldReceive('insert')->once()->with(['migration' => 'bar', 'batch' => 1]);
$query->shouldReceive('insert')->once()->with(['migration' => 'bar', 'batch' => 1, 'created_at' => now()]);
$query->shouldReceive('useWritePdo')->once()->andReturn($query);

$repo->log('bar', 1);
Expand Down
Loading