Skip to content

Commit

Permalink
Drupal 9+ SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED, fixes
Browse files Browse the repository at this point in the history
…#4281 (#4351) [skip ci]
  • Loading branch information
rfay committed Oct 31, 2022
1 parent 2d9fd17 commit c6a2fc4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
3 changes: 3 additions & 0 deletions docs/content/users/topics/cms_specific_help.md
Expand Up @@ -25,6 +25,9 @@ This helps new users and people who are kicking the tires on a CMS. Plus it’s
### Drupal Specifics

* **Settings Files**: By default, DDEV will create settings files for your project that make it “just work” out of the box. It creates a `sites/default/settings.ddev.php` and adds an include in `sites/default/settings.php` to bring that in. There are guards to prevent the `settings.ddev.php` from being active when the project is not running under DDEV, but it still should not be checked in and is gitignored.
* **Database requirements for Drupal 9.5+ +**:
* Using MySQL or MariaDB, Drupal requires `SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED` and DDEV does this for you on `ddev start`.
* Using PostgreSQL, Drupal requires the`pg_trm` extension. DDEV creates this extension automatically for you on `ddev start`.
* **Twig Debugging**: With the default Drupal configuration, it’s very difficult to debug Twig templates; you need to use `development.services.yml` instead of `services.yml`. Add this line in your `settings.php` or `settings.local.php`. See discussion at [drupal.org](https://www.drupal.org/forum/support/module-development-and-code-questions/2019-09-02/ddev-twig-debugging) and the Drupal documentation.

```php
Expand Down
31 changes: 22 additions & 9 deletions pkg/ddevapp/drupal.go
Expand Up @@ -382,15 +382,28 @@ func drupal8PostStartAction(app *DdevApp) error {
}

func drupalPostStartAction(app *DdevApp) error {
// pg_trm extension is required
if app.Database.Type == nodeps.Postgres && (isDrupal9App(app) || isDrupal10App(app)) {
stdout, stderr, err := app.Exec(&ExecOpts{
Service: "db",
Cmd: `psql -q -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" 2>/dev/null`,
NoCapture: false,
})
if err != nil {
util.Warning("unable to CREATE EXTENSION pg_trm: stdout='%s', stderr='%s', err=%v", stdout, stderr, err)
if isDrupal9App(app) || isDrupal10App(app) {
// pg_trm extension is required in Drupal9.5+
if app.Database.Type == nodeps.Postgres {
stdout, stderr, err := app.Exec(&ExecOpts{
Service: "db",
Cmd: `psql -q -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" 2>/dev/null`,
NoCapture: false,
})
if err != nil {
util.Warning("unable to CREATE EXTENSION pg_trm: stdout='%s', stderr='%s', err=%v", stdout, stderr, err)
}
}
// SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED required in Drupal 9.5+
if app.Database.Type == nodeps.MariaDB || app.Database.Type == nodeps.MySQL {
stdout, stderr, err := app.Exec(&ExecOpts{
Service: "db",
Cmd: `mysql -e "SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;" 2>/dev/null`,
NoCapture: false,
})
if err != nil {
util.Warning("unable to SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED: stdout='%s', stderr='%s', err=%v", stdout, stderr, err)
}
}
}
// Return early because we aren't expected to manage settings.
Expand Down
7 changes: 0 additions & 7 deletions pkg/ddevapp/drupal/drupal10/settings.ddev.php
Expand Up @@ -28,13 +28,6 @@
'prefix' => "{{ $config.DatabasePrefix }}",
);


// Setting the MySQL transaction isolation level.
// @see https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level
if ($driver === "mysql") {
$databases['default']['default']['init_commands']['isolation_level'] = 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED';
}

$settings['hash_salt'] = '{{ $config.HashSalt }}';

// This will prevent Drupal from setting read-only permissions on sites/default.
Expand Down
7 changes: 0 additions & 7 deletions pkg/ddevapp/drupal/drupal9/settings.ddev.php
Expand Up @@ -28,13 +28,6 @@
'prefix' => "{{ $config.DatabasePrefix }}",
);


// Setting the MySQL transaction isolation level.
// @see https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level
if ($driver === "mysql") {
$databases['default']['default']['init_commands']['isolation_level'] = 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED';
}

$settings['hash_salt'] = '{{ $config.HashSalt }}';

// This will prevent Drupal from setting read-only permissions on sites/default.
Expand Down

0 comments on commit c6a2fc4

Please sign in to comment.