--- /dev/null
+-- Computed new value for sequence associated to table
+CREATE OR REPLACE FUNCTION init_sequence(tableName varchar) RETURNS void AS '
+DECLARE
+ next_id_table1 INTEGER;
+BEGIN
+ EXECUTE ''SELECT MAX(id)+1 FROM '' || tablename INTO next_id_table1;
+ EXECUTE ''ALTER SEQUENCE seq_'' || tableName || '' RESTART '' || CAST(next_id_table1 as varchar(10));
+END;'
+ LANGUAGE 'plpgsql';
+
+-- Convertion on scenariodefinitionabstarct
+CREATE OR REPLACE FUNCTION updateScenarioDef() RETURNS void AS '
+DECLARE
+ rec RECORD;
+BEGIN
+ for rec in (select id, pid from scenariodefinition) loop
+ execute ''update scenariodefinitionabstract set pid='' || quote_literal(rec.pid) || '' where id='' || quote_literal(rec.id);
+ end loop;
+END;'
+ LANGUAGE 'plpgsql';
+
+-- Function for deleting FK which as unknown name (generted by hibernate)
+CREATE OR REPLACE FUNCTION deleteConstraint(tableName varchar, colName1 varchar, colName2 varchar) RETURNS void AS '
+DECLARE
+ rec RECORD;
+BEGIN
+ for rec in (select * from information_schema.key_column_usage where table_name=tableName and (column_name=colName1 or column_name=colName2) and position(''fk'' in constraint_name) = 1 and position(''fk_'' in constraint_name) !=1) loop
+ execute ''ALTER TABLE ''|| tableName ||'' DROP CONSTRAINT '' || rec.constraint_name;
+ end loop;
+END;'
+ LANGUAGE 'plpgsql';
\ No newline at end of file