-
Notifications
You must be signed in to change notification settings - Fork 2
Lesson 2 - Tran Trong Duc #16
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/tran_trong_duc
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
81 changes: 81 additions & 0 deletions
81
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,81 @@ | ||
| create type type_status as enum ('active','deactived','deleted'); | ||
|
|
||
| create table if not exists sso_user ( | ||
| user_id int generated always as identity not null, | ||
| user_name text not null, | ||
| password text not null, | ||
| email text, | ||
| kvp json, | ||
| date_created timestamp, | ||
| date_modified timestamp, | ||
| modified_by uuid DEFAULT gen_random_uuid(), | ||
| last_logged_in timestamp, | ||
| user_settings json default '{}'::json, | ||
| status type_status default 'active', | ||
| primary key (user_id) | ||
| ); | ||
|
|
||
| create table if not exists sso_organization ( | ||
| organization_id int generated always as identity not null, | ||
| organization_name text not null, | ||
| kvp json, | ||
| date_created timestamp, | ||
| date_modified timestamp, | ||
| status type_status default 'active' not null, | ||
| address text, | ||
| contact_number text, | ||
| email text, | ||
| country text, | ||
| state text, | ||
| city text, | ||
| postal_code text, | ||
| organization_sub_name text, | ||
| website_url text, | ||
| primary key (organization_id) | ||
| ); | ||
|
|
||
| create table if not exists sso_role ( | ||
| role_id uuid DEFAULT gen_random_uuid(), | ||
| role_name text not null, | ||
| role_description text, | ||
| organization_id int, | ||
| primary key (role_id) | ||
| ); | ||
|
|
||
| alter table sso_role | ||
| add constraint fk_organization | ||
| foreign key (organization_id) | ||
| references sso_organization(organization_id); | ||
|
|
||
| create table if not exists sso_user_organization ( | ||
| organization_id int not null, | ||
| user_id int not null, | ||
| constraint user_org primary key (organization_id,user_id), | ||
| constraint fk_user foreign key (user_id) references sso_user(user_id), | ||
| constraint fk_org foreign key (organization_id) references sso_organization(organization_id) | ||
| ); | ||
|
|
||
| create table if not exists sso_user_role ( | ||
| user_id int not null, | ||
| role_id uuid not null, | ||
| constraint user_role primary key (user_id, role_id), | ||
| constraint fk_user foreign key (user_id) references sso_user(user_id), | ||
| constraint fk_role foreign key (role_id) references sso_role(role_id) | ||
| ); | ||
|
|
||
| create type type_sex as enum ('male','female'); | ||
|
|
||
| create table if not exists sso_user_profile ( | ||
| profile_id uuid default gen_random_uuid() not null, | ||
| user_id int not null, | ||
| birth_date date, | ||
| sex type_sex, | ||
| title text, | ||
| firstname text not null, | ||
| lastname text not null, | ||
| avatar text, | ||
| age int, | ||
| address text, | ||
| date_created timestamp, | ||
| constraint fk_user_profiles foreign key (user_id) references sso_user(user_id) | ||
| ); | ||
103 changes: 103 additions & 0 deletions
103
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,103 @@ | ||
| -- Insert data into sso_organization table | ||
| INSERT INTO sso_organization ( | ||
| organization_name, | ||
| kvp, | ||
| date_created, | ||
| date_modified, | ||
| address, | ||
| contact_number, | ||
| email, | ||
| country, | ||
| state, | ||
| city, | ||
| postal_code, | ||
| organization_sub_name, | ||
| website_url | ||
| ) | ||
| VALUES ( | ||
| 'Tech Innovators Inc.', | ||
| '{"industry": "Technology", "employees": 1200}', | ||
| NOW(), | ||
| NOW(), | ||
| '567 Tech Ave', | ||
| '555-4321', | ||
| 'mailto:[email protected]', | ||
| 'USA', | ||
| 'California', | ||
| 'San Francisco', | ||
| '94101', | ||
| 'Tech Innovators West', | ||
| 'https://www.techinnovators.com' | ||
| ); | ||
|
|
||
| -- Insert data into sso_role table | ||
| INSERT INTO sso_role ( | ||
| role_name, | ||
| role_description, | ||
| organization_id | ||
| ) | ||
| VALUES ( | ||
| 'Administrator', | ||
| 'Full access to all features', | ||
| 2 | ||
| ); | ||
|
|
||
| -- Insert data into sso_user table | ||
| INSERT INTO sso_user ( | ||
| user_name, | ||
| password, | ||
| email, | ||
| kvp, | ||
| date_created, | ||
| date_modified, | ||
| modified_by, | ||
| last_logged_in, | ||
| user_settings, | ||
| status | ||
| ) | ||
| VALUES ( | ||
| 'mark_johnson', | ||
| 'p@ssw0rd456', | ||
| 'mailto:[email protected]', | ||
| '{"role": "admin"}', | ||
| NOW(), | ||
| NOW(), | ||
| null, | ||
| NOW(), | ||
| '{"theme": "light"}', | ||
| 'active' | ||
| ); | ||
|
|
||
| -- Insert data into sso_user_organization table | ||
| INSERT INTO sso_user_organization (organization_id, user_id) | ||
| VALUES (2, 1); | ||
|
|
||
| -- Insert data into sso_user_role table | ||
| INSERT INTO sso_user_role (user_id, role_id) | ||
| VALUES (1, 'ce40b375-f4de-4df8-9848-721573b39ff2'); | ||
|
|
||
| -- Insert data into sso_user_profile table for Mark Johnson | ||
| INSERT INTO sso_user_profile ( | ||
| user_id, | ||
| birth_date, | ||
| sex, | ||
| title, | ||
| firstname, | ||
| lastname, | ||
| avatar, | ||
| age, | ||
| address, | ||
| date_created | ||
| ) | ||
| VALUES ( | ||
| 1, | ||
| '1985-07-15', | ||
| 'male', | ||
| 'Mr.', | ||
| 'Mark', | ||
| 'Johnson', | ||
| 'https://example.com/mark_avatar.jpg', | ||
| 38, | ||
| '567 Tech Ave, San Francisco, California, USA', | ||
| NOW() | ||
| ); |
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.
Nếu dùng kiểu dữ liệu UUID cần cài extension
uuid-ossp