[12.x] Support for Attaching Databases as Schemas in SQLite #54380
+258
−251
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
schemas
config property that adds support for attaching databases as schemas to SQLite connections. TheATTACH DATABASE
query is not persistent between SQLite connections, which is why we need to attach schemas every time the connection is established.Note: When attaching databases to a SQLite connection using this new
schemas
config 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:wipe
andmigrate:fresh
commands.\Illuminate\Foundation\Testing\RefreshDatabase
and\Illuminate\Foundation\Testing\DatabaseTruncation
traits.Schema::dropAllTables()
andSchema::dropAllViews()
methods.This PR also moves the connection configurations logic from the
SQLiteConnection
class to theSQLiteConnector
class, following the pattern of other database drivers. SQLite was the only DB driver that configured its connection in theConnection
class instead of theConnector
class. As part of this change, redundantBuilder
andGrammar
methods have been removed. There are manypragma
key/value pairs, so it doesn't make sense to have a method in both classes for eachpragma
key/value (added recently on #52052).Summary
schemas
config property for thesqlite
connection.Schema::connection('sqlite')->pragma($key, $value = null)
method to get/set a pragma value.Schema::pragma('schema_name.journal_mode', 'wal')
SQLiteConnection
class to theSQLiteConnector
class 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')