Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable database initialization for use in building environments such as Docker #40

Open
amedranogil opened this issue Dec 31, 2022 · 1 comment

Comments

@amedranogil
Copy link

amedranogil commented Dec 31, 2022

Following instructions to build a custom docker image, when adding any plugin which declares an sql-dir extra parameter for SQL database initialisation, it fails.

This is logical, as the database engine is not running in this build environment, in fact the actual configuration is not even loaded at this stage. And even if the script where to find the database, in docker the core database is not initialised until first execution, thus there will be no "standard" tables either, and plugins' scripts who rely on those will fail.

By removing the assumption that roundcube is set up and running when executing a composer require command, some of these issues could be avoided.

One alternative would be to have an execution switch to avoid executing database initialisation script (maybe post-installation scripts too).

Another way is to detect the condition the database is accessible with current configuration, and if it not the case append the plugin SQL initialisation scripts to the "core SQL initialisation scripts" (the scripts in roundcube/SQL/ directory); this still complies with the specification and enables the command to continue. I have been using this technique when "manually" building my docker image, and it works fine as the initialisation is handled just like the core SQL initialisation. This of course only works with clean installs, plugin updates in roundcube-docker are not considered; thus manual SQL initialisation is always necessary in these cases anyway.

UPDATE: Failed to connect to database exception is handled to end the execution, so the condition needs to be detected before the exception.

@jonasknobloch
Copy link

jonasknobloch commented Jul 22, 2024

The following patch (via cweagans/composer-patches) did the trick for me.

diff --git a/src/ExtensionInstaller.php b/src/ExtensionInstaller.php
index b4272ac..caddb3d 100644
--- a/src/ExtensionInstaller.php
+++ b/src/ExtensionInstaller.php
@@ -131,7 +131,7 @@ abstract class ExtensionInstaller extends LibraryInstaller
             }
 
             // initialize database schema
-            if (!empty($extra['roundcube']['sql-dir'])) {
+            if (!empty($extra['roundcube']['sql-dir']) && !getenv('SKIP_DB_INIT')) {
                 if ($sqldir = realpath($package_dir . \DIRECTORY_SEPARATOR . $extra['roundcube']['sql-dir'])) {
                     $this->io->write("<info>Running database initialization script for {$package_name}</info>");
 
@@ -197,7 +197,7 @@ abstract class ExtensionInstaller extends LibraryInstaller
             $fs->remove($temp_dir);
 
             // update database schema
-            if (!empty($extra['roundcube']['sql-dir'])) {
+            if (!empty($extra['roundcube']['sql-dir']) && !getenv('SKIP_DB_UPDATE')) {
                 if ($sqldir = realpath($package_dir . \DIRECTORY_SEPARATOR . $extra['roundcube']['sql-dir'])) {
                     $this->io->write("<info>Updating database schema for {$package_name}</info>");
 

The included command line scripts bin/initdb.sh & bin/updatedb.sh can be used to run migrations after plugin installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants