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
84 changes: 84 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,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 eGender 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,
gender eGender,
title text,
firstname text not null,
lastname text not null,
avatar text,
age int,
address text,
date_created timestamp,
date_modified timestamp,
constraint fk_user_profiles foreign key (user_id) references sso_user(user_id)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 ('Seta International Inc.', '{"industry": "Outsourcing", "employees": 200}', NOW(), NOW(), '1234 something St', '111-1234', '[email protected]', 'USA', 'California', 'Los Angeles', '90001', 'something', 'https://www.setainternational.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 ('Blueoc Corp.', '{"industry": "Technology", "employees": 1000}', NOW(), NOW(), '111 some thing', '1111-111111', '[email protected]', 'Canada', 'Toronto', 'Toronto City', '66777', 'some where','https://www.blueocvn.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 ('useradmin001', 'password123', '[email protected]', '{"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', '[email protected]', '{"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, gender, title, firstname, lastname, avatar, age, address, date_created)
VALUES (1, '2000-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, gender, title, firstname, lastname, avatar, age, address, date_created)
VALUES (2, '2000-05-05', 'female', 'Ms.', 'Jane', 'Doe', 'https://example.com/avatar.jpg', 26, '456 Oak Ave, New York City, New York, USA', NOW());