-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[12.x] Support for Attaching Databases as Schemas in SQLite #54380
[12.x] Support for Attaching Databases as Schemas in SQLite #54380
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
Given how much SQLite is starting to be used for scalable web services, this PR seems to me to be an excellent direction. |
Do we have any real data on this? This feels incredibly edge case in Laravel at least 😅 |
I want to hold off on this until there is more demand for this kind of thing. |
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')