Mercurial > hg > orthanc-databases
changeset 653:d5c889dea585 attach-custom-data
added missing files
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Tue, 11 Mar 2025 09:17:06 +0100 |
| parents | e5051580aeac |
| children | 12861c70239a |
| files | PostgreSQL/Plugins/SQL/Downgrades/Rev5ToRev4.sql PostgreSQL/Plugins/SQL/Upgrades/Rev4ToRev5.sql |
| diffstat | 2 files changed, 75 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PostgreSQL/Plugins/SQL/Downgrades/Rev5ToRev4.sql Tue Mar 11 09:17:06 2025 +0100 @@ -0,0 +1,56 @@ +-- This file contains an SQL procedure to downgrade from schema Rev5 to Rev4 (version = 6). +-- It removes the column that has been added in Rev5 + +-- these constraints were introduced in Rev5 +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, 4); -- GlobalProperty_DatabasePatchLevel +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PostgreSQL/Plugins/SQL/Upgrades/Rev4ToRev5.sql Tue Mar 11 09:17:06 2025 +0100 @@ -0,0 +1,19 @@ +-- This file contains part of the changes required to upgrade from Revision 4 to Revision 5 (DB version 6) +-- It actually contains only the changes that: + -- can not be executed with an idempotent statement in SQL + -- or would polute the PrepareIndex.sql +-- This file is executed only if the current schema is in revision 4 and it is executed +-- before PrepareIndex.sql that is idempotent. + + + +DO $body$ +BEGIN + + BEGIN + ALTER TABLE AttachedFiles ADD COLUMN customData TEXT; + EXCEPTION + WHEN duplicate_column THEN RAISE NOTICE 'column customData already exists in AttachedFiles.'; + END; + +END $body$ LANGUAGE plpgsql;
