Mercurial > hg > orthanc-databases
view PostgreSQL/Plugins/SQL/Downgrades/Rev3ToRev2.sql @ 571:7453fc5bef1a attach-custom-data
fix
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 26 Sep 2024 08:55:00 +0200 |
parents | 73e784792a51 |
children |
line wrap: on
line source
-- This file contains an SQL procedure to downgrade from schema Rev3 to Rev2 (version = 6). -- It removes the column that has been added in Rev3 -- these constraints were introduced in Rev3 ALTER TABLE AttachedFiles DROP COLUMN customData; -- reinstall previous triggers CREATE OR REPLACE FUNCTION CreateDeletedFilesTemporaryTable( ) RETURNS VOID AS $body$ BEGIN SET client_min_messages = warning; -- suppress NOTICE: relation "deletedresources" already exists, skipping -- note: temporary tables are created at session (connection) level -> they are likely to exist CREATE TEMPORARY TABLE IF NOT EXISTS DeletedFiles( uuid VARCHAR(64) NOT NULL, fileType INTEGER, compressedSize BIGINT, uncompressedSize BIGINT, compressionType INTEGER, uncompressedHash VARCHAR(40), compressedHash VARCHAR(40) ); RESET client_min_messages; -- clear the temporary table in case it has been created earlier in the session DELETE FROM DeletedFiles; END; $body$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION AttachedFileDeletedFunc() RETURNS TRIGGER AS $body$ BEGIN INSERT INTO DeletedFiles VALUES (old.uuid, old.filetype, old.compressedSize, old.uncompressedSize, old.compressionType, old.uncompressedHash, old.compressedHash); RETURN NULL; END; $body$ LANGUAGE plpgsql; DROP TRIGGER IF EXISTS AttachedFileDeleted on AttachedFiles; CREATE TRIGGER AttachedFileDeleted AFTER DELETE ON AttachedFiles FOR EACH ROW EXECUTE PROCEDURE AttachedFileDeletedFunc(); DELETE FROM GlobalProperties WHERE property IN (4); INSERT INTO GlobalProperties VALUES (4, 2); -- GlobalProperty_DatabasePatchLevel