summaryrefslogtreecommitdiff
path: root/app/Schema
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-03-01 18:03:58 -0500
committerFrederic Guillot <fred@kanboard.net>2015-03-01 18:03:58 -0500
commit35d99ec5d3e5d18e83537c68831be02d40f36d8e (patch)
tree35a86751ad752be286c9e908211dacfc5d174e59 /app/Schema
parentda425e4187e5e8e7feb9783c9d75bcaa9fa0c7ec (diff)
Add subtask position
Diffstat (limited to 'app/Schema')
-rw-r--r--app/Schema/Mysql.php24
-rw-r--r--app/Schema/Postgres.php24
-rw-r--r--app/Schema/Sqlite.php26
3 files changed, 71 insertions, 3 deletions
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index 1c5cdc3a..21c304c1 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -6,7 +6,29 @@ use PDO;
use Core\Security;
use Model\Link;
-const VERSION = 48;
+const VERSION = 49;
+
+function version_49($pdo)
+{
+ $pdo->exec('ALTER TABLE subtasks ADD COLUMN position INTEGER DEFAULT 1');
+
+ $task_id = 0;
+ $urq = $pdo->prepare('UPDATE subtasks SET position=? WHERE id=?');
+
+ $rq = $pdo->prepare('SELECT * FROM subtasks ORDER BY task_id, id ASC');
+ $rq->execute();
+
+ foreach ($rq->fetchAll(PDO::FETCH_ASSOC) as $subtask) {
+
+ if ($task_id != $subtask['task_id']) {
+ $position = 1;
+ $task_id = $subtask['task_id'];
+ }
+
+ $urq->execute(array($position, $subtask['id']));
+ $position++;
+ }
+}
function version_48($pdo)
{
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index aa3f60f7..df003267 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -6,7 +6,29 @@ use PDO;
use Core\Security;
use Model\Link;
-const VERSION = 29;
+const VERSION = 30;
+
+function version_30($pdo)
+{
+ $pdo->exec('ALTER TABLE subtasks ADD COLUMN position INTEGER DEFAULT 1');
+
+ $task_id = 0;
+ $urq = $pdo->prepare('UPDATE subtasks SET position=? WHERE id=?');
+
+ $rq = $pdo->prepare('SELECT * FROM subtasks ORDER BY task_id, id ASC');
+ $rq->execute();
+
+ foreach ($rq->fetchAll(PDO::FETCH_ASSOC) as $subtask) {
+
+ if ($task_id != $subtask['task_id']) {
+ $position = 1;
+ $task_id = $subtask['task_id'];
+ }
+
+ $urq->execute(array($position, $subtask['id']));
+ $position++;
+ }
+}
function version_29($pdo)
{
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index 6fc2d07e..9134760f 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -6,7 +6,31 @@ use Core\Security;
use PDO;
use Model\Link;
-const VERSION = 47;
+const VERSION = 48;
+
+function version_48($pdo)
+{
+ $pdo->exec('ALTER TABLE subtasks ADD COLUMN position INTEGER DEFAULT 1');
+
+ // Migrate all subtasks position
+
+ $task_id = 0;
+ $urq = $pdo->prepare('UPDATE subtasks SET position=? WHERE id=?');
+
+ $rq = $pdo->prepare('SELECT * FROM subtasks ORDER BY task_id, id ASC');
+ $rq->execute();
+
+ foreach ($rq->fetchAll(PDO::FETCH_ASSOC) as $subtask) {
+
+ if ($task_id != $subtask['task_id']) {
+ $position = 1;
+ $task_id = $subtask['task_id'];
+ }
+
+ $urq->execute(array($position, $subtask['id']));
+ $position++;
+ }
+}
function version_47($pdo)
{