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..f1912c0 --- /dev/null +++ b/flyway/postgre/migrations/sql/V1_3__Create_lesson2_tables.sql @@ -0,0 +1,84 @@ +create type type_status as enum ('active','deactived','deleted') + +CREATE EXTENSION IF NOT EXISTS "uuid-ossp" + + +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 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 uuid_generate_v4 (), + 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 uuid_generate_v4 () 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) +) diff --git a/flyway/postgre/migrations/sql/V1_4__Insert_lesson2_initial_data.sql b/flyway/postgre/migrations/sql/V1_4__Insert_lesson2_initial_data.sql new file mode 100644 index 0000000..ed7bb88 --- /dev/null +++ b/flyway/postgre/migrations/sql/V1_4__Insert_lesson2_initial_data.sql @@ -0,0 +1,203 @@ +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 ( + 'Acme Inc.', +'{"industry": "Manufacturing", "employees": 500}', +NOW(), +NOW(), +'123 Main St', +'555-1234', +'info@acme.com', +'USA', +'California', +'Los Angeles', +'90001', +'Acme West', +'https://www.acme.com' +); + +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 ( + 'Globex Corp.', +'{"industry": "Technology", "employees": 1000}', +NOW(), +NOW(), +'456 Oak Ave', +'555-5678', +'info@globex.com', +'USA', +'New York', +'New York City', +'10001', +'Globex East', +'https://www.globex.com' +); + +insert + into + sso_role ( + role_name, + role_description, + organization_id +) +values ( + 'Admin', +'Full access to all features', +2 +); + +insert + into + sso_role ( + role_name, + role_description, + organization_id +) +values ( + 'Manager', +'Access to manage users and roles', +2 +); + +insert + into + sso_role ( + role_name, + role_description, + organization_id +) +values ( + 'User', +'Basic access to view and edit own profile', +2 +); + +insert + into + sso_user ( + user_name, + password, + email, + kvp, + date_created, + date_modified, + modified_by, + last_logged_in, + user_settings, + status +) +values ( + 'john_doe', +'password123', +'john_doe@example.com', +'{"role": "admin"}', +NOW(), +NOW(), +null, +NOW(), +'{"theme": "dark"}', +'active' +); + +insert + into + sso_user ( + user_name, + password, + email, + kvp, + date_created, + date_modified, + modified_by, + last_logged_in, + user_settings, + status +) +values ( + 'jane_doe', +'password456', +'jane_doe@example.com', +'{"role": "user"}', +NOW(), +NOW(), +null, +NOW(), +'{"theme": "light"}', +'active' +); + +insert + into + sso_user_organization ( + organization_id, + user_id +) +values ( + 2, +1 +); + +insert + into + sso_user_organization ( + organization_id, + user_id +) +values ( + 3, +2 +); + +insert + into + sso_user_role ( + user_id, + role_id +) +values (1, +'c5089b76-92e5-42f0-81a3-1317322ad372'), +(1, +'ce40b375-f4de-4df8-9848-721573b39ff2') + +INSERT INTO sso_user_profile ( + user_id, birth_date, sex, title, firstname, lastname, avatar, age, address, date_created +) VALUES ( + 1, '1990-01-01', 'male', 'Mr.', 'John', 'Doe', 'https://example.com/avatar.jpg', 31, '123 Main St, Los Angeles, California, USA', NOW() +); + +INSERT INTO sso_user_profile ( + user_id, birth_date, sex, title, firstname, lastname, avatar, age, address, date_created +) VALUES ( + 2, '1995-05-05', 'female', 'Ms.', 'Jane', 'Doe', 'https://example.com/avatar.jpg', 26, '456 Oak Ave, New York City, New York, USA', NOW() +); \ No newline at end of file