-- this script updates the tables TASKANA_SCHEMA_VERSION and HISTORY_EVENTS.

SET search_path = %schemaName%;

INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('3.0.0', CURRENT_TIMESTAMP);

ALTER TABLE HISTORY_EVENTS DROP COLUMN COMMENT, DROP COLUMN OLD_DATA, DROP COLUMN NEW_DATA, ADD COLUMN DETAILS TEXT;

ALTER TABLE CLASSIFICATION ALTER COLUMN ID TYPE VARCHAR(40);

ALTER TABLE WORKBASKET ALTER COLUMN ID TYPE VARCHAR(40);

ALTER TABLE TASK ALTER COLUMN ID TYPE VARCHAR(40);

ALTER TABLE TASK ALTER COLUMN WORKBASKET_ID TYPE VARCHAR(40);

ALTER TABLE TASK ALTER COLUMN CLASSIFICATION_ID TYPE VARCHAR(40);

ALTER TABLE DISTRIBUTION_TARGETS ALTER COLUMN SOURCE_ID TYPE VARCHAR(40);

ALTER TABLE DISTRIBUTION_TARGETS ALTER COLUMN TARGET_ID TYPE VARCHAR(40);

ALTER TABLE WORKBASKET_ACCESS_LIST ALTER COLUMN ID TYPE VARCHAR(40);

ALTER TABLE WORKBASKET_ACCESS_LIST ALTER COLUMN WORKBASKET_ID TYPE VARCHAR(40);

ALTER TABLE OBJECT_REFERENCE ALTER COLUMN ID TYPE VARCHAR(40);

ALTER TABLE ATTACHMENT ALTER COLUMN ID TYPE VARCHAR(40);

ALTER TABLE ATTACHMENT ALTER COLUMN TASK_ID TYPE VARCHAR(40);

ALTER TABLE ATTACHMENT ALTER COLUMN CLASSIFICATION_ID TYPE VARCHAR(40);

ALTER TABLE TASK_COMMENT ALTER COLUMN ID TYPE VARCHAR(40);

ALTER TABLE TASK_COMMENT ALTER COLUMN TASK_ID TYPE VARCHAR(40);

CREATE TABLE CONFIGURATION (
    ENFORCE_SECURITY BOOLEAN NOT NULL
);

-- TSK-1227 allow null values in OBJECT_REFERENCE#SYSTEM and OBJECT_REFERENCE#SYSTEM_INSTANCE

ALTER TABLE OBJECT_REFERENCE ALTER COLUMN SYSTEM DROP NOT NULL;
ALTER TABLE OBJECT_REFERENCE ALTER COLUMN SYSTEM_INSTANCE DROP NOT NULL;

ALTER TABLE TASK ALTER COLUMN POR_SYSTEM DROP NOT NULL;
ALTER TABLE TASK ALTER COLUMN POR_INSTANCE DROP NOT NULL;


