From 2c512f93acf6ce3e83e4600c199371ee5eb4f3a6 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 11 Feb 2015 20:46:14 -0500 Subject: Improve pull-request --- app/Schema/Mysql.php | 48 +++++++++++++++++++++++++----------------------- app/Schema/Postgres.php | 36 +++++++++++++++++++----------------- app/Schema/Sqlite.php | 38 ++++++++++++++++++++------------------ 3 files changed, 64 insertions(+), 58 deletions(-) (limited to 'app/Schema') diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index e4be05b7..24bc2baf 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -9,33 +9,35 @@ const VERSION = 45; function version_45($pdo) { - $pdo->exec('ALTER TABLE tasks ADD COLUMN date_moved INT DEFAULT 0'); - - /* Update tasks.date_moved from project_activities table if tasks.date_moved = null or 0. - * We take max project_activities.date_creation where event_name in task.create','task.move.column - * since creation date is always less than task moves - */ - $pdo->exec("UPDATE tasks - SET date_moved = ( - SELECT md + $pdo->exec('ALTER TABLE tasks ADD COLUMN date_moved INT DEFAULT 0'); + + /* Update tasks.date_moved from project_activities table if tasks.date_moved = null or 0. + * We take max project_activities.date_creation where event_name in task.create','task.move.column + * since creation date is always less than task moves + */ + $pdo->exec("UPDATE tasks + SET date_moved = ( + SELECT md FROM ( - SELECT task_id, max(date_creation) md - FROM project_activities - WHERE event_name IN ('task.create', 'task.move.column') - GROUP BY task_id - ) src + SELECT task_id, max(date_creation) md + FROM project_activities + WHERE event_name IN ('task.create', 'task.move.column') + GROUP BY task_id + ) src WHERE id = src.task_id - ) + ) WHERE (date_moved IS NULL OR date_moved = 0) AND id IN ( SELECT task_id FROM ( - SELECT task_id, max(date_creation) md - FROM project_activities - WHERE event_name IN ('task.create', 'task.move.column') - GROUP BY task_id - ) src - ) - "); + SELECT task_id, max(date_creation) md + FROM project_activities + WHERE event_name IN ('task.create', 'task.move.column') + GROUP BY task_id + ) src + )"); + + // If there is no activities for some tasks use the date_creation + $pdo->exec("UPDATE tasks SET date_moved = date_creation WHERE date_moved IS NULL OR date_moved = 0"); } function version_44($pdo) @@ -65,7 +67,7 @@ function version_43($pdo) function version_42($pdo) { - $pdo->exec('ALTER TABLE columns ADD COLUMN description TEXT'); + $pdo->exec('ALTER TABLE columns ADD COLUMN description TEXT'); } function version_41($pdo) diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 92587273..d3fb9fc4 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -14,33 +14,35 @@ function version_26($pdo) /* Update tasks.date_moved from project_activities table if tasks.date_moved = null or 0. * We take max project_activities.date_creation where event_name in task.create','task.move.column * since creation date is always less than task moves - */ + */ $pdo->exec("UPDATE tasks - SET date_moved = ( - SELECT md + SET date_moved = ( + SELECT md FROM ( - SELECT task_id, max(date_creation) md - FROM project_activities - WHERE event_name IN ('task.create', 'task.move.column') - GROUP BY task_id - ) src + SELECT task_id, max(date_creation) md + FROM project_activities + WHERE event_name IN ('task.create', 'task.move.column') + GROUP BY task_id + ) src WHERE id = src.task_id - ) + ) WHERE (date_moved IS NULL OR date_moved = 0) AND id IN ( SELECT task_id FROM ( - SELECT task_id, max(date_creation) md - FROM project_activities - WHERE event_name IN ('task.create', 'task.move.column') - GROUP BY task_id - ) src - ) - "); + SELECT task_id, max(date_creation) md + FROM project_activities + WHERE event_name IN ('task.create', 'task.move.column') + GROUP BY task_id + ) src + )"); + + // If there is no activities for some tasks use the date_creation + $pdo->exec("UPDATE tasks SET date_moved = date_creation WHERE date_moved IS NULL OR date_moved = 0"); } function version_25($pdo) { - $pdo->exec("ALTER TABLE users ADD COLUMN disable_login_form BOOLEAN DEFAULT '1'"); + $pdo->exec("ALTER TABLE users ADD COLUMN disable_login_form BOOLEAN DEFAULT '0'"); } function version_24($pdo) diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 7e0668e3..f027cf91 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -12,30 +12,32 @@ function version_44($pdo) $pdo->exec('ALTER TABLE tasks ADD COLUMN date_moved INTEGER DEFAULT 0'); /* Update tasks.date_moved from project_activities table if tasks.date_moved = null or 0. - * We take max project_activities.date_creation where event_name in task.create','task.move.column - * since creation date is always less than task moves - */ + * We take max project_activities.date_creation where event_name in task.create','task.move.column + * since creation date is always less than task moves + */ $pdo->exec("UPDATE tasks - SET date_moved = ( - SELECT md + SET date_moved = ( + SELECT md FROM ( - SELECT task_id, max(date_creation) md - FROM project_activities - WHERE event_name IN ('task.create', 'task.move.column') - GROUP BY task_id - ) src + SELECT task_id, max(date_creation) md + FROM project_activities + WHERE event_name IN ('task.create', 'task.move.column') + GROUP BY task_id + ) src WHERE id = src.task_id - ) + ) WHERE (date_moved IS NULL OR date_moved = 0) AND id IN ( SELECT task_id FROM ( - SELECT task_id, max(date_creation) md - FROM project_activities - WHERE event_name IN ('task.create', 'task.move.column') - GROUP BY task_id - ) src - ) - "); + SELECT task_id, max(date_creation) md + FROM project_activities + WHERE event_name IN ('task.create', 'task.move.column') + GROUP BY task_id + ) src + )"); + + // If there is no activities for some tasks use the date_creation + $pdo->exec("UPDATE tasks SET date_moved = date_creation WHERE date_moved IS NULL OR date_moved = 0"); } function version_43($pdo) -- cgit v1.2.3