diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.10.0/1.10.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.10.0/1.10.0.sql index ac1bfa2de..4474cb693 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.10.0/1.10.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.10.0/1.10.0.sql @@ -1,27 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.9.0-ee'; - next_version CONSTANT text := 'v1.10.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; +\set previous_version 'v1.9.0-ee' +\set next_version 'v1.10.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 'v1.10.0-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- -- Backup dashboard & search data: DO $$ @@ -669,4 +665,10 @@ COMMIT; CREATE INDEX CONCURRENTLY IF NOT EXISTS clicks_selector_idx ON events.clicks (selector); CREATE INDEX CONCURRENTLY IF NOT EXISTS clicks_path_idx ON events.clicks (path); CREATE INDEX CONCURRENTLY IF NOT EXISTS clicks_path_gin_idx ON events.clicks USING GIN (path gin_trgm_ops); -CREATE INDEX CONCURRENTLY IF NOT EXISTS issues_project_id_issue_id_idx ON public.issues (project_id, issue_id); \ No newline at end of file +CREATE INDEX CONCURRENTLY IF NOT EXISTS issues_project_id_issue_id_idx ON public.issues (project_id, issue_id); + +\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 \ No newline at end of file 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 6fd5c9dc7..b54240afc 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,26 +1,23 @@ -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; +\set previous_version 'v1.10.0-ee' +\set next_version 'v1.11.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 'v1.11.0-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- ALTER TYPE issue_type ADD VALUE IF NOT EXISTS 'mouse_thrashing'; @@ -42,4 +39,10 @@ ALTER TABLE IF EXISTS public.projects "defaultInputMode": "obscured" }'::jsonb; -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.12.0/1.12.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.12.0/1.12.0.sql index 6a68cbaa9..195a7061f 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.12.0/1.12.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.12.0/1.12.0.sql @@ -1,27 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.11.0-ee'; - next_version CONSTANT text := 'v1.12.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; +\set previous_version 'v1.11.0-ee' +\set next_version 'v1.12.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 'v1.12.0-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- ALTER TYPE issue_type ADD VALUE IF NOT EXISTS 'app_crash'; CREATE TABLE IF NOT EXISTS public.projects_stats @@ -36,4 +32,10 @@ CREATE TABLE IF NOT EXISTS public.projects_stats CREATE INDEX IF NOT EXISTS projects_stats_project_id_idx ON public.projects_stats (project_id); -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.5.0/1.5.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.5.0/1.5.0.sql index a73032e41..f54fa5e60 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.5.0/1.5.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.5.0/1.5.0.sql @@ -1,26 +1,21 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.4.0-ee'; - next_version CONSTANT text := 'v1.5.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; +\set previous_version 'v1.4.0-ee' +\set next_version 'v1.5.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 'v1.5.0-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec -- CREATE TABLE IF NOT EXISTS traces @@ -183,4 +178,10 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS alerts_project_id_idx ON alerts (project CREATE INDEX CONCURRENTLY IF NOT EXISTS alerts_series_id_idx ON alerts (series_id); CREATE INDEX CONCURRENTLY IF NOT EXISTS metrics_user_id_is_public_idx ON public.metrics (user_id, is_public); CREATE INDEX CONCURRENTLY IF NOT EXISTS metric_series_metric_id_idx ON public.metric_series (metric_id); -CREATE INDEX CONCURRENTLY IF NOT EXISTS funnels_project_id_idx ON public.funnels (project_id); \ No newline at end of file +CREATE INDEX CONCURRENTLY IF NOT EXISTS funnels_project_id_idx ON public.funnels (project_id); + +\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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.5.1/1.5.1.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.5.1/1.5.1.sql index e5f19444c..8e8899c08 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.5.1/1.5.1.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.5.1/1.5.1.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.0-ee'; - next_version CONSTANT text := 'v1.5.1-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; +\set previous_version 'v1.5.0-ee' +\set next_version 'v1.5.1-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 'v1.5.1-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- COMMIT; @@ -55,3 +52,9 @@ ALTER TYPE country ADD VALUE IF NOT EXISTS 'WK'; ALTER TYPE country ADD VALUE IF NOT EXISTS 'YD'; ALTER TYPE country ADD VALUE IF NOT EXISTS 'YU'; ALTER TYPE country ADD VALUE IF NOT EXISTS 'ZR'; + +\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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.5.2/1.5.2.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.5.2/1.5.2.sql index 675ecb871..08a0e525e 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.5.2/1.5.2.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.5.2/1.5.2.sql @@ -1,25 +1,28 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.1-ee'; - next_version CONSTANT text := 'v1.5.2-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; +\set previous_version 'v1.5.1-ee' +\set next_version 'v1.5.2-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 'v1.5.2-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec -COMMIT; \ No newline at end of file +-- + +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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.5.3/1.5.3.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.5.3/1.5.3.sql index 55494b9c9..815a2c2ed 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.5.3/1.5.3.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.5.3/1.5.3.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.2-ee'; - next_version CONSTANT text := 'v1.5.3-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; +\set previous_version 'v1.5.2-ee' +\set next_version 'v1.5.3-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 'v1.5.3-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- UPDATE metrics SET is_public= TRUE; @@ -112,4 +109,10 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS requests_status_code_nn_idx ON events_co CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_request_body_nn_idx ON events.graphql (request_body) WHERE request_body IS NOT NULL; CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_request_body_nn_gin_idx ON events.graphql USING GIN (request_body gin_trgm_ops) WHERE request_body IS NOT NULL; CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_response_body_nn_idx ON events.graphql (response_body) WHERE response_body IS NOT NULL; -CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_response_body_nn_gin_idx ON events.graphql USING GIN (response_body gin_trgm_ops) WHERE response_body IS NOT NULL; \ No newline at end of file +CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_response_body_nn_gin_idx ON events.graphql USING GIN (response_body gin_trgm_ops) WHERE response_body IS NOT NULL; + +\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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.5.4/1.5.4.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.5.4/1.5.4.sql index fcb9cd832..a40c1e708 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.5.4/1.5.4.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.5.4/1.5.4.sql @@ -1,29 +1,25 @@ -\set ON_ERROR_STOP true -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.3-ee'; - next_version CONSTANT text := 'v1.5.4-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; - SET client_min_messages TO NOTICE; +\set ON_ERROR_STOP true +\set previous_version 'v1.5.3-ee' +\set next_version 'v1.5.4-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 'v1.5.4-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- -- to detect duplicate users and delete them if possible DO @@ -106,3 +102,9 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_value_usercountryonly_gin_i CREATE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_value_userdeviceonly_gin_idx ON public.autocomplete USING GIN (value gin_trgm_ops) WHERE type = 'USERDEVICE'; CREATE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_value_useridonly_gin_idx ON public.autocomplete USING GIN (value gin_trgm_ops) WHERE type = 'USERID'; CREATE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_value_userosonly_gin_idx ON public.autocomplete USING GIN (value gin_trgm_ops) WHERE type = 'USEROS'; + +\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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.6.0/1.6.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.6.0/1.6.0.sql index 1f545b1d6..726c9a610 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.6.0/1.6.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.6.0/1.6.0.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.4-ee'; - next_version CONSTANT text := 'v1.6.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; +\set previous_version 'v1.5.4-ee' +\set next_version 'v1.6.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 'v1.6.0-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- CREATE TABLE IF NOT EXISTS dashboards @@ -362,4 +359,10 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_query_nn_idx ON events.pages (quer CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_query_nn_gin_idx ON events.pages USING GIN (query gin_trgm_ops) WHERE query IS NOT NULL; CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_path_session_id_timestamp_idx ON events.pages (path, session_id, timestamp); -CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_path_pathLNGT2_idx ON events.pages (path) WHERE length(path) > 2; \ No newline at end of file +CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_path_pathLNGT2_idx ON events.pages (path) WHERE length(path) > 2; + +\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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.7.0/1.7.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.7.0/1.7.0.sql index fc62e3767..09611988a 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.7.0/1.7.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.7.0/1.7.0.sql @@ -1,27 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.6.0-ee'; - next_version CONSTANT text := 'v1.7.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; +\set previous_version 'v1.6.0-ee' +\set next_version 'v1.7.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; -CREATE OR REPLACE - FUNCTION openreplay_version() +SELECT format($fn_def$ +CREATE OR REPLACE FUNCTION openreplay_version() RETURNS text AS $$ -SELECT 'v1.7.0-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- UPDATE roles SET permissions=array_remove(permissions, 'ERRORS'); @@ -230,4 +226,10 @@ $$ END $$; DROP INDEX IF EXISTS autocomplete_unique; -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.8.0/1.8.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.8.0/1.8.0.sql index aeb87b3ff..be236523b 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.8.0/1.8.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.8.0/1.8.0.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.7.0-ee'; - next_version CONSTANT text := 'v1.8.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; +\set previous_version 'v1.7.0-ee' +\set next_version 'v1.8.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 'v1.8.0-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- ALTER TABLE IF EXISTS projects ADD COLUMN IF NOT EXISTS first_recorded_session_at timestamp without time zone NULL DEFAULT NULL, @@ -65,4 +62,10 @@ DROP INDEX IF EXISTS autocomplete_unique; DROP INDEX IF EXISTS events_common.requests_response_body_nn_idx; DROP INDEX IF EXISTS events_common.requests_request_body_nn_idx; -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.8.1/1.8.1.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.8.1/1.8.1.sql index 59c8819a7..0a5b52cf7 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.8.1/1.8.1.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.8.1/1.8.1.sql @@ -1,27 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.8.0-ee'; - next_version CONSTANT text := 'v1.8.1-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; +\set previous_version 'v1.8.0-ee' +\set next_version 'v1.8.1-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 'v1.8.1-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- INSERT INTO metrics (name, category, default_config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type) @@ -52,4 +48,10 @@ DROP INDEX IF EXISTS oauth_authentication_user_id_provider_key; CREATE UNIQUE INDEX IF NOT EXISTS oauth_authentication_unique_user_id_provider_idx ON oauth_authentication (user_id, provider); -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.9.0/1.9.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.9.0/1.9.0.sql index 8e969aeb6..96d422b73 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.9.0/1.9.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.9.0/1.9.0.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.8.1-ee'; - next_version CONSTANT text := 'v1.9.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; +\set previous_version 'v1.8.1-ee' +\set next_version 'v1.9.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 'v1.9.0-ee' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- ALTER TABLE IF EXISTS public.tenants ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT), @@ -103,4 +100,10 @@ WHERE NOT is_predefined COMMIT; -CREATE INDEX CONCURRENTLY IF NOT EXISTS requests_session_id_status_code_nn_idx ON events_common.requests (session_id, status_code) WHERE status_code IS NOT NULL; \ No newline at end of file +CREATE INDEX CONCURRENTLY IF NOT EXISTS requests_session_id_status_code_nn_idx ON events_common.requests (session_id, status_code) WHERE status_code IS NOT NULL; + +\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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.10.0/1.10.0.sql b/scripts/schema/db/init_dbs/postgresql/1.10.0/1.10.0.sql index d7a6af576..5fff0e13d 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.10.0/1.10.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.10.0/1.10.0.sql @@ -1,27 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.9.0'; - next_version CONSTANT text := 'v1.10.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; +\set previous_version 'v1.9.0' +\set next_version 'v1.10.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 'v1.10.0' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- -- Backup dashboard & search data: DO $$ @@ -644,3 +640,9 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS clicks_selector_idx ON events.clicks (se CREATE INDEX CONCURRENTLY IF NOT EXISTS clicks_path_idx ON events.clicks (path); CREATE INDEX CONCURRENTLY IF NOT EXISTS clicks_path_gin_idx ON events.clicks USING GIN (path gin_trgm_ops); CREATE INDEX CONCURRENTLY IF NOT EXISTS issues_project_id_issue_id_idx ON public.issues (project_id, issue_id); + +\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 \ No newline at end of file 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 cdab6f1ad..9b05fa21e 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,27 +1,23 @@ -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; +\set previous_version 'v1.10.0' +\set next_version 'v1.11.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 'v1.11.0' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- ALTER TYPE issue_type ADD VALUE IF NOT EXISTS 'mouse_thrashing'; LOCK TABLE ONLY events.inputs IN ACCESS EXCLUSIVE MODE; @@ -42,4 +38,10 @@ ALTER TABLE IF EXISTS public.projects "defaultInputMode": "obscured" }'::jsonb; -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.12.0/1.12.0.sql b/scripts/schema/db/init_dbs/postgresql/1.12.0/1.12.0.sql index ae2036f3f..f1b643647 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.12.0/1.12.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.12.0/1.12.0.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.11.0'; - next_version CONSTANT text := 'v1.12.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; +\set previous_version 'v1.11.0' +\set next_version 'v1.12.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 'v1.12.0' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- ALTER TYPE issue_type ADD VALUE IF NOT EXISTS 'app_crash'; @@ -36,4 +33,10 @@ CREATE TABLE IF NOT EXISTS public.projects_stats CREATE INDEX IF NOT EXISTS projects_stats_project_id_idx ON public.projects_stats (project_id); -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.5.0/1.5.0.sql b/scripts/schema/db/init_dbs/postgresql/1.5.0/1.5.0.sql index f0a3203b7..3e9a1b1bf 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.5.0/1.5.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.5.0/1.5.0.sql @@ -1,26 +1,21 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.4.0'; - next_version CONSTANT text := 'v1.5.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; +\set previous_version 'v1.4.0' +\set next_version 'v1.5.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 'v1.5.0' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec -- CREATE INDEX IF NOT EXISTS user_favorite_sessions_user_id_session_id_idx ON user_favorite_sessions (user_id, session_id); @@ -111,4 +106,10 @@ ALTER TABLE public.metrics CREATE INDEX IF NOT EXISTS resources_timestamp_duration_durationgt0NN_idx ON events.resources (timestamp, duration) WHERE duration > 0 AND duration IS NOT NULL; COMMIT; -ALTER TYPE public.error_source ADD VALUE IF NOT EXISTS 'elasticsearch'; -- cannot add new value inside a transaction block \ No newline at end of file +ALTER TYPE public.error_source ADD VALUE IF NOT EXISTS 'elasticsearch'; -- cannot add new value inside a transaction block + +\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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.5.1/1.5.1.sql b/scripts/schema/db/init_dbs/postgresql/1.5.1/1.5.1.sql index c637b072d..25d776598 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.5.1/1.5.1.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.5.1/1.5.1.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.0'; - next_version CONSTANT text := 'v1.5.1'; - 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; +\set previous_version 'v1.5.0' +\set next_version 'v1.5.1' +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 'v1.5.1' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- COMMIT; @@ -54,4 +51,10 @@ ALTER TYPE country ADD VALUE IF NOT EXISTS 'VD'; ALTER TYPE country ADD VALUE IF NOT EXISTS 'WK'; ALTER TYPE country ADD VALUE IF NOT EXISTS 'YD'; ALTER TYPE country ADD VALUE IF NOT EXISTS 'YU'; -ALTER TYPE country ADD VALUE IF NOT EXISTS 'ZR'; \ No newline at end of file +ALTER TYPE country ADD VALUE IF NOT EXISTS 'ZR'; + +\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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.5.2/1.5.2.sql b/scripts/schema/db/init_dbs/postgresql/1.5.2/1.5.2.sql index a94c1c3e9..01f87fdb6 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.5.2/1.5.2.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.5.2/1.5.2.sql @@ -1,25 +1,28 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.1'; - next_version CONSTANT text := 'v1.5.2'; - 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; +\set previous_version 'v1.5.1' +\set next_version 'v1.5.2' +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 'v1.5.2' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec -COMMIT; \ No newline at end of file +-- + +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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.5.3/1.5.3.sql b/scripts/schema/db/init_dbs/postgresql/1.5.3/1.5.3.sql index 5b5bb92c4..5ab146527 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.5.3/1.5.3.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.5.3/1.5.3.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.2'; - next_version CONSTANT text := 'v1.5.3'; - 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; +\set previous_version 'v1.5.2' +\set next_version 'v1.5.3' +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 'v1.5.3' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- UPDATE metrics SET is_public= TRUE; @@ -110,4 +107,10 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS requests_status_code_nn_idx ON events_co CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_request_body_nn_idx ON events.graphql (request_body) WHERE request_body IS NOT NULL; CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_request_body_nn_gin_idx ON events.graphql USING GIN (request_body gin_trgm_ops) WHERE request_body IS NOT NULL; CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_response_body_nn_idx ON events.graphql (response_body) WHERE response_body IS NOT NULL; -CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_response_body_nn_gin_idx ON events.graphql USING GIN (response_body gin_trgm_ops) WHERE response_body IS NOT NULL; \ No newline at end of file +CREATE INDEX CONCURRENTLY IF NOT EXISTS graphql_response_body_nn_gin_idx ON events.graphql USING GIN (response_body gin_trgm_ops) WHERE response_body IS NOT NULL; + +\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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.5.4/1.5.4.sql b/scripts/schema/db/init_dbs/postgresql/1.5.4/1.5.4.sql index 68aa530d3..c6fcddedb 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.5.4/1.5.4.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.5.4/1.5.4.sql @@ -1,29 +1,25 @@ -\set ON_ERROR_STOP true -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.3'; - next_version CONSTANT text := 'v1.5.4'; - 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; - SET client_min_messages TO NOTICE; +\set ON_ERROR_STOP true +\set previous_version 'v1.5.3' +\set next_version 'v1.5.4' +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 'v1.5.4' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- -- to detect duplicate users and delete them if possible DO @@ -106,3 +102,9 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_value_usercountryonly_gin_i CREATE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_value_userdeviceonly_gin_idx ON public.autocomplete USING GIN (value gin_trgm_ops) WHERE type = 'USERDEVICE'; CREATE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_value_useridonly_gin_idx ON public.autocomplete USING GIN (value gin_trgm_ops) WHERE type = 'USERID'; CREATE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_value_userosonly_gin_idx ON public.autocomplete USING GIN (value gin_trgm_ops) WHERE type = 'USEROS'; + +\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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.6.0/1.6.0.sql b/scripts/schema/db/init_dbs/postgresql/1.6.0/1.6.0.sql index cf5c88eab..91fff519e 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.6.0/1.6.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.6.0/1.6.0.sql @@ -1,27 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.5.4'; - next_version CONSTANT text := 'v1.6.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; +\set previous_version 'v1.5.4' +\set next_version 'v1.6.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 'v1.6.0' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- CREATE TABLE IF NOT EXISTS dashboards ( @@ -362,4 +358,10 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_query_nn_idx ON events.pages (quer CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_query_nn_gin_idx ON events.pages USING GIN (query gin_trgm_ops) WHERE query IS NOT NULL; CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_path_session_id_timestamp_idx ON events.pages (path, session_id, timestamp); -CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_path_pathLNGT2_idx ON events.pages (path) WHERE length(path) > 2; \ No newline at end of file +CREATE INDEX CONCURRENTLY IF NOT EXISTS pages_path_pathLNGT2_idx ON events.pages (path) WHERE length(path) > 2; + +\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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.7.0/1.7.0.sql b/scripts/schema/db/init_dbs/postgresql/1.7.0/1.7.0.sql index 88a7acca7..2ff05492a 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.7.0/1.7.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.7.0/1.7.0.sql @@ -1,27 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.6.0'; - next_version CONSTANT text := 'v1.7.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; +\set previous_version 'v1.6.0' +\set next_version 'v1.7.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 'v1.7.0' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- ALTER TABLE IF EXISTS dashboards ADD COLUMN IF NOT EXISTS description text NOT NULL DEFAULT ''; @@ -218,4 +214,10 @@ $$ END $$; DROP INDEX IF EXISTS autocomplete_unique; -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.8.0/1.8.0.sql b/scripts/schema/db/init_dbs/postgresql/1.8.0/1.8.0.sql index 93e05f01f..682fd1ac2 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.8.0/1.8.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.8.0/1.8.0.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.7.0'; - next_version CONSTANT text := 'v1.8.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; +\set previous_version 'v1.7.0' +\set next_version 'v1.8.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 'v1.8.0' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- ALTER TABLE IF EXISTS projects ADD COLUMN IF NOT EXISTS first_recorded_session_at timestamp without time zone NULL DEFAULT NULL, @@ -64,4 +61,10 @@ BEGIN; DROP INDEX IF EXISTS autocomplete_unique; DROP INDEX IF EXISTS events_common.requests_response_body_nn_idx; DROP INDEX IF EXISTS events_common.requests_request_body_nn_idx; -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.8.1/1.8.1.sql b/scripts/schema/db/init_dbs/postgresql/1.8.1/1.8.1.sql index 3b906c9ea..226b2a454 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.8.1/1.8.1.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.8.1/1.8.1.sql @@ -1,27 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.8.0'; - next_version CONSTANT text := 'v1.8.1'; - 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; +\set previous_version 'v1.8.0' +\set next_version 'v1.8.1' +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 'v1.8.1' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec +-- INSERT INTO metrics (name, category, default_config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type) @@ -52,4 +48,10 @@ DROP INDEX IF EXISTS oauth_authentication_user_id_provider_key; CREATE UNIQUE INDEX IF NOT EXISTS oauth_authentication_unique_user_id_provider_idx ON oauth_authentication (user_id, provider); -COMMIT; \ No newline at end of file +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 \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/postgresql/1.9.0/1.9.0.sql b/scripts/schema/db/init_dbs/postgresql/1.9.0/1.9.0.sql index 1b483432c..847a5157e 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.9.0/1.9.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.9.0/1.9.0.sql @@ -1,26 +1,23 @@ -DO -$$ - DECLARE - previous_version CONSTANT text := 'v1.8.1'; - next_version CONSTANT text := 'v1.9.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; +\set previous_version 'v1.8.1' +\set next_version 'v1.9.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 'v1.9.0' +SELECT '%1$s' $$ LANGUAGE sql IMMUTABLE; +$fn_def$, :'next_version') +\gexec + +-- ALTER TABLE IF EXISTS public.tenants ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT), @@ -93,4 +90,10 @@ WHERE NOT is_predefined COMMIT; -CREATE INDEX CONCURRENTLY IF NOT EXISTS requests_session_id_status_code_nn_idx ON events_common.requests (session_id, status_code) WHERE status_code IS NOT NULL; \ No newline at end of file +CREATE INDEX CONCURRENTLY IF NOT EXISTS requests_session_id_status_code_nn_idx ON events_common.requests (session_id, status_code) WHERE status_code IS NOT NULL; + +\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 \ No newline at end of file