summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Console/DatabaseMigrationCommand.php23
-rw-r--r--app/Console/DatabaseVersionCommand.php23
-rw-r--r--app/ServiceProvider/CommandProvider.php4
-rw-r--r--app/ServiceProvider/DatabaseProvider.php41
-rw-r--r--app/constants.php3
-rw-r--r--config.default.php8
6 files changed, 97 insertions, 5 deletions
diff --git a/app/Console/DatabaseMigrationCommand.php b/app/Console/DatabaseMigrationCommand.php
new file mode 100644
index 00000000..252d4369
--- /dev/null
+++ b/app/Console/DatabaseMigrationCommand.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Kanboard\Console;
+
+use Kanboard\ServiceProvider\DatabaseProvider;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class DatabaseMigrationCommand extends DatabaseVersionCommand
+{
+ protected function configure()
+ {
+ $this
+ ->setName('db:migrate')
+ ->setDescription('Execute SQL migrations');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ parent::execute($input, $output);
+ DatabaseProvider::runMigrations($this->container['db']);
+ }
+}
diff --git a/app/Console/DatabaseVersionCommand.php b/app/Console/DatabaseVersionCommand.php
new file mode 100644
index 00000000..5b1f1ed1
--- /dev/null
+++ b/app/Console/DatabaseVersionCommand.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Kanboard\Console;
+
+use Kanboard\ServiceProvider\DatabaseProvider;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class DatabaseVersionCommand extends BaseCommand
+{
+ protected function configure()
+ {
+ $this
+ ->setName('db:version')
+ ->setDescription('Show database schema version');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $output->writeln('<info>Current version: '.DatabaseProvider::getSchemaVersion($this->container['db']).'</info>');
+ $output->writeln('<info>Last version: '.\Schema\VERSION.'</info>');
+ }
+}
diff --git a/app/ServiceProvider/CommandProvider.php b/app/ServiceProvider/CommandProvider.php
index 55c2712b..c9abb294 100644
--- a/app/ServiceProvider/CommandProvider.php
+++ b/app/ServiceProvider/CommandProvider.php
@@ -3,6 +3,8 @@
namespace Kanboard\ServiceProvider;
use Kanboard\Console\CronjobCommand;
+use Kanboard\Console\DatabaseMigrationCommand;
+use Kanboard\Console\DatabaseVersionCommand;
use Kanboard\Console\LocaleComparatorCommand;
use Kanboard\Console\LocaleSyncCommand;
use Kanboard\Console\PluginInstallCommand;
@@ -55,6 +57,8 @@ class CommandProvider implements ServiceProviderInterface
$application->add(new PluginUpgradeCommand($container));
$application->add(new PluginInstallCommand($container));
$application->add(new PluginUninstallCommand($container));
+ $application->add(new DatabaseMigrationCommand($container));
+ $application->add(new DatabaseVersionCommand($container));
$container['cli'] = $application;
return $container;
diff --git a/app/ServiceProvider/DatabaseProvider.php b/app/ServiceProvider/DatabaseProvider.php
index a3f57457..9998ac43 100644
--- a/app/ServiceProvider/DatabaseProvider.php
+++ b/app/ServiceProvider/DatabaseProvider.php
@@ -27,6 +27,10 @@ class DatabaseProvider implements ServiceProviderInterface
{
$container['db'] = $this->getInstance();
+ if (DB_RUN_MIGRATIONS) {
+ self::runMigrations($container['db']);
+ }
+
if (DEBUG) {
$container['db']->getStatementHandler()
->withLogging()
@@ -38,7 +42,7 @@ class DatabaseProvider implements ServiceProviderInterface
}
/**
- * Setup the database driver and execute schema migration
+ * Setup the database driver
*
* @access public
* @return \PicoDb\Database
@@ -59,12 +63,39 @@ class DatabaseProvider implements ServiceProviderInterface
throw new LogicException('Database driver not supported');
}
- if ($db->schema()->check(\Schema\VERSION)) {
- return $db;
- } else {
+ return $db;
+ }
+
+ /**
+ * Get current database version
+ *
+ * @static
+ * @access public
+ * @param Database $db
+ * @return int
+ */
+ public static function getSchemaVersion(Database $db)
+ {
+ return $db->getDriver()->getSchemaVersion();
+ }
+
+ /**
+ * Execute database migrations
+ *
+ * @static
+ * @access public
+ * @throws RuntimeException
+ * @param Database $db
+ * @return bool
+ */
+ public static function runMigrations(Database $db)
+ {
+ if (! $db->schema()->check(\Schema\VERSION)) {
$messages = $db->getLogMessages();
throw new RuntimeException('Unable to run SQL migrations: '.implode(', ', $messages).' (You may have to fix it manually)');
}
+
+ return true;
}
/**
@@ -79,7 +110,7 @@ class DatabaseProvider implements ServiceProviderInterface
return new Database(array(
'driver' => 'sqlite',
- 'filename' => DB_FILENAME
+ 'filename' => DB_FILENAME,
));
}
diff --git a/app/constants.php b/app/constants.php
index 3adb0835..ba14cde6 100644
--- a/app/constants.php
+++ b/app/constants.php
@@ -35,6 +35,9 @@ defined('LOG_FILE') or define('LOG_FILE', DATA_DIR.DIRECTORY_SEPARATOR.'debug.lo
// Application version
defined('APP_VERSION') or define('APP_VERSION', build_app_version('$Format:%d$', '$Format:%H$'));
+// Run automatically database migrations
+defined('DB_RUN_MIGRATIONS') or define('DB_RUN_MIGRATIONS', true);
+
// Database driver: sqlite, mysql or postgres
defined('DB_DRIVER') or define('DB_DRIVER', 'sqlite');
diff --git a/config.default.php b/config.default.php
index 04728f3e..09774689 100644
--- a/config.default.php
+++ b/config.default.php
@@ -50,6 +50,11 @@ define('MAIL_SMTP_ENCRYPTION', null); // Valid values are "null", "ssl" or "tls"
// Sendmail command to use when the transport is "sendmail"
define('MAIL_SENDMAIL_COMMAND', '/usr/sbin/sendmail -bs');
+// Run automatically database migrations
+// If set to false, you will have to run manually the SQL migrations from the CLI during the next Kanboard upgrade
+// Do not run the migrations from multiple processes at the same time (example: web page + background worker)
+define('DB_RUN_MIGRATIONS', true);
+
// Database driver: sqlite, mysql or postgres (sqlite by default)
define('DB_DRIVER', 'sqlite');
@@ -226,3 +231,6 @@ define('HTTP_PROXY_PASSWORD', '');
// Set to false to allow self-signed certificates
define('HTTP_VERIFY_SSL_CERTIFICATE', true);
+
+// TOTP (2FA) issuer name
+define('TOTP_ISSUER', 'Kanboard');