-- ==============================================================
-- GNUmed database schema change script
--
-- Source database version: v5
-- Target database version: v6
--
-- License: GPL v2 or later
-- Author: Karsten Hilbert
-- 
-- ==============================================================
\set ON_ERROR_STOP 1

-- --------------------------------------------------------------
-- cleanup
drop table if exists ref.papersizes cascade;

-- create new table
create table ref.papersizes (
	pk serial
		primary key,
	name text
		unique
		not null,
	size point
		not null
);

-- transfer data
insert into ref.papersizes select * from public.papersizes;

-- adjust foreign keys
alter table public.form_print_defs
	drop constraint if exists "form_print_defs_fk_papersize_fkey";
alter table public.form_print_defs
	drop constraint if exists "$2";

alter table public.form_print_defs
	add foreign key(fk_papersize)
		references ref.papersizes(pk)
		on update cascade
		on delete restrict;

-- drop old table
drop table public.papersizes;

-- --------------------------------------------------------------
select public.log_script_insertion('$RCSfile: ref-papersizes.sql,v $', '$Revision: 1.2 $');
