Skip to content

Commit

Permalink
[11.x] Fix SQLite schema dumps missing most tables (#52275)
Browse files Browse the repository at this point in the history
* Update test to make sure all expected tables are present in dump

* Fix removal of sqlite internal tables
  • Loading branch information
bakerkretzmar authored Jul 26, 2024
1 parent 45a42f9 commit 5979519
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/SqliteSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function dump(Connection $connection, $path)
//
]));

$migrations = preg_replace('/CREATE TABLE sqlite_.+\);[\r\n]+/is', '', $process->getOutput());
$migrations = preg_replace('/CREATE TABLE sqlite_.+?\);[\r\n]+/is', '', $process->getOutput());

$this->files->put($path, $migrations.PHP_EOL);

Expand Down
4 changes: 3 additions & 1 deletion tests/Integration/Database/Sqlite/SchemaStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function testSchemaDumpOnSqlite()
$connection = DB::connection();
$connection->getSchemaBuilder()->createDatabase($connection->getConfig('database'));

$connection->statement('CREATE TABLE users(id integer primary key autoincrement not null, email varchar not null, name varchar not null);');
$connection->statement('CREATE TABLE IF NOT EXISTS migrations (id integer primary key autoincrement not null, migration varchar not null, batch integer not null);');
$connection->statement('CREATE TABLE users (id integer primary key autoincrement not null, email varchar not null, name varchar not null);');
$connection->statement('INSERT INTO users (email, name) VALUES ("[email protected]", "Taylor Otwell");');

$this->assertTrue($connection->table('sqlite_sequence')->exists());
Expand All @@ -60,6 +61,7 @@ public function testSchemaDumpOnSqlite()
$connection->getSchemaState()->dump($connection, database_path('schema/sqlite-schema.sql'));

$this->assertFileContains([
'CREATE TABLE migrations',
'CREATE TABLE users',
], 'database/schema/sqlite-schema.sql');
$this->assertFileNotContains([
Expand Down

0 comments on commit 5979519

Please sign in to comment.