From bca6b99068cbf1dd4148d6bd5cb60e926162cfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 15 Feb 2012 10:58:55 +0100 Subject: [PATCH] Fixed bug in finish_task() Due to an error on a column name, finish_task() was broken. It has been fixed. --- database/tasks-functions.sql | 2 +- ...5130326245fa8175bc390ce58b387b92d568a7.sql | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 database/upgrade/from-205130326245fa8175bc390ce58b387b92d568a7.sql diff --git a/database/tasks-functions.sql b/database/tasks-functions.sql index 949e047..ca79819 100644 --- a/database/tasks-functions.sql +++ b/database/tasks-functions.sql @@ -72,7 +72,7 @@ CREATE FUNCTION finish_task( t_id INT , u_id INT , n_text TEXT ) AS $finish_task$ BEGIN PERFORM 1 FROM tasks_single_view t - WHERE task_id = t_id AND badness = 0; + WHERE id = t_id AND badness = 0; IF NOT FOUND THEN RETURN 2; END IF; diff --git a/database/upgrade/from-205130326245fa8175bc390ce58b387b92d568a7.sql b/database/upgrade/from-205130326245fa8175bc390ce58b387b92d568a7.sql new file mode 100644 index 0000000..e184d74 --- /dev/null +++ b/database/upgrade/from-205130326245fa8175bc390ce58b387b92d568a7.sql @@ -0,0 +1,41 @@ +-- +-- Upgrade the database from commit ID 205130326245fa8175bc390ce58b387b92d568a7 +-- +-- Run this from the top-level directory +-- + + +\i database/config.sql +\c :db_name + +BEGIN; + DROP FUNCTION finish_task( INT , INT , TEXT ); + CREATE FUNCTION finish_task( t_id INT , u_id INT , n_text TEXT ) + RETURNS INT + STRICT VOLATILE + SECURITY INVOKER + AS $finish_task$ + BEGIN + PERFORM 1 FROM tasks_single_view t + WHERE id = t_id AND badness = 0; + IF NOT FOUND THEN + RETURN 2; + END IF; + + BEGIN + INSERT INTO completed_tasks ( task_id , user_id ) + VALUES ( t_id , u_id ); + EXCEPTION + WHEN unique_violation THEN + RETURN 1; + END; + + UPDATE tasks SET user_id_assigned = NULL WHERE task_id = t_id; + INSERT INTO notes ( task_id , user_id , note_text ) + VALUES ( t_id , u_id , n_text ); + RETURN 0; + END; + $finish_task$ LANGUAGE plpgsql; + REVOKE EXECUTE ON FUNCTION finish_task( INT , INT , TEXT ) FROM PUBLIC; + GRANT EXECUTE ON FUNCTION finish_task( INT , INT , TEXT ) TO :webapp_user; +COMMIT;