Skip to content

Commit

Permalink
feat(DB): DB changes for v1.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tahayk committed Feb 1, 2024
1 parent 8263773 commit 0ad7a43
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 51 deletions.
1 change: 1 addition & 0 deletions ee/scripts/schema/db/init_dbs/clickhouse/1.18.0/1.18.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.18.0-ee';
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 29 additions & 0 deletions ee/scripts/schema/db/init_dbs/postgresql/1.18.0/1.18.0.sql
Original file line number Diff line number Diff line change
@@ -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
26 changes: 1 addition & 25 deletions ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions ee/scripts/schema/db/rollback_dbs/postgresql/1.18.0/1.18.0.sql
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions scripts/schema/db/init_dbs/postgresql/1.18.0/1.18.0.sql
Original file line number Diff line number Diff line change
@@ -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
26 changes: 1 addition & 25 deletions scripts/schema/db/init_dbs/postgresql/init_schema.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions scripts/schema/db/rollback_dbs/postgresql/1.18.0/1.18.0.sql
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0ad7a43

Please sign in to comment.