-- Migration from 051 to 052

-- Add QUERY_TYPE column to QUERIES
CREATE DOMAIN QUERY_TYPE AS VARCHAR(40) CHECK (VALUE IN ('GENERIC', 'EXPERIMENT', 'SAMPLE', 'DATA_SET', 'MATERIAL'));
ALTER TABLE QUERIES ADD COLUMN QUERY_TYPE QUERY_TYPE;
UPDATE QUERIES SET QUERY_TYPE = 'GENERIC';
ALTER TABLE QUERIES ALTER COLUMN QUERY_TYPE SET NOT NULL; 

-- add DB_KEY column to QUERIES

ALTER TABLE queries ADD COLUMN db_key code NOT NULL DEFAULT '1';