Support database table prefixing

Created on 9 December 2024, 4 months ago

Problem/Motivation

In static queries, all table names must be wrapped in curly braces {...}.

Wrapping table names in curly braces flags them so that the database system can attach a prefix string to them if appropriate. Prefixing allows for running multiple sites from the same database or, in limited cases, for sharing selected tables between sites. It is also necessary to avoid data from the host site to leak into tests.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @trackleft2
  • πŸ‡ͺπŸ‡ΈSpain omarlopesino

    Currently we are using select queries β†’ , which already supports database prefixing, as they are automatically added by Drupal API.

    If your wordpress database has a database prefix, it should be declared at database definition at settings.php (or other settings file) .

    Example:

    $databases['legacy']['default'] = [
      'database' => 'legacy',
      'username' => 'db',
      'password' => 'db',
      'prefix' => 'elem_',
      'host' => $host,
      'port' => $port,
      'driver' => $driver,
    ];
    

    This example adds the 'prefix' => 'elem_', property to let Drupal nows the database prefix on queries. This should fix the issue. Indeed, I had to do this on my project to make it works with a wordpress site that has database prefixes.

    Let me know if that fixes the problem for you.

    Marking task as Needs review in the meanwhile.

Production build 0.71.5 2024