Skip to content

Conversation

JanJakes
Copy link
Member

@JanJakes JanJakes commented Aug 6, 2025

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.

Copy link
Contributor

@wojtekn wojtekn left a 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.

@JanJakes
Copy link
Member Author

JanJakes commented Aug 6, 2025

FYI @adamziel. Studio doesn't yet inject the missing constants into wp-config.php, so we'll add back a fallback temporarily. Since now the provided database name is verified against the existing DB, this should be a safe change.

@JanJakes JanJakes changed the title Add back a database name fallback for Studio for now Add back a database name fallback for early adopters of the new driver Aug 6, 2025
@JanJakes JanJakes changed the title Add back a database name fallback for early adopters of the new driver Add a database name fallback for early adopters of the new driver Aug 6, 2025
@JanJakes JanJakes force-pushed the db-name-studio-fix branch from 2112f47 to 48f1123 Compare August 6, 2025 11:44
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.
@JanJakes JanJakes force-pushed the db-name-studio-fix branch from 48f1123 to b9f2107 Compare August 6, 2025 11:48
@adamziel adamziel added the bug Something isn't working label Aug 6, 2025
@JanJakes JanJakes merged commit e61736e into develop Aug 6, 2025
12 checks passed
@JanJakes JanJakes deleted the db-name-studio-fix branch August 6, 2025 12:11
@basil
Copy link

basil commented Aug 30, 2025

As a result of poor documentation, I accidentally created my database without DB_NAME, and now my SQL dump contains lots of ugly instances of database_name_here. Is there any way this can be easily repaired without starting from scratch?

@JanJakes
Copy link
Member Author

JanJakes commented Sep 1, 2025

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 WP_SQLITE_AST_DRIVER constant) or the current one? Also, where does the database_name_here appear exactly in your dump? SQL dumps usually don't contain the database name itself, apart from the CREATE DATABASE statement, I think.

@basil
Copy link

basil commented Sep 1, 2025

@JanJakes I created the blog with the current SQLite driver and then switched to the new one by setting WP_SQLITE_AST_DRIVER. Nothing in the documentation said that I needed to set DB_NAME, so I didn't. database_name_here appears over 300 times in the dump, mostly in these tables:

  • _wp_sqlite_mysql_information_schema_statistics
  • _wp_sqlite_mysql_information_schema_columns
  • _wp_sqlite_mysql_information_schema_tables
  • _wp_sqlite_mysql_information_schema_table_constraints

When I try to set DB_NAME now to any new value other than database_name_here, WordPress stops loading.

@JanJakes
Copy link
Member Author

JanJakes commented Sep 2, 2025

@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 _wp_sqlite_ tables are internal tables that the driver needs to store extra data for MySQL-like behavior. They should not appear in a MySQL-like dump (something like wp db export, not fully supported yet), but in a pure SQLite dump/backup/export, they are necessary.

All that said, it's OK to replace all occurrences of database_name_here with any other value in your dump. Then you can set DB_NAME to that same new value, and a site from such a dump should work.

@basil
Copy link

basil commented Sep 2, 2025

@JanJakes I dumped my database with SQLite's .dump command. Is there any way I can repair my existing database without having to dump and reimport from scratch?

@JanJakes
Copy link
Member Author

@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';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants