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.

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

Command icon 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

cozzamara created an issue. See original summary.

yash_khandelwal’s picture

Status: Active » Needs review

The 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

Version: 7.54 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

hyperlogos’s picture

This 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?

poker10’s picture

Version: 7.x-dev » 10.1.x-dev
Status: Needs review » Active

Tested this on clean Drupal 10.1.x-dev minimal installation profile and if you select SQLite and enter a prefix, there is an error:

Failed to connect to database. The database engine reports the following message: SQLSTATE[HY000]: General error: 14 unable to open database: sites/default/files/.ht.sqlite-minimal_: ATTACH DATABASE :database_file AS :database; Array ( [:database_file] => sites/default/files/.ht.sqlite-minimal_ [:database] => minimal_ ) .
- Does the database file exist?
- Does web server have permission to write to the database file?
- Does the web server have permission to write to the directory the database file should be created in?

Database is created with the name sites/default/files/.ht.sqlite, but the installer is looking for sites/default/files/.ht.sqlite-minimal_

Therefore switching version to D10, thanks!

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pingwin4eg’s picture

Title: Installation fail with SqLite Table prefix » Fix installation in SQLite with a table prefix
Issue summary: View changes

In D11 the situation is a bit different, but the main problem is the same. Updated IS.

pingwin4eg’s picture

Issue summary: View changes
pingwin4eg’s picture

Component: database system » sqlite db driver
pingwin4eg’s picture

I 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.

pingwin4eg’s picture

Issue summary: View changes

Drush error appears even without a table prefix, removing it from IS. It was caused by xdebug.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

codebymikey’s picture

Issue summary: View changes
Priority: Normal » Major

This appears to be pretty big bug, and I'm surprised it's not been noticed so far.

codebymikey’s picture

Status: Active » Needs work
Issue tags: +Needs tests

Updated PR so that the prefix behaviour is consistent with how the other connectors work.

Still need to add tests for the newly introduced database_name property, as well as a plan for how to enforce the migration of prefix to database_name if that's the desired effect.

Feel free to test if you're affected by this.

codebymikey’s picture