feat(DB): feature-flags

This commit is contained in:
Taha Yassine Kraiem 2023-06-22 12:33:58 +01:00
parent b98b30725f
commit d76c5ce6e2
2 changed files with 59 additions and 1 deletions

View file

@ -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;

View file

@ -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;