summaryrefslogtreecommitdiff
path: root/app/Schema
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-02-18 09:42:01 -0500
committerFrederic Guillot <fred@kanboard.net>2017-02-18 09:42:01 -0500
commitde128dbad860478496a0d655b5eb5c1005ebbabe (patch)
tree7fee510e901273472731e8e843981268c593ec40 /app/Schema
parent0430a09c069134622c0161dc2fb9ba3718a73c0d (diff)
Remove default swimlane
Diffstat (limited to 'app/Schema')
-rw-r--r--app/Schema/Migration.php63
-rw-r--r--app/Schema/Mysql.php14
-rw-r--r--app/Schema/Postgres.php15
-rw-r--r--app/Schema/Sqlite.php9
4 files changed, 98 insertions, 3 deletions
diff --git a/app/Schema/Migration.php b/app/Schema/Migration.php
new file mode 100644
index 00000000..395ac1ad
--- /dev/null
+++ b/app/Schema/Migration.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Schema;
+
+use PDO;
+
+function migrate_default_swimlane(PDO $pdo)
+{
+ $projects = get_all_projects($pdo);
+
+ foreach ($projects as $project) {
+
+ // Create new default swimlane
+ $rq = $pdo->prepare('INSERT INTO swimlanes (project_id, name, is_active, position) VALUES (?, ?, ?, ?)');
+ $rq->execute(array(
+ $project['id'],
+ $project['default_swimlane'],
+ (int) $project['show_default_swimlane'],
+ $project['show_default_swimlane'] == 1 ? 1 : 0,
+ ));
+
+ $swimlaneId = get_last_insert_id($pdo);
+
+ // Reorder swimlanes if the default one was active
+ if ($project['show_default_swimlane']) {
+ $rq = $pdo->prepare("UPDATE swimlanes SET position=position+1 WHERE project_id=? AND is_active='1' AND id!=?");
+ $rq->execute(array(
+ $project['id'],
+ $swimlaneId,
+ ));
+ }
+
+ // Move all tasks to new swimlane
+ $rq = $pdo->prepare("UPDATE tasks SET swimlane_id=? WHERE swimlane_id='0' AND project_id=?");
+ $rq->execute(array(
+ $swimlaneId,
+ $project['id'],
+ ));
+
+ // Migrate automatic actions
+ $rq = $pdo->prepare("UPDATE action_has_params SET value=? WHERE id IN (SELECT action_has_params.id FROM action_has_params LEFT JOIN actions ON actions.id=action_has_params.action_id WHERE project_id=? AND name='swimlane_id' AND value='0')");
+ $rq->execute(array($swimlaneId, $project['id']));
+ }
+}
+
+function get_all_projects(PDO $pdo)
+{
+ $rq = $pdo->prepare('SELECT * FROM projects');
+ $rq->execute();
+ return $rq->fetchAll(PDO::FETCH_ASSOC);
+}
+
+function get_last_insert_id(PDO $pdo)
+{
+ if (DB_DRIVER === 'postgres') {
+ $rq = $pdo->prepare('SELECT LASTVAL()');
+ $rq->execute();
+ return $rq->fetchColumn();
+ }
+
+ return $pdo->lastInsertId();
+}
+
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index ca9f45ad..385f63a3 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -2,11 +2,23 @@
namespace Schema;
+require_once __DIR__.'/Migration.php';
+
use PDO;
use Kanboard\Core\Security\Token;
use Kanboard\Core\Security\Role;
-const VERSION = 121;
+const VERSION = 122;
+
+function version_122(PDO $pdo)
+{
+ migrate_default_swimlane($pdo);
+
+ $pdo->exec('ALTER TABLE `projects` DROP COLUMN `default_swimlane`');
+ $pdo->exec('ALTER TABLE `projects` DROP COLUMN `show_default_swimlane`');
+ $pdo->exec('ALTER TABLE `tasks` MODIFY `swimlane_id` INT(11) NOT NULL;');
+ $pdo->exec('ALTER TABLE tasks ADD CONSTRAINT tasks_swimlane_ibfk_1 FOREIGN KEY (swimlane_id) REFERENCES swimlanes(id) ON DELETE CASCADE');
+}
function version_121(PDO $pdo)
{
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index cbea908f..cc3d9632 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -2,11 +2,24 @@
namespace Schema;
+require_once __DIR__.'/Migration.php';
+
use PDO;
use Kanboard\Core\Security\Token;
use Kanboard\Core\Security\Role;
-const VERSION = 100;
+const VERSION = 101;
+
+function version_101(PDO $pdo)
+{
+ migrate_default_swimlane($pdo);
+
+ $pdo->exec('ALTER TABLE "projects" DROP COLUMN "default_swimlane"');
+ $pdo->exec('ALTER TABLE "projects" DROP COLUMN "show_default_swimlane"');
+ $pdo->exec('ALTER TABLE "tasks" ALTER COLUMN "swimlane_id" SET NOT NULL');
+ $pdo->exec('ALTER TABLE "tasks" ALTER COLUMN "swimlane_id" DROP DEFAULT');
+ $pdo->exec('ALTER TABLE "tasks" ADD FOREIGN KEY (swimlane_id) REFERENCES swimlanes ON DELETE CASCADE');
+}
function version_100(PDO $pdo)
{
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index a68ed418..2d35b99e 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -2,11 +2,18 @@
namespace Schema;
+require_once __DIR__.'/Migration.php';
+
use Kanboard\Core\Security\Token;
use Kanboard\Core\Security\Role;
use PDO;
-const VERSION = 111;
+const VERSION = 112;
+
+function version_112(PDO $pdo)
+{
+ migrate_default_swimlane($pdo);
+}
function version_111(PDO $pdo)
{