Skip to content
Snippets Groups Projects
Commit 9dcdfdbf authored by Jean-Laurent DUZANT's avatar Jean-Laurent DUZANT
Browse files

FIX #19580 TIME 0:45 migrate chronos from parameters table to sequences

parent d3492af6
No related branches found
No related tags found
No related merge requests found
......@@ -6,12 +6,29 @@
-- --
-- *************************************************************************--
DO $$
DECLARE
last_chrono text;
chrono record;
chrono_id_seq text;
BEGIN
FOR chrono IN (SELECT id, param_value_int as value FROM parameters WHERE id LIKE 'chrono_%') LOOP
chrono_id_seq := CONCAT(chrono.id, '_seq');
IF NOT EXISTS (SELECT 0 FROM pg_class where relname = chrono_id_seq ) THEN
EXECUTE 'CREATE SEQUENCE ' || chrono_id_seq || ' INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;';
END IF;
EXECUTE 'SELECT setVal(''' || chrono_id_seq ||''',' || chrono.value ||',false)';
END LOOP;
END
$$;
CREATE OR REPLACE FUNCTION public.increase_chrono(chrono_id_seq text, chrono_id_name text) returns table (chrono_id bigint) as $$
DECLARE
retval bigint;
BEGIN
IF NOT EXISTS (SELECT 0 FROM pg_class where relname = chrono_id_seq ) THEN
EXECUTE 'CREATE SEQUENCE ' || chrono_id_seq || ' INCREMENT 1 MINVALUE 100 MAXVALUE 9223372036854775807 START 100 CACHE 1;';
EXECUTE 'CREATE SEQUENCE ' || chrono_id_seq || ' INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;';
END IF;
IF NOT EXISTS (SELECT 0 FROM parameters where id = chrono_id_name ) THEN
EXECUTE 'INSERT INTO parameters (id, param_value_int) VALUES ( ''' || chrono_id_name || ''', 1)';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment