-
Notifications
You must be signed in to change notification settings - Fork 2
Lesson 2 - Chu Dang Hieu #20
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
Open
ndthang15
wants to merge
1
commit into
lesson2/main
Choose a base branch
from
lesson2/chu_dang_hieu
base: lesson2/main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
flyway/postgre/migrations/sql/V1_3__Create_lesson2_tables.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||
| CREATE TYPE enum AS ENUM ('active', 'suspend', 'deleted'); | ||||||
| CREATE TYPE enum_org AS ENUM ('active', 'deactivated', 'deleted'); | ||||||
| CREATE TYPE enum_sex AS ENUM ('male', 'female'); | ||||||
| CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||||||
|
|
||||||
| CREATE TABLE public.sso_organization ( | ||||||
| organization_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE), | ||||||
| organization_name text NOT NULL, | ||||||
| date_created timestamp NULL, | ||||||
| date_modified timestamp NULL, | ||||||
| address text NULL, | ||||||
| contact_number text NULL, | ||||||
| email text NULL, | ||||||
| country text NULL, | ||||||
| state text NULL, | ||||||
| city text NULL, | ||||||
| postal_code text NULL, | ||||||
| organization_sub_name text NULL, | ||||||
| website_url text NULL, | ||||||
| kvp json NULL, | ||||||
| status public."enum_org" NOT NULL DEFAULT 'active'::enum_org, | ||||||
| CONSTRAINT sso_organization_pk PRIMARY KEY (organization_id) | ||||||
| ); | ||||||
|
|
||||||
| CREATE TABLE public.sso_organization_user ( | ||||||
| user_id int4 NULL, | ||||||
| organization_id int4 NULL | ||||||
| ); | ||||||
|
|
||||||
| -- public.sso_organization_user foreign keys | ||||||
| ALTER TABLE public.sso_organization_user ADD CONSTRAINT sso_org_user_fk FOREIGN KEY (user_id) REFERENCES public.sso_user(user_id); | ||||||
| ALTER TABLE public.sso_organization_user ADD CONSTRAINT sso_org_user_fk_1 FOREIGN KEY (organization_id) REFERENCES public.sso_organization(organization_id); | ||||||
|
|
||||||
| CREATE TABLE public.sso_role ( | ||||||
| role_id uuid NOT NULL, | ||||||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| role_name text NOT NULL, | ||||||
| role_description text NULL, | ||||||
| organization_id int4 NULL, | ||||||
| CONSTRAINT sso_role_pk PRIMARY KEY (role_id) | ||||||
| ); | ||||||
|
|
||||||
| -- public.sso_role foreign keys | ||||||
| ALTER TABLE public.sso_role ADD CONSTRAINT sso_role_fk FOREIGN KEY (organization_id) REFERENCES public.sso_organization(organization_id); | ||||||
|
|
||||||
| CREATE TABLE public.sso_role_user ( | ||||||
| user_id int4 NULL, | ||||||
| role_id uuid NULL | ||||||
|
Comment on lines
+46
to
+47
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tương tự bảng sso_organization_user |
||||||
| ); | ||||||
|
|
||||||
| -- public.sso_role_user foreign keys | ||||||
| ALTER TABLE public.sso_role_user ADD CONSTRAINT sso_role_user_fk FOREIGN KEY (user_id) REFERENCES public.sso_user(user_id); | ||||||
| ALTER TABLE public.sso_role_user ADD CONSTRAINT sso_role_user_fk_1 FOREIGN KEY (role_id) REFERENCES public.sso_role(role_id); | ||||||
|
|
||||||
| CREATE TABLE public.sso_user ( | ||||||
| user_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE), | ||||||
| user_name text NOT NULL, | ||||||
| "password" text NOT NULL, | ||||||
| email text NULL, | ||||||
| kvp json NULL, | ||||||
| date_created timestamp NULL, | ||||||
| date_modified timestamp NULL, | ||||||
| modified_by uuid NULL, | ||||||
| last_logged_in timestamp NULL, | ||||||
| user_settings json NULL DEFAULT '{}'::json, | ||||||
| status public."enum" NULL DEFAULT 'active'::enum, | ||||||
| CONSTRAINT sso_user_pk PRIMARY KEY (user_id) | ||||||
| ); | ||||||
|
|
||||||
| CREATE TABLE public.sso_user_profile ( | ||||||
| profile_id uuid NOT NULL, | ||||||
| birth_date date NULL, | ||||||
| title text NULL, | ||||||
| firstname text NOT NULL, | ||||||
| lastname text NOT NULL, | ||||||
| avatar text NULL, | ||||||
| age int4 NULL, | ||||||
| address text NULL, | ||||||
| date_created timestamp NULL, | ||||||
| sex public."enum_sex" NULL, | ||||||
| user_id int4 NULL, | ||||||
| CONSTRAINT sso_user_profile_pk PRIMARY KEY (profile_id) | ||||||
| ); | ||||||
|
|
||||||
| -- public.sso_user_profile foreign keys | ||||||
| ALTER TABLE public.sso_user_profile ADD CONSTRAINT sso_user_profile_fk FOREIGN KEY (user_id) REFERENCES public.sso_user(user_id); | ||||||
36 changes: 36 additions & 0 deletions
36
flyway/postgre/migrations/sql/V1_4__Insert_lesson2_initial_data.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| INSERT INTO sso_organization ( organization_name, kvp, status, address, contact_number, email, country, state, city, postal_code, website_url) | ||
| VALUES | ||
| ('org id 1', '{"key": "value"}', 'active', '123 Street', '012345678', '[email protected]', 'Vietnam', 'Hanoi', 'Hanoi', '100000', 'http://test.com'), | ||
| ('org id 2', '{"key": "value"}', 'suspended', '456 Street', '0123456789', '[email protected]', 'America', 'Los Angeles', 'Los AngelesCity', '700000', 'http://test1.com'); | ||
|
|
||
| INSERT INTO sso_role (role_id, role_name, role_description, organization_id) | ||
| VALUES | ||
| (uuid_generate_v4(), 'Admin', 'admin', (SELECT organization_id FROM sso_organization LIMIT 1)), | ||
| (uuid_generate_v4(), 'User', 'user', (SELECT organization_id FROM sso_organization LIMIT 1)), | ||
| (uuid_generate_v4(), 'Manage', 'manage', (SELECT organization_id FROM sso_organization OFFSET 1 LIMIT 1)); | ||
|
|
||
| INSERT INTO sso_user ( user_name, password, email, kvp, modified_by, last_logged_in, user_settings, status) | ||
| VALUES | ||
| ( 'Bob', 'admin_password', '[email protected]', '{"key": "value"}', NULL, NULL, '{}', 'active'), | ||
| ( 'Minh', 'user_password', '[email protected]', '{"key": "value"}', NULL, NULL, '{}', 'active'), | ||
| ( 'David', 'user_password', '[email protected]', '{"key": "value"}', NULL, NULL, '{}', 'active'); | ||
|
|
||
| INSERT INTO sso_user_profile (profile_id, user_id, birth_date, sex, title, firstname, lastname, avatar, age, address) | ||
| VALUES | ||
| (uuid_generate_v4(), (SELECT user_id FROM sso_user WHERE user_id = 1), '1997-01-13', 'male', 'Mr.', 'Admin', 'User', 'avatar_url1', 33, '123 Test St'), | ||
| (uuid_generate_v4(), (SELECT user_id FROM sso_user WHERE user_id = 2), '1992-06-24', 'male', 'Mr.', 'User', 'One', 'avatar_url2', 38, '456 Test St'), | ||
| (uuid_generate_v4(), (SELECT user_id FROM sso_user WHERE user_id = 3), '1995-08-21', 'male', 'Mr.', 'User', 'Two', 'avatar_url3', 31, '789 Test St'); | ||
|
|
||
|
|
||
| INSERT INTO sso_organization_user (organization_id, user_id) | ||
| VALUES | ||
| ((SELECT organization_id FROM sso_organization LIMIT 1), (SELECT user_id FROM sso_user WHERE user_id = 1)), | ||
| ((SELECT organization_id FROM sso_organization LIMIT 1), (SELECT user_id FROM sso_user WHERE user_id = 2)), | ||
| ((SELECT organization_id FROM sso_organization OFFSET 1 LIMIT 1), (SELECT user_id FROM sso_user WHERE user_id = 3)); | ||
|
|
||
| INSERT INTO sso_role_user (user_id, role_id) | ||
| VALUES | ||
| ((SELECT user_id FROM sso_user WHERE user_id = 1), (SELECT role_id FROM sso_role WHERE role_id = '20c8f6a7-d1db-4c82-8101-afdd44765da8')), | ||
| ((SELECT user_id FROM sso_user WHERE user_id = 2), (SELECT role_id FROM sso_role WHERE role_id = '771a6dee-2d88-47ca-a928-599bae9b09b5')), | ||
| ((SELECT user_id FROM sso_user WHERE user_id = 3), (SELECT role_id FROM sso_role WHERE role_id = '75076631-15cb-4bf9-b01c-09d587f8c060')); | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.