Skip to content
Open
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
81 changes: 81 additions & 0 deletions flyway/postgre/migrations/sql/V1_3__Create_lesson2_tables.sql
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(),
Copy link
Owner Author

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

Suggested change
modified_by uuid DEFAULT gen_random_uuid(),
modified_by uuid DEFAULT uuid_generate_v4(),

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 flyway/postgre/migrations/sql/V1_4__Insert_lesson2_initial_data.sql
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()
);