From d76c5ce6e2da00b29865e187ed3d8420a0f33942 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Thu, 22 Jun 2023 12:33:58 +0100 Subject: [PATCH] feat(DB): feature-flags --- .../db/init_dbs/postgresql/init_schema.sql | 32 ++++++++++++++++++- .../db/init_dbs/postgresql/init_schema.sql | 28 ++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) 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 f68281a12..fc66afd81 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -133,7 +133,9 @@ $$ ('sessions_notes'), ('assist_records'), ('projects_stats'), - ('frontend_signals')) + ('frontend_signals'), + ('feature_flags'), + ('feature_flags_conditions')) select bool_and(exists(select * from information_schema.tables t where table_schema = 'public' @@ -895,6 +897,34 @@ $$ CREATE INDEX IF NOT EXISTS projects_stats_project_id_idx ON public.projects_stats (project_id); + CREATE TABLE IF NOT EXISTS public.feature_flags + ( + feature_flag_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + name text NOT NULL, + flag_key text NOT NULL, + description text NOT NULL, + flag_type text NOT NULL, + is_persist boolean NOT NULL DEFAULT FALSE, + is_active boolean NOT NULL DEFAULT FALSE, + created_by integer REFERENCES users (user_id) ON DELETE SET NULL, + updated_by integer REFERENCES users (user_id) ON DELETE SET NULL, + created_at timestamp without time zone NOT NULL DEFAULT timezone('utc'::text, now()), + updated_at timestamp without time zone NOT NULL DEFAULT timezone('utc'::text, now()), + deleted_at timestamp without time zone NULL DEFAULT NULL + ); + + CREATE INDEX IF NOT EXISTS idx_feature_flags_project_id ON public.feature_flags (project_id); + + CREATE TABLE IF NOT EXISTS public.feature_flags_conditions + ( + condition_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + feature_flag_id integer NOT NULL REFERENCES feature_flags (feature_flag_id) ON DELETE CASCADE, + name text NOT NULL, + rollout_percentage integer NOT NULL, + filters jsonb NOT NULL DEFAULT '[]'::jsonb + ); + RAISE NOTICE 'Created missing public schema tables'; END IF; END; diff --git a/scripts/schema/db/init_dbs/postgresql/init_schema.sql b/scripts/schema/db/init_dbs/postgresql/init_schema.sql index 4b046890f..e9557d0ee 100644 --- a/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -978,6 +978,34 @@ $$ CREATE INDEX projects_stats_project_id_idx ON public.projects_stats (project_id); + CREATE TABLE public.feature_flags + ( + feature_flag_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + name text NOT NULL, + flag_key text NOT NULL, + description text NOT NULL, + flag_type text NOT NULL, + is_persist boolean NOT NULL DEFAULT FALSE, + is_active boolean NOT NULL DEFAULT FALSE, + created_by integer REFERENCES users (user_id) ON DELETE SET NULL, + updated_by integer REFERENCES users (user_id) ON DELETE SET NULL, + created_at timestamp without time zone NOT NULL DEFAULT timezone('utc'::text, now()), + updated_at timestamp without time zone NOT NULL DEFAULT timezone('utc'::text, now()), + deleted_at timestamp without time zone NULL DEFAULT NULL + ); + + CREATE INDEX idx_feature_flags_project_id ON public.feature_flags (project_id); + + CREATE TABLE public.feature_flags_conditions + ( + condition_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + feature_flag_id integer NOT NULL REFERENCES feature_flags (feature_flag_id) ON DELETE CASCADE, + name text NOT NULL, + rollout_percentage integer NOT NULL, + filters jsonb NOT NULL DEFAULT '[]'::jsonb + ); + raise notice 'DB created'; END IF; END;