-
Notifications
You must be signed in to change notification settings - Fork 2
Lesson 2 - Nguyen Minh Hai #14
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||||
| -- Database: admindb | ||||||||
|
|
||||||||
| -- DROP DATABASE IF EXISTS admindb; | ||||||||
|
|
||||||||
| CREATE TYPE sex AS ENUM ('female', 'male'); | ||||||||
| CREATE TYPE status AS ENUM ('active', 'deactived', 'deleted'); | ||||||||
|
|
||||||||
| DROP TABLE IF EXISTS sso_organization; | ||||||||
| CREATE TABLE sso_organization ( | ||||||||
| organization_id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | ||||||||
| organization_name TEXT, | ||||||||
| kvp json, | ||||||||
| date_created TIMESTAMP, | ||||||||
| date_modified TIMESTAMP, | ||||||||
| status status DEFAULT 'active' NOT NULL, | ||||||||
| address TEXT, | ||||||||
| contact_number TEXT, | ||||||||
| email TEXT, | ||||||||
| country TEXT, | ||||||||
| city TEXT, | ||||||||
| postal_code TEXT, | ||||||||
| organization_sub_name TEXT, | ||||||||
| website_url TEXT | ||||||||
| ); | ||||||||
|
|
||||||||
| DROP TABLE IF EXISTS sso_role; | ||||||||
| CREATE TABLE sso_role( | ||||||||
|
Comment on lines
+26
to
+27
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_id uuid DEFAULT gen_random_uuid() PRIMARY KEY, | ||||||||
|
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. Nếu dùng UUID muốn gen random uuid cần cài thêm extension
Suggested change
|
||||||||
| role_name TEXT, | ||||||||
| rele_description TEXT, | ||||||||
| organization_id INT NOT NULL, | ||||||||
| CONSTRAINT fk_organization FOREIGN KEY(organization_id) REFERENCES sso_organization(organization_id) | ||||||||
|
|
||||||||
| ); | ||||||||
| DROP TABLE IF EXISTS sso_user; | ||||||||
| CREATE TABLE sso_user( | ||||||||
|
Comment on lines
+35
to
+36
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
|
||||||||
| user_id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | ||||||||
| password TEXT, | ||||||||
| email TEXT, | ||||||||
| kvp json, | ||||||||
| date_created TIMESTAMP, | ||||||||
| date_modified TIMESTAMP, | ||||||||
| modified_by uuid, | ||||||||
| last_logged_in TIMESTAMP, | ||||||||
| user_settings jsonb DEFAULT '{}'::jsonb, | ||||||||
| status status DEFAULT 'active' | ||||||||
|
|
||||||||
| ); | ||||||||
|
|
||||||||
| DROP TABLE IF EXISTS sso_user_profile; | ||||||||
| CREATE TABLE sso_user_profile ( | ||||||||
|
Comment on lines
+50
to
+51
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
|
||||||||
| profile_id uuid DEFAULT gen_random_uuid() PRIMARY KEY, | ||||||||
| user_id INT, | ||||||||
| birth_date DATE, | ||||||||
| sex sex, | ||||||||
| title TEXT, | ||||||||
| fristname TEXT NOT NULL, | ||||||||
| lastname TEXT NOT NULL, | ||||||||
| avatar TEXT, | ||||||||
| age INT, | ||||||||
| address TEXT, | ||||||||
| date_created TIMESTAMP, | ||||||||
| CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES sso_user(user_id) | ||||||||
| ); | ||||||||
|
|
||||||||
|
|
||||||||
|
|
||||||||
| DROP TABLE IF EXISTS sso_organization_user; | ||||||||
| CREATE TABLE sso_organization_user( | ||||||||
| organization_id INT, | ||||||||
| user_id INT, | ||||||||
| PRIMARY KEY (organization_id, user_id), | ||||||||
| CONSTRAINT fk_organization_id FOREIGN KEY(organization_id) REFERENCES sso_organization(organization_id), | ||||||||
| CONSTRAINT fk_user_id FOREIGN KEY(user_id) REFERENCES sso_user(user_id) | ||||||||
| ); | ||||||||
| DROP TABLE IF EXISTS sso_user_role; | ||||||||
| CREATE TABLE sso_user_role( | ||||||||
| user_id INT, | ||||||||
| role_id uuid, | ||||||||
| PRIMARY KEY (user_id, role_id), | ||||||||
| CONSTRAINT fk_role_id FOREIGN KEY(role_id) REFERENCES sso_role(role_id), | ||||||||
| CONSTRAINT fk_user_id FOREIGN KEY(user_id) REFERENCES sso_user(user_id) | ||||||||
| ); | ||||||||
|
|
||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| INSERT INTO sso_organization(organization_name,kvp,date_created,status,address,contact_number,email,country,city,postal_code,organization_sub_name,website_url) | ||
| VALUES ('seta','{}','2023-10-10 11:30:30','active','Duy Tân, Cầu Giấy, VN','0123456789', '[email protected]','Việt Nam','Hà Nội','000084','seta','https://seta-international.com'); | ||
| INSERT INTO sso_role(role_name,rele_description, organization_id) | ||
| VALUES ('member','member',1); | ||
| INSERT INTO sso_user(password,email,kvp,date_created, status) | ||
| VALUES('password','[email protected]','{}','2023-10-10 11:30:00', 'active'); | ||
| INSERT INTO sso_user_profile (user_id,birth_date,sex,title, fristname, lastname, avatar,age,address, date_created) | ||
| VALUES(1,'1-3-2000','male','Hai','Hai','Nguyen','hai_nguyen',23,'Ha Noi','2023-10-10 11:30:00'); | ||
| INSERT INTO sso_organization_user(organization_id,user_id) | ||
| SELECT organization_id, user_id | ||
| FROM sso_organization | ||
| CROSS JOIN sso_user; | ||
| INSERT INTO sso_user_role(user_id, role_id) | ||
| SELECT user_id, role_id | ||
| FROM sso_user | ||
| CROSS JOIN sso_role; |
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.
Không nên xóa bảng vì có thể gây mất dữ liệu. Chỉ cần câu lệnh CREATE TABLE IF NOT EXISTS thì sẽ không bị lỗi khi bảng đã tồn tại.