diff options
Diffstat (limited to 'app/Schema')
-rw-r--r-- | app/Schema/Mysql.php | 54 | ||||
-rw-r--r-- | app/Schema/Postgres.php | 53 | ||||
-rw-r--r-- | app/Schema/Sqlite.php | 53 |
3 files changed, 155 insertions, 5 deletions
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 24bc2baf..82dd8428 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -4,8 +4,60 @@ namespace Schema; use PDO; use Core\Security; +use Model\Link; -const VERSION = 45; +const VERSION = 46; + +function version_46($pdo) +{ + $pdo->exec("CREATE TABLE link + ( + link_id INT NOT NULL AUTO_INCREMENT, + project_id INT NOT NULL DEFAULT -1, + PRIMARY KEY(link_id) + ) ENGINE=InnoDB CHARSET=utf8"); + $pdo->exec("CREATE TABLE link_label + ( + id INT NOT NULL AUTO_INCREMENT, + link_id INT NOT NULL, + label TEXT NOT NULL, + behaviour INT DEFAULT 2, + PRIMARY KEY(id), + FOREIGN KEY(link_id) REFERENCES link(link_id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8"); + $pdo->exec("CREATE TABLE task_has_links + ( + id INT NOT NULL AUTO_INCREMENT, + link_label_id INT NOT NULL, + task_id INT NOT NULL, + task_inverse_id INT NOT NULL, + PRIMARY KEY(id), + FOREIGN KEY(link_label_id) REFERENCES link_label(id) ON DELETE CASCADE, + FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE, + FOREIGN KEY(task_inverse_id) REFERENCES tasks(id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8"); + $pdo->exec("CREATE INDEX task_has_links_task_index ON task_has_links(task_id)"); + $pdo->exec("CREATE UNIQUE INDEX task_has_links_unique ON task_has_links(link_label_id, task_id, task_inverse_id)"); + $rq = $pdo->prepare('INSERT INTO link (project_id) VALUES (?)'); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq = $pdo->prepare('INSERT INTO link_label (link_id, label, behaviour) VALUES (?, ?, ?)'); + $rq->execute(array(1, t('relates to'), Link::BEHAVIOUR_BOTH)); + $rq->execute(array(2, t('blocks'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(2, t('is blocked by'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(3, t('duplicates'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(3, t('is duplicated by'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(4, t('is a child of'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(4, t('is a parent of'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(5, t('targets milestone'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(5, t('is a milestone of'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(6, t('fixes'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(6, t('is fixed by'), Link::BEHAVIOUR_RIGHT2LEFT)); +} function version_45($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index d3fb9fc4..af1f3170 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -4,8 +4,57 @@ namespace Schema; use PDO; use Core\Security; +use Model\Link; -const VERSION = 26; +const VERSION = 27; + +function version_27($pdo) +{ + $pdo->exec("CREATE TABLE link + ( + link_id SERIAL PRIMARY KEY, + project_id INTEGER NOT NULL DEFAULT -1 + ) ENGINE=InnoDB CHARSET=utf8"); + $pdo->exec("CREATE TABLE link_label + ( + id SERIAL PRIMARY KEY, + link_id INTEGER NOT NULL, + label TEXT NOT NULL, + behaviour INTEGER NOT NULL DEFAULT 2, + FOREIGN KEY(link_id) REFERENCES link(link_id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8"); + $pdo->exec("CREATE TABLE task_has_links + ( + id SERIAL PRIMARY KEY, + link_label_id INTEGER NOT NULL, + task_id INTEGER NOT NULL, + task_inverse_id INTEGER NOT NULL, + FOREIGN KEY(link_label_id) REFERENCES link_label(id) ON DELETE CASCADE, + FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE, + FOREIGN KEY(task_inverse_id) REFERENCES tasks(id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8"); + $pdo->exec("CREATE INDEX task_has_links_task_index ON task_has_links(task_id)"); + $pdo->exec("CREATE UNIQUE INDEX task_has_links_unique ON task_has_links(link_label_id, task_id, task_inverse_id)"); + $rq = $pdo->prepare('INSERT INTO link (project_id) VALUES (?)'); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq = $pdo->prepare('INSERT INTO link_label (link_id, label, behaviour) VALUES (?, ?, ?)'); + $rq->execute(array(1, t('relates to'), Link::BEHAVIOUR_BOTH)); + $rq->execute(array(2, t('blocks'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(2, t('is blocked by'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(3, t('duplicates'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(3, t('is duplicated by'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(4, t('is a child of'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(4, t('is a parent of'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(5, t('targets milestone'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(5, t('is a milestone of'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(6, t('fixes'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(6, t('is fixed by'), Link::BEHAVIOUR_RIGHT2LEFT)); +} function version_26($pdo) { @@ -66,7 +115,7 @@ function version_24($pdo) function version_23($pdo) { - $pdo->exec('ALTER TABLE columns ADD COLUMN description TEXT'); + $pdo->exec('ALTER TABLE columns ADD COLUMN description TEXT'); } function version_22($pdo) diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index f027cf91..727a32cd 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -4,8 +4,57 @@ namespace Schema; use Core\Security; use PDO; +use Model\Link; -const VERSION = 44; +const VERSION = 45; + +function version_45($pdo) +{ + $pdo->exec("CREATE TABLE link + ( + link_id INTEGER PRIMARY KEY, + project_id INTEGER NOT NULL DEFAULT -1 + )"); + $pdo->exec("CREATE TABLE link_label + ( + id INTEGER PRIMARY KEY, + link_id INTEGER NOT NULL, + label TEXT NOT NULL, + behaviour INTEGER DEFAULT '2', + FOREIGN KEY(link_id) REFERENCES link(link_id) ON DELETE CASCADE + )"); + $pdo->exec("CREATE TABLE task_has_links + ( + id INTEGER PRIMARY KEY, + link_label_id INTEGER NOT NULL, + task_id INTEGER NOT NULL, + task_inverse_id INTEGER NOT NULL, + FOREIGN KEY(link_label_id) REFERENCES link_label(id) ON DELETE CASCADE, + FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE, + FOREIGN KEY(task_inverse_id) REFERENCES tasks(id) ON DELETE CASCADE + )"); + $pdo->exec("CREATE INDEX task_has_links_task_index ON task_has_links(task_id)"); + $pdo->exec("CREATE UNIQUE INDEX task_has_links_unique ON task_has_links(link_label_id, task_id, task_inverse_id)"); + $rq = $pdo->prepare('INSERT INTO link (project_id) VALUES (?)'); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq->execute(array(-1)); + $rq = $pdo->prepare('INSERT INTO link_label (link_id, label, behaviour) VALUES (?, ?, ?)'); + $rq->execute(array(1, t('relates to'), Link::BEHAVIOUR_BOTH)); + $rq->execute(array(2, t('blocks'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(2, t('is blocked by'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(3, t('duplicates'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(3, t('is duplicated by'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(4, t('is a child of'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(4, t('is a parent of'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(5, t('targets milestone'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(5, t('is a milestone of'), Link::BEHAVIOUR_RIGHT2LEFT)); + $rq->execute(array(6, t('fixes'), Link::BEHAVIOUR_LEFT2RIGTH)); + $rq->execute(array(6, t('is fixed by'), Link::BEHAVIOUR_RIGHT2LEFT)); +} function version_44($pdo) { @@ -66,7 +115,7 @@ function version_42($pdo) function version_41($pdo) { - $pdo->exec('ALTER TABLE columns ADD COLUMN description TEXT'); + $pdo->exec('ALTER TABLE columns ADD COLUMN description TEXT'); } function version_40($pdo) |