From 24036ef94687300e98c742cfc268a2b5e9e87a88 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 5 Jan 2013 17:24:07 +0100 Subject: o Trying out dbdeploy. --- .../sql/dbdelta/1-person_badge-add-timestamps.sql | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/sql/dbdelta/1-person_badge-add-timestamps.sql (limited to 'src/main/sql/dbdelta') diff --git a/src/main/sql/dbdelta/1-person_badge-add-timestamps.sql b/src/main/sql/dbdelta/1-person_badge-add-timestamps.sql new file mode 100644 index 0000000..5b53145 --- /dev/null +++ b/src/main/sql/dbdelta/1-person_badge-add-timestamps.sql @@ -0,0 +1,21 @@ +ALTER TABLE person_badge ADD timestamps TIMESTAMP[]; + +DO $$ +DECLARE r RECORD; +DECLARE ts TIMESTAMP[]; +BEGIN + FOR r IN SELECT uuid, count FROM person_badge + LOOP + SELECT array_agg(x) FROM (SELECT current_timestamp FROM generate_series(1, r.count)) AS x INTO ts; + UPDATE person_badge SET timestamps=ts WHERE uuid=r.uuid; + END LOOP; +END$$; + +ALTER TABLE person_badge DROP count; + +--//@UNDO + +ALTER TABLE person_badge ADD count INT; +UPDATE person_badge SET count=array_length(timestamps, 1); +ALTER TABLE person_badge ALTER count SET NOT NULL; +ALTER TABLE person_badge DROP timestamps; -- cgit v1.2.3