-
Notifications
You must be signed in to change notification settings - Fork 2
Lesson 2 - Ngo Thi Hong Nhung #18
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/ngo_thi_hong_nhung
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
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||||||||||
| CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||||||||||
|
|
||||||||||
| CREATE TYPE org_status_type AS ENUM ('active', 'suspend', 'deleted'); | ||||||||||
|
|
||||||||||
| CREATE TYPE user_status_type AS ENUM ('active', 'deactivated', 'deleted'); | ||||||||||
|
|
||||||||||
| CREATE TYPE gender_type AS ENUM ('male', 'female'); | ||||||||||
|
|
||||||||||
| CREATE TABLE IF NOT EXISTS sso_organization ( | ||||||||||
| org_id int PRIMARY KEY NOT NULL, | ||||||||||
| org_name text NOT NULL, | ||||||||||
| kvp JSON, | ||||||||||
| created_time timestamp DEFAULT now(), | ||||||||||
| updated_time timestamp DEFAULT now(), | ||||||||||
| status org_status_type DEFAULT 'active' NOT NULL, | ||||||||||
| address text, | ||||||||||
| contact_number text, | ||||||||||
| email text, | ||||||||||
| country text, | ||||||||||
| state text, | ||||||||||
| city text, | ||||||||||
| postal_code text, | ||||||||||
| website_url text, | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE IF NOT EXISTS sso_user ( | ||||||||||
| user_id uuid DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL, | ||||||||||
| username text NOT NULL, | ||||||||||
| password text NOT NULL, | ||||||||||
| email text NOT NULL, | ||||||||||
| kvp json, | ||||||||||
| created_time timestamp DEFAULT now(), | ||||||||||
| updated_time timestamp DEFAULT now(), | ||||||||||
| modified_by uuid, | ||||||||||
| last_logged_in timestamp, | ||||||||||
| user_settings json DEFAULT '{}' :: json, | ||||||||||
| status user_status_type DEFAULT 'active' NOT NULL, | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE IF NOT EXISTS sso_user_profile ( | ||||||||||
| profile_id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, | ||||||||||
| user_id uuid NOT NULL REFERENCES sso_user(user_id), | ||||||||||
| birth_date date, | ||||||||||
| sex gender_type, | ||||||||||
| title text, | ||||||||||
| first_name text, | ||||||||||
| last_name text, | ||||||||||
| avatar text, | ||||||||||
| age int, | ||||||||||
| address text, | ||||||||||
| date_created timestamp DEFAULT now(), | ||||||||||
| date_modified timestamp DEFAULT now(), | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE IF NOT EXISTS sso_role ( | ||||||||||
| role_id uuid DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL, | ||||||||||
| role_name text NOT NULL, | ||||||||||
| role_description text, | ||||||||||
| organization_id int 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
|
||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE IF NOT EXISTS sso_organization_user ( | ||||||||||
| organization_id int REFERENCES sso_user(user_id), | ||||||||||
| user_id uuid REFERENCES sso_organization(organization_id), | ||||||||||
|
Comment on lines
+63
to
+64
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
|
||||||||||
| CONSTRAINT sso_organization_user_pk PRIMARY KEY (organization_id, user_id), | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE IF NOT EXISTS sso_user_role ( | ||||||||||
| user_id uuid REFERENCES sso_role(role_id), | ||||||||||
| role_id uuid REFERENCES sso_user(user_id), | ||||||||||
|
Comment on lines
+69
to
+70
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
|
||||||||||
| CONSTRAINT sso_user_role_pk PRIMARY KEY(user_id, role_id), | ||||||||||
| ); | ||||||||||
269 changes: 269 additions & 0 deletions
269
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,269 @@ | ||
| INSERT INTO | ||
| sso_organization ( | ||
| org_id, | ||
| org_name, | ||
| kvp, | ||
| address, | ||
| contact_number, | ||
| email, | ||
| country, | ||
| city, | ||
| postal_code, | ||
| website_url | ||
| ) | ||
| VALUES | ||
| ( | ||
| 1, | ||
| 'org 1', | ||
| '{}', | ||
| '643 Pham Van Dong', | ||
| '0123-456-789', | ||
| '[email protected]', | ||
| 'Vietnam', | ||
| 'Hanoi', | ||
| '10000', | ||
| 'org1.com' | ||
| ), | ||
| ( | ||
| 2, | ||
| 'org 2', | ||
| '{}', | ||
| '643 Pham Van Dong', | ||
| '0123-456-789', | ||
| '[email protected]', | ||
| 'Vietnam', | ||
| 'Hanoi', | ||
| '10000', | ||
| 'org2.com' | ||
| ); | ||
|
|
||
| INSERT INTO | ||
| sso_role (role_name, role_description, org_id) | ||
| VALUES | ||
| ( | ||
| 'admin', | ||
| 'admin', | ||
| 1 | ||
| ), | ||
| ('user', 'user', 1), | ||
| ('super-admin', 'super admin', 1); | ||
|
|
||
| INSERT INTO | ||
| sso_user ( | ||
| username, | ||
| password, | ||
| email, | ||
| kvp, | ||
| modified_by, | ||
| last_logged_in, | ||
| user_settings, | ||
| ) | ||
| VALUES | ||
| ( | ||
| 'admin', | ||
| 'admin_password', | ||
| '[email protected]', | ||
| '{}', | ||
| NULL, | ||
| NULL, | ||
| '{}', | ||
| ), | ||
| ( | ||
| 'super_admin', | ||
| 'user_password', | ||
| '[email protected]', | ||
| '{}', | ||
| NULL, | ||
| NULL, | ||
| '{}', | ||
| ), | ||
| ( | ||
| 'user', | ||
| 'user_password', | ||
| '[email protected]', | ||
| '{}', | ||
| NULL, | ||
| NULL, | ||
| '{}', | ||
| ); | ||
|
|
||
| INSERT INTO | ||
| sso_user_profile ( | ||
| user_id, | ||
| birth_date, | ||
| sex, | ||
| title, | ||
| first_name, | ||
| last_name, | ||
| avatar, | ||
| age, | ||
| address | ||
| ) | ||
| VALUES | ||
| ( | ||
| ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'admin' | ||
| ), | ||
| '1995-01-01', | ||
| 'male', | ||
| 'Mr.', | ||
| 'Admin', | ||
| 'User', | ||
| 'url', | ||
| 33, | ||
| '87 PD' | ||
| ), | ||
| ( | ||
| ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'super_admin' | ||
| ), | ||
| '1995-01-01', | ||
| 'female', | ||
| 'Ms.', | ||
| 'User', | ||
| 'User', | ||
| 'url', | ||
| 38, | ||
| '87 PD' | ||
| ), | ||
| ( | ||
| ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'user' | ||
| ), | ||
| '1995-01-01', | ||
| 'male', | ||
| 'Mr.', | ||
| 'User', | ||
| 'User', | ||
| 'url', | ||
| 31, | ||
| '87 PD' | ||
| ); | ||
|
|
||
| INSERT INTO | ||
| sso_organization_user (org_id, user_id) | ||
| VALUES | ||
| ( | ||
| ( | ||
| SELECT | ||
| org_id | ||
| FROM | ||
| sso_organization | ||
| LIMIT | ||
| 1 | ||
| ), ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'admin' | ||
| ) | ||
| ), | ||
| ( | ||
| ( | ||
| SELECT | ||
| org_id | ||
| FROM | ||
| sso_organization | ||
| LIMIT | ||
| 1 | ||
| ), ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'super_admin' | ||
| ) | ||
| ), | ||
| ( | ||
| ( | ||
| SELECT | ||
| org_id | ||
| FROM | ||
| sso_organization OFFSET 1 | ||
| LIMIT | ||
| 1 | ||
| ), ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'user' | ||
| ) | ||
| ); | ||
|
|
||
| INSERT INTO | ||
| sso_user_role (user_id, role_id) | ||
| VALUES | ||
| ( | ||
| ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'admin' | ||
| ), | ||
| ( | ||
| SELECT | ||
| role_id | ||
| FROM | ||
| sso_role | ||
| WHERE | ||
| role_name = 'admin' | ||
| ) | ||
| ), | ||
| ( | ||
| ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'super_admin' | ||
| ), | ||
| ( | ||
| SELECT | ||
| role_id | ||
| FROM | ||
| sso_role | ||
| WHERE | ||
| role_name = 'user' | ||
| ) | ||
| ), | ||
| ( | ||
| ( | ||
| SELECT | ||
| user_id | ||
| FROM | ||
| sso_user | ||
| WHERE | ||
| username = 'user' | ||
| ), | ||
| ( | ||
| SELECT | ||
| role_id | ||
| FROM | ||
| sso_role | ||
| WHERE | ||
| role_name = 'super-admin' | ||
| ) | ||
| ); |
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.