Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sql scripts sync for 282 #5763

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/sql/282_user_group.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DROP INDEX IF EXISTS idx_unique_user_group_user_id;
DROP TABLE IF EXISTS "public"."user_group_mapping";
DROP INDEX IF EXISTS idx_unique_user_group_name;
DROP INDEX IF EXISTS idx_unique_user_group_identifier;
DROP TABLE IF EXISTS "public"."user_group";
DROP SEQUENCE IF EXISTS "public"."id_seq_user_group_mapping";
DROP SEQUENCE IF EXISTS "public"."id_seq_user_group";
ALTER TABLE user_auto_assigned_groups RENAME TO user_groups;
42 changes: 42 additions & 0 deletions scripts/sql/282_user_group.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
CREATE SEQUENCE IF NOT EXISTS id_seq_user_group;
CREATE TABLE IF NOT EXISTS public.user_group
(
"id" int NOT NULL DEFAULT nextval('id_seq_user_group'::regclass),
"name" VARCHAR(50) NOT NULL,
"identifier" VARCHAR(50) NOT NULL,
"description" TEXT NOT NULL,
"active" bool NOT NULL,
"created_on" timestamptz NOT NULL,
"created_by" int4 NOT NULL,
"updated_on" timestamptz NOT NULL,
"updated_by" int4 NOT NULL,
PRIMARY KEY ("id")
);

CREATE UNIQUE INDEX idx_unique_user_group_name
ON user_group (name)
WHERE active = true;

CREATE UNIQUE INDEX idx_unique_user_group_identifier
ON user_group (identifier)
WHERE active = true;

CREATE SEQUENCE IF NOT EXISTS id_seq_user_group_mapping;
CREATE TABLE IF NOT EXISTS public.user_group_mapping
(
"id" int NOT NULL DEFAULT nextval('id_seq_user_group_mapping'::regclass),
"user_id" int NOT NULL,
"user_group_id" int NOT NULL,
"created_on" timestamptz NOT NULL,
"created_by" int4 NOT NULL,
"updated_on" timestamptz NOT NULL,
"updated_by" int4 NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "user_group_mapping_user_group_id_fkey" FOREIGN KEY ("user_group_id") REFERENCES "public"."user_group" ("id"),
CONSTRAINT "user_group_mapping_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id")
);

CREATE UNIQUE INDEX idx_unique_user_group_user_id
ON user_group_mapping(user_id,user_group_id);

ALTER TABLE user_groups RENAME TO user_auto_assigned_groups;