-
Notifications
You must be signed in to change notification settings - Fork 52
Add a database name fallback for early adopters of the new driver #226
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
Conversation
wojtekn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fixes the issue, and code change looks clean.
|
FYI @adamziel. Studio doesn't yet inject the missing constants into |
2112f47 to
48f1123
Compare
The experimental new SQLite driver requires a database name to be set, while the old one doesn't. There are some scenarios in which the DB_NAME constant is missing in wp-config.php. To enable easier early adoption and testing before version 3.0, we're adding a default database name in case the DB_NAME constant is not set. Since the provided database name is now verified against the existing database, this should be a safe change.
48f1123 to
b9f2107
Compare
|
As a result of poor documentation, I accidentally created my database without |
|
Hi @basil! Could you, please, share more information about your setup and the contents of the dump? Did you use the new SQLite driver (the |
|
@JanJakes I created the blog with the current SQLite driver and then switched to the new one by setting
When I try to set |
|
@basil Thanks for the details. How did you dump your database? Is it an SQLite dump using some SQLite tooling? Or are you interested in a MySQL-like dump of the database? These All that said, it's OK to replace all occurrences of |
|
@JanJakes I dumped my database with SQLite's |
|
@basil You could update all the records in the SQLite database. You can use an SQLite database admin tool and run something like this: UPDATE _wp_sqlite_information_schema_schemata SET schema_name = 'new_name';
UPDATE _wp_sqlite_information_schema_tables SET table_schema = 'new_name';
UPDATE _wp_sqlite_information_schema_columns SET table_schema = 'new_name';
UPDATE _wp_sqlite_information_schema_statistics SET table_schema = 'new_name', index_schema = 'new_name';
UPDATE _wp_sqlite_information_schema_table_constraints SET table_schema = 'new_name', constraint_schema = 'new_name';
UPDATE _wp_sqlite_information_schema_table_referential_constraints SET constraint_schema = 'new_name', unique_constraint_schema = 'new_name';
UPDATE _wp_sqlite_information_schema_table_key_column_usage SET constraint_schema = 'new_name', table_schema = 'new_name', referenced_table_schema = 'new_name'; |
This PR replaces #262. It is a simpler solution to the same problem: When a table reference targets an information schema table, we replace it with a subquery, injecting the configured database name dynamically: ```sql -- The following query: SELECT *, t.*, t.table_schema FROM information_schema.tables t -- Will be translated to: SELECT *, t.*, t.table_schema FROM ( SELECT `TABLE_CATALOG`, IIF(`TABLE_SCHEMA` = 'information_schema', `TABLE_SCHEMA`, 'database_name') AS `TABLE_SCHEMA`, `TABLE_NAME`, ... FROM _wp_sqlite_mysql_information_schema_tables AS tables ) t ``` The same logic will be applied to table references in JOIN clauses as well. --- With the new SQLite driver, we keep running into issues with missing and incorrect database name values (#197, #203, #226, #260, #261, and other issues). Thinking through this further, I came to the conclusion that to provide maximum flexibility and portability, it would be best to provide an API in the shape of: _"Mount `my-sqlite-file.sqlite` as `my-db-name`."_ Even if we consider adding multi-database support one day, it would still be great to allow mounting additional SQLite files under dynamic database names. I don't see any downsides to doing this, except maybe that we'll have to choose some database name in some scenarios, such as in database admin tools. However, in these cases we can use a reasonable default or the file name. This is a WIP pull request demonstrating the simplest approach. For it to be merged, I only need to resolve how the existing database name values should be treated.
The experimental new SQLite driver requires a database name to be set, while the old one doesn't.
There are some scenarios in which the
DB_NAMEconstant is missing inwp-config.php. To enable easier early adoption and testing before version 3.0, we're adding a default database name in case theDB_NAMEconstant is not set.Since the provided database name is now verified against the existing database, this should be a safe change.