changeset 642:cfddeec356c5

added version check
author Alain Mazy <am@orthanc.team>
date Fri, 14 Feb 2025 15:36:41 +0100 (2 months ago)
parents a66ad2d115fa
children 77004b16d7fe
files PostgreSQL/Plugins/SQL/Downgrades/Rev4ToRev3.sql
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/PostgreSQL/Plugins/SQL/Downgrades/Rev4ToRev3.sql	Fri Feb 14 13:25:40 2025 +0100
+++ b/PostgreSQL/Plugins/SQL/Downgrades/Rev4ToRev3.sql	Fri Feb 14 15:36:41 2025 +0100
@@ -1,6 +1,22 @@
 -- This file contains an SQL procedure to downgrade from schema Rev4 to Rev3 (version = 6).
   -- It re-installs the old childcount trigger mechanisms
 
+DO $$
+DECLARE
+    current_revision TEXT;
+    expected_revision TEXT;
+BEGIN
+    expected_revision := '4';
+
+    SELECT value INTO current_revision FROM GlobalProperties WHERE property = 4; -- GlobalProperty_DatabasePatchLevel
+
+    IF current_revision != expected_revision THEN
+        RAISE EXCEPTION 'Unexpected schema revision % to run this script.  Expected revision = %', current_revision, expected_revision;
+    END IF;
+END $$;
+
+---
+
 DROP TRIGGER IF EXISTS IncrementChildCount on Resources;
 DROP TRIGGER IF EXISTS DecrementChildCount on Resources;