Problem/Motivation
Installing Drupal 11-dev website in SQLite with a table prefix creates 2 db files:
- the correct one (e.g., .ht.sqlite), but it's empty (with only the sqlite_master table),
- and the other one with the prefix actually appended to a file name (e.g., .ht.sqlite-prefix_), with all the tables originally named (not prefixed).
-rw-r--r-- 1 m m 4096 Jan 19 10:38 .ht.sqlite
-rw-r--r-- 1 m m 2498560 Jan 19 10:45 .ht.sqlite-prefix_
A snippet from the auto-generated settings.php is correct:
$databases['default']['default'] = array (
'database' => 'sites/default/files/.ht.sqlite',
'prefix' => 'prefix_',
'driver' => 'sqlite',
'namespace' => 'Drupal\\sqlite\\Driver\\Database\\sqlite',
'autoload' => 'core/modules/sqlite/src/Driver/Database/sqlite/',
);
The site works, no errors reported by the installation process and no errors on the admin/reports/dblog page. But the site uses incorrect DB file.
In Drupal versions < 11 the installation process fails with errors (according to the original issue report and comments).
It seems the sqlite module does not behave according the documentations declared within the settings.php.
The prefix configuration is meant for table prefixes, but the sqlite module has repurposed it as a database name instead. I think the documentation needs to be updated and a dedicated database name property introduced for the custom database name functionality.
Steps to reproduce
During the installation process, on the 'Set up database' step, select SQLite database type, in advanced options set the table name prefix. Continue installation.
Proposed resolution
Fix and allow table prefixes in SQLite DB.
Merge request link
Remaining tasks
User interface changes
Shouldn't be any.
API changes
Data model changes
Release notes snippet
Original report
@cozzamara:
Hi I found an issue on installation process. If I use a SQLite database and set table prefix option, the installation fails because the table prefix is used as database name suffix.
Issue fork drupal-2852035
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
yash_khandelwalThe SQLite database tables haven't a prefix name. If you install drupal using an SQLite database and specifying a table prefix in the option of database installation wizard, you get an error.
For more details, see below link..
https://api.drupal.org/api/drupal/INSTALL.sqlite.txt/7.x
Comment #4
hyperlogos commentedThis still seems to be a thing in D10?
Problem is, I need to use a prefix because I want to use views_database_connector
I guess I can't use sqlite?
Comment #5
poker10 commentedTested this on clean Drupal 10.1.x-dev minimal installation profile and if you select SQLite and enter a prefix, there is an error:
Database is created with the name
sites/default/files/.ht.sqlite, but the installer is looking forsites/default/files/.ht.sqlite-minimal_Therefore switching version to D10, thanks!
Comment #7
pingwin4egIn D11 the situation is a bit different, but the main problem is the same. Updated IS.
Comment #8
pingwin4egComment #9
pingwin4egComment #10
pingwin4egI found out that the SQLite driver uses database attachment concept instead of actual table prefixes. Not sure whether this is OK or not, and why it was implemented this way.
If it's OK, then the settings.php documentation needs to mention that, the prefix is better be prepended to a DB file name or appended to a base name before the file extension, and reported errors need to be fixed.
Comment #11
pingwin4egDrush error appears even without a table prefix, removing it from IS. It was caused by xdebug.
Comment #13
codebymikey commentedThis appears to be pretty big bug, and I'm surprised it's not been noticed so far.
Comment #15
codebymikey commentedUpdated PR so that the
prefixbehaviour is consistent with how the other connectors work.Still need to add tests for the newly introduced
database_nameproperty, as well as a plan for how to enforce the migration ofprefixtodatabase_nameif that's the desired effect.Feel free to test if you're affected by this.
Comment #16
codebymikey commented