[12.x] Support for Attaching Databases as Schemas in SQLite #54380
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Continuing the work on #54274 to enhance multi-schema support, this PR introduces a new
schemasconfig property that adds support for attaching databases as schemas to SQLite connections. TheATTACH DATABASEquery is not persistent between SQLite connections, which is why we need to attach schemas every time the connection is established.'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', 'database' => env('DB_DATABASE', database_path('database.sqlite')), + 'schemas' => [ + 'secondary' => env('DB_SECONDARY_DATABASE', database_path('secondary.sqlite')), + 'tertiary' => env('DB_TERTIARY_DATABASE', ':memory:'), + ], // ... ], ],Note: When attaching databases to a SQLite connection using this new
schemasconfig property, the following commands, testing traits and methods will drop tables/views in the attached databases (schemas) as well (This behavior is the same for PostgreSQL and SQL Server schemas):db:wipeandmigrate:freshcommands.\Illuminate\Foundation\Testing\RefreshDatabaseand\Illuminate\Foundation\Testing\DatabaseTruncationtraits.Schema::dropAllTables()andSchema::dropAllViews()methods.This PR also moves the connection configurations logic from the
SQLiteConnectionclass to theSQLiteConnectorclass, following the pattern of other database drivers. SQLite was the only DB driver that configured its connection in theConnectionclass instead of theConnectorclass. As part of this change, redundantBuilderandGrammarmethods have been removed. There are manypragmakey/value pairs, so it doesn't make sense to have a method in both classes for eachpragmakey/value (added recently on #52052).Summary
schemasconfig property for thesqliteconnection.Schema::connection('sqlite')->pragma($key, $value = null)method to get/set a pragma value.Schema::pragma('schema_name.journal_mode', 'wal')SQLiteConnectionclass to theSQLiteConnectorclass to be consistent with other DB drivers.SQLiteGrammar::compileSetBusyTimeout(),compileSetJournalMode(),compileSetSynchronous(),compileEnableWriteableSchema(), andcompileDisableWriteableSchema()methods.SQLiteBuilder::setBusyTimeout(),setJournalMode(), andsetSynchronous()methods:Schema::setBusyTimeout(12345)->Schema::pragma('busy_timeout', 12345)Schema::setJournalMode('wal')->Schema::pragma('journal_mode', 'wal')Schema::setSynchronous('normal')->Schema::pragma('synchronous', 'normal')