From 13986a3c55b6423256a3746036945ef2bbe52c22 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Mon, 20 Mar 2023 13:39:50 +0100 Subject: [PATCH] feat(DB): stop upgrade on version hopping --- .../db/init_dbs/postgresql/1.11.0/1.11.0.sql | 17 +++++++++++++++++ .../db/init_dbs/postgresql/1.11.0/1.11.0.sql | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.11.0/1.11.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.11.0/1.11.0.sql index cf80dcad1..21544f62c 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.11.0/1.11.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.11.0/1.11.0.sql @@ -1,3 +1,20 @@ +DO +$$ + DECLARE + previous_version CONSTANT text := 'v1.10.0-ee'; + next_version CONSTANT text := 'v1.11.0-ee'; + BEGIN + IF (SELECT openreplay_version()) = previous_version THEN + raise notice 'valid previous DB version'; + ELSEIF (SELECT openreplay_version()) = next_version THEN + raise notice 'new version detected, nothing to do'; + ELSE + RAISE EXCEPTION 'upgrade to % failed, invalid previous version, expected %, got %', next_version,previous_version,(SELECT openreplay_version()); + END IF; + END ; +$$ +LANGUAGE plpgsql; + BEGIN; CREATE OR REPLACE FUNCTION openreplay_version() RETURNS text AS diff --git a/scripts/schema/db/init_dbs/postgresql/1.11.0/1.11.0.sql b/scripts/schema/db/init_dbs/postgresql/1.11.0/1.11.0.sql index 41521a886..0fde93c48 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.11.0/1.11.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.11.0/1.11.0.sql @@ -1,3 +1,20 @@ +DO +$$ + DECLARE + previous_version CONSTANT text := 'v1.10.0'; + next_version CONSTANT text := 'v1.11.0'; + BEGIN + IF (SELECT openreplay_version()) = previous_version THEN + raise notice 'valid previous DB version'; + ELSEIF (SELECT openreplay_version()) = next_version THEN + raise notice 'new version detected, nothing to do'; + ELSE + RAISE EXCEPTION 'upgrade to % failed, invalid previous version, expected %, got %', next_version,previous_version,(SELECT openreplay_version()); + END IF; + END ; +$$ +LANGUAGE plpgsql; + BEGIN; CREATE OR REPLACE FUNCTION openreplay_version() RETURNS text AS