diff --git a/ee/scripts/schema/db/init_dbs/clickhouse/1.18.0/1.18.0.sql b/ee/scripts/schema/db/init_dbs/clickhouse/1.18.0/1.18.0.sql new file mode 100644 index 000000000..54d88f4e3 --- /dev/null +++ b/ee/scripts/schema/db/init_dbs/clickhouse/1.18.0/1.18.0.sql @@ -0,0 +1 @@ +CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.18.0-ee'; \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql b/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql index 0d406b36d..fb6fa6f20 100644 --- a/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql +++ b/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.17.0-ee'; +CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.18.0-ee'; CREATE DATABASE IF NOT EXISTS experimental; CREATE TABLE IF NOT EXISTS experimental.autocomplete diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.18.0/1.18.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.18.0/1.18.0.sql new file mode 100644 index 000000000..d58f3610f --- /dev/null +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.18.0/1.18.0.sql @@ -0,0 +1,29 @@ +\set previous_version 'v1.17.0-ee' +\set next_version 'v1.18.0-ee' +SELECT openreplay_version() AS current_version, + openreplay_version() = :'previous_version' AS valid_previous, + openreplay_version() = :'next_version' AS is_next +\gset + +\if :valid_previous +\echo valid previous DB version :'previous_version', starting DB upgrade to :'next_version' +BEGIN; +SELECT format($fn_def$ +CREATE OR REPLACE FUNCTION openreplay_version() + RETURNS text AS +$$ +SELECT '%1$s' +$$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- +DROP FUNCTION IF EXISTS events.funnel(steps integer[], m integer); + +COMMIT; + +\elif :is_next +\echo new version detected :'next_version', nothing to do +\else +\warn skipping DB upgrade of :'next_version', expected previous version :'previous_version', found :'current_version' +\endif diff --git a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql index 03f6835ad..2aacbbdb8 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -1,4 +1,4 @@ -\set or_version 'v1.17.0-ee' +\set or_version 'v1.18.0-ee' SET client_min_messages TO NOTICE; \set ON_ERROR_STOP true SELECT EXISTS (SELECT 1 @@ -48,30 +48,6 @@ end; $$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION events.funnel(steps integer[], m integer) RETURNS boolean AS -$$ -DECLARE - step integer; - c integer := 0; -BEGIN - FOREACH step IN ARRAY steps - LOOP - IF step + c = 0 THEN - IF c = 0 THEN - RETURN false; - END IF; - c := 0; - CONTINUE; - END IF; - IF c + 1 = step THEN - c := step; - END IF; - END LOOP; - RETURN c = m; -END; -$$ LANGUAGE plpgsql IMMUTABLE; - - CREATE OR REPLACE FUNCTION notify_integration() RETURNS trigger AS $$ BEGIN diff --git a/ee/scripts/schema/db/rollback_dbs/postgresql/1.18.0/1.18.0.sql b/ee/scripts/schema/db/rollback_dbs/postgresql/1.18.0/1.18.0.sql new file mode 100644 index 000000000..f7d048473 --- /dev/null +++ b/ee/scripts/schema/db/rollback_dbs/postgresql/1.18.0/1.18.0.sql @@ -0,0 +1,28 @@ +\set previous_version 'v1.18.0-ee' +\set next_version 'v1.17.0-ee' +SELECT openreplay_version() AS current_version, + openreplay_version() = :'previous_version' AS valid_previous, + openreplay_version() = :'next_version' AS is_next +\gset + +\if :valid_previous +\echo valid previous DB version :'previous_version', starting DB downgrade to :'next_version' +BEGIN; +SELECT format($fn_def$ +CREATE OR REPLACE FUNCTION openreplay_version() + RETURNS text AS +$$ +SELECT '%1$s' +$$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- + +COMMIT; + +\elif :is_next +\echo new version detected :'next_version', nothing to do +\else +\warn skipping DB downgrade of :'next_version', expected previous version :'previous_version', found :'current_version' +\endif \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.18.0/1.18.0.sql b/scripts/schema/db/init_dbs/postgresql/1.18.0/1.18.0.sql new file mode 100644 index 000000000..dc3af11ab --- /dev/null +++ b/scripts/schema/db/init_dbs/postgresql/1.18.0/1.18.0.sql @@ -0,0 +1,29 @@ +\set previous_version 'v1.17.0' +\set next_version 'v1.18.0' +SELECT openreplay_version() AS current_version, + openreplay_version() = :'previous_version' AS valid_previous, + openreplay_version() = :'next_version' AS is_next +\gset + +\if :valid_previous +\echo valid previous DB version :'previous_version', starting DB upgrade to :'next_version' +BEGIN; +SELECT format($fn_def$ +CREATE OR REPLACE FUNCTION openreplay_version() + RETURNS text AS +$$ +SELECT '%1$s' +$$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- +DROP FUNCTION IF EXISTS events.funnel(steps integer[], m integer); + +COMMIT; + +\elif :is_next +\echo new version detected :'next_version', nothing to do +\else +\warn skipping DB upgrade of :'next_version', expected previous version :'previous_version', found :'current_version' +\endif diff --git a/scripts/schema/db/init_dbs/postgresql/init_schema.sql b/scripts/schema/db/init_dbs/postgresql/init_schema.sql index 444b9bbc2..76222954e 100644 --- a/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -1,4 +1,4 @@ -\set or_version 'v1.17.0' +\set or_version 'v1.18.0' SET client_min_messages TO NOTICE; \set ON_ERROR_STOP true SELECT EXISTS (SELECT 1 @@ -48,30 +48,6 @@ end; $$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION events.funnel(steps integer[], m integer) RETURNS boolean AS -$$ -DECLARE - step integer; - c integer := 0; -BEGIN - FOREACH step IN ARRAY steps - LOOP - IF step + c = 0 THEN - IF c = 0 THEN - RETURN false; - END IF; - c := 0; - CONTINUE; - END IF; - IF c + 1 = step THEN - c := step; - END IF; - END LOOP; - RETURN c = m; -END; -$$ LANGUAGE plpgsql IMMUTABLE; - - CREATE OR REPLACE FUNCTION notify_integration() RETURNS trigger AS $$ BEGIN diff --git a/scripts/schema/db/rollback_dbs/postgresql/1.18.0/1.18.0.sql b/scripts/schema/db/rollback_dbs/postgresql/1.18.0/1.18.0.sql new file mode 100644 index 000000000..ce8f250bc --- /dev/null +++ b/scripts/schema/db/rollback_dbs/postgresql/1.18.0/1.18.0.sql @@ -0,0 +1,29 @@ +\set previous_version 'v1.18.0' +\set next_version 'v1.17.0' +SELECT openreplay_version() AS current_version, + openreplay_version() = :'previous_version' AS valid_previous, + openreplay_version() = :'next_version' AS is_next +\gset + +\if :valid_previous +\echo valid previous DB version :'previous_version', starting DB downgrade to :'next_version' +BEGIN; +SELECT format($fn_def$ +CREATE OR REPLACE FUNCTION openreplay_version() + RETURNS text AS +$$ +SELECT '%1$s' +$$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- + + +COMMIT; + +\elif :is_next +\echo new version detected :'next_version', nothing to do +\else +\warn skipping DB downgrade of :'next_version', expected previous version :'previous_version', found :'current_version' +\endif \ No newline at end of file