Called during "update functions" by slonik to perform schema changes
declare
p_old alias for $1;
begin
-- upgrade sl_table
if p_old = '1.0.2' or p_old = '1.0.5' then
-- Add new column(s) sl_table.tab_relname, sl_table.tab_nspname
execute 'alter table sl_table add column tab_relname name';
execute 'alter table sl_table add column tab_nspname name';
-- populate the colums with data
update sl_table set
tab_relname = PGC.relname, tab_nspname = PGN.nspname
from pg_catalog.pg_class PGC, pg_catalog.pg_namespace PGN
where sl_table.tab_reloid = PGC.oid
and PGC.relnamespace = PGN.oid;
-- constrain the colums
execute 'alter table sl_table alter column tab_relname set NOT NULL';
execute 'alter table sl_table alter column tab_nspname set NOT NULL';
end if;
-- upgrade sl_sequence
if p_old = '1.0.2' or p_old = '1.0.5' then
-- Add new column(s) sl_sequence.seq_relname, sl_sequence.seq_nspname
execute 'alter table sl_sequence add column seq_relname name';
execute 'alter table sl_sequence add column seq_nspname name';
-- populate the columns with data
update sl_sequence set
seq_relname = PGC.relname, seq_nspname = PGN.nspname
from pg_catalog.pg_class PGC, pg_catalog.pg_namespace PGN
where sl_sequence.seq_reloid = PGC.oid
and PGC.relnamespace = PGN.oid;
-- constrain the data
execute 'alter table sl_sequence alter column seq_relname set NOT NULL';
execute 'alter table sl_sequence alter column seq_nspname set NOT NULL';
end if;
-- ----
-- Changes from 1.0.x to 1.1.0
-- ----
if p_old = '1.0.2' or p_old = '1.0.5' then
-- Add new column sl_node.no_spool for virtual spool nodes
execute 'alter table sl_node add column no_spool boolean';
update sl_node set no_spool = false;
end if;
return p_old;
end;