diff --git a/flyway/postgre/migrations/sql/V1_3_Create_lesson2_tables.sql b/flyway/postgre/migrations/sql/V1_3_Create_lesson2_tables.sql new file mode 100644 index 0000000..89eec27 --- /dev/null +++ b/flyway/postgre/migrations/sql/V1_3_Create_lesson2_tables.sql @@ -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( + role_id uuid DEFAULT gen_random_uuid() PRIMARY KEY, + 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( + 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 ( + 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) +); + + diff --git a/flyway/postgre/migrations/sql/V1_4_Insert_lession2_initial_data.sql b/flyway/postgre/migrations/sql/V1_4_Insert_lession2_initial_data.sql new file mode 100644 index 0000000..268306f --- /dev/null +++ b/flyway/postgre/migrations/sql/V1_4_Insert_lession2_initial_data.sql @@ -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', 'seta-international@gmail.com','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','hai@gmail.com','{}','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; \ No newline at end of file