Skip to content
Merged
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
],
"require": {
"ext-mbstring": "*",
"php": "~7.3|~8.0.0|~8.1.0|~8.2.0|~8.3.0|~8.4.0",
"laravel/framework": "^8.0|^9.0|^10.0|^11.0|^12"
},
Expand Down
11 changes: 9 additions & 2 deletions src/Commands/MigrateDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,16 @@ private static function sqliteSchemaDump(array $db_config, string $schema_sql_pa
}

if ($migrationsTable === $table) {
$insert_rows = array_slice($output, 4, -1);
$insert_rows = array_filter(
$output,
function ($line) {
return 0 !== preg_match('/^\s*(INSERT INTO\s)/iu', $line)
&& 0 < mb_strlen($line);
}
);

$sorted = self::reorderMigrationRows($insert_rows);
array_splice($output, 4, -1, $sorted);
array_splice($output, array_key_first($insert_rows), -1, $sorted);
}

file_put_contents(
Expand Down
3 changes: 2 additions & 1 deletion tests/Mysql/MigrateDumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function test_handle()
$this->assertFileExists($this->schemaSqlPath);
$result_sql = file_get_contents($this->schemaSqlPath);
$this->assertMatchesRegularExpression("/CREATE TABLE [\`\"]{$this->dbPrefix}test_ms[\`\"]/", $result_sql);
$this->assertMatchesRegularExpression("/INSERT INTO [\`\"]{$this->dbPrefix}migrations[\`\"]/", $result_sql);
$this->assertStringContainsString("INSERT INTO `{$this->dbPrefix}migrations` VALUES (1,'0000_00_00_000000_create_test_tables',0);", $result_sql);
$this->assertStringContainsString("INSERT INTO `{$this->dbPrefix}migrations` VALUES (2,'0000_00_00_000001_second_migration_for_testing',0);", $result_sql);
$this->assertStringNotContainsString(' AUTO_INCREMENT=', $result_sql);
$last_character = mb_substr($result_sql, -1);
$this->assertMatchesRegularExpression("/[\r\n]\z/mu", $last_character);
Expand Down
3 changes: 2 additions & 1 deletion tests/Postgresql/MigrateDumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public function test_handle()
$this->assertFileExists($this->schemaSqlPath);
$result_sql = file_get_contents($this->schemaSqlPath);
$this->assertMatchesRegularExpression("/CREATE TABLE (public\.)?{$this->dbPrefix}test_ms /", $result_sql);
$this->assertMatchesRegularExpression("/INSERT INTO (public\.)?{$this->dbPrefix}migrations /", $result_sql);
$this->assertStringContainsString("INSERT INTO public.{$this->dbPrefix}migrations VALUES (1,'0000_00_00_000000_create_test_tables',0);", $result_sql);
$this->assertStringContainsString("INSERT INTO public.{$this->dbPrefix}migrations VALUES (2,'0000_00_00_000001_second_migration_for_testing',0);", $result_sql);
$last_character = mb_substr($result_sql, -1);
$this->assertMatchesRegularExpression("/[\r\n]\z/mu", $last_character);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Sqlite/MigrateDumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public function test_handle()
$this->assertFileExists($this->schemaSqlPath);
$result_sql = file_get_contents($this->schemaSqlPath);
$this->assertMatchesRegularExpression("/CREATE TABLE( IF NOT EXISTS)? \"{$this->dbPrefix}test_ms\" /", $result_sql);
$this->assertMatchesRegularExpression("/INSERT INTO \"?{$this->dbPrefix}migrations\"? /", $result_sql);
$this->assertStringContainsString("INSERT INTO {$this->dbPrefix}migrations VALUES(1,'0000_00_00_000000_create_test_tables',0);", $result_sql);
$this->assertStringContainsString("INSERT INTO {$this->dbPrefix}migrations VALUES(2,'0000_00_00_000001_second_migration_for_testing',0);", $result_sql);
$last_character = mb_substr($result_sql, -1);
$this->assertMatchesRegularExpression("/[\r\n]\z/mu", $last_character);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ protected function createTestTablesWithoutMigrate() : void
'migration' => '0000_00_00_000000_create_test_tables',
'batch' => 1,
]);
\DB::table('migrations')->insert([
'migration' => '0000_00_00_000001_second_migration_for_testing',
'batch' => 1,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class SecondMigrationForTesting extends \Illuminate\Database\Migrations\Migration
{
public function up()
{
// this migration just needs to exist to confirm migration table insert statements
}

public function down()
{
//
}
}