-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: adapt the SQL scripts pattern
Change from SQL Server to PostgreSQL.
- Loading branch information
1 parent
041baca
commit 0d3401a
Showing
2 changed files
with
57 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,56 @@ | ||
/* TABLES */ | ||
|
||
CREATE TABLE user ( | ||
id UNIQUEIDENTIFIER NOT NULL, | ||
username VARCHAR(50) NOT NULL, | ||
email VARCHAR(255) NOT NULL, | ||
[password] CHAR(32) NOT NULL, | ||
password_salt CHAR(16) NOT NULL, | ||
[role] VARCHAR(5) NOT NULL, | ||
created_on DATETIME2 NOT NULL, | ||
updated_on DATETIME2 NULL, | ||
is_disabled BIT NOT NULL | ||
CREATE TABLE "user" ( | ||
id UUID NOT NULL PRIMARY KEY, | ||
username VARCHAR(50) UNIQUE NOT NULL, | ||
email VARCHAR(255) UNIQUE NOT NULL, | ||
"password" CHAR(32) NOT NULL, | ||
password_salt CHAR(24) NOT NULL, | ||
"role" VARCHAR(5) NOT NULL, | ||
created_on TIMESTAMP NOT NULL, | ||
updated_on TIMESTAMP NULL, | ||
is_disabled BOOLEAN NOT NULL | ||
); | ||
|
||
CREATE TABLE country ( | ||
id UNIQUEIDENTIFIER NOT NULL, | ||
[name] VARCHAR(255), | ||
iso_alpha3_code VARCHAR(4) NOT NULL, | ||
created_on DATETIME2 NOT NULL, | ||
updated_on DATETIME2 NULL, | ||
is_disabled BIT NOT NULL | ||
id UUID NOT NULL PRIMARY KEY, | ||
"name" VARCHAR(255) UNIQUE, | ||
iso_alpha3_code VARCHAR(4) UNIQUE NOT NULL, | ||
created_on TIMESTAMP NOT NULL, | ||
updated_on TIMESTAMP NULL, | ||
is_disabled BOOLEAN NOT NULL | ||
); | ||
|
||
CREATE TABLE director ( | ||
id UNIQUEIDENTIFIER NOT NULL, | ||
country_id UNIQUEIDENTIFIER NOT NULL, | ||
[name] VARCHAR(255) NOT NULL, | ||
id UUID NOT NULL PRIMARY KEY, | ||
country_id UUID NOT NULL, | ||
"name" VARCHAR(255) UNIQUE NOT NULL, | ||
date_of_birth DATE NOT NULL, | ||
created_on DATETIME2 NOT NULL, | ||
updated_on DATETIME2 NULL, | ||
is_disabled BIT NOT NULL | ||
created_on TIMESTAMP NOT NULL, | ||
updated_on TIMESTAMP NULL, | ||
is_disabled BOOLEAN NOT NULL, | ||
|
||
CONSTRAINT FK_country_director | ||
FOREIGN KEY (country_id) | ||
REFERENCES country(id) | ||
); | ||
|
||
CREATE TABLE movie ( | ||
id UNIQUEIDENTIFIER NOT NULL, | ||
director_id UNIQUEIDENTIFIER NOT NULL, | ||
country_id UNIQUEIDENTIFIER NOT NULL, | ||
id UUID NOT NULL PRIMARY KEY, | ||
director_id UUID NOT NULL, | ||
country_id UUID NOT NULL, | ||
english_name VARCHAR(255) NOT NULL, | ||
original_name VARCHAR(255) NULL, | ||
release_year CHAR(4) NOT NULL, | ||
runtime_in_minutes SMALLINT NOT NULL, | ||
genres SMALLINT NOT NULL, | ||
created_on DATETIME2 NOT NULL, | ||
updated_on DATETIME2 NULL, | ||
is_disabled BIT NOT NULL | ||
); | ||
|
||
/* PRIMARY KEY CONSTRAINTS */ | ||
|
||
ALTER TABLE user | ||
ADD CONSTRAINT PK_user | ||
PRIMARY KEY (id); | ||
|
||
ALTER TABLE country | ||
ADD CONSTRAINT PK_country | ||
PRIMARY KEY (id); | ||
created_on TIMESTAMP NOT NULL, | ||
updated_on TIMESTAMP NULL, | ||
is_disabled BOOLEAN NOT NULL, | ||
|
||
ALTER TABLE director | ||
ADD CONSTRAINT PK_director | ||
PRIMARY KEY (id); | ||
|
||
ALTER TABLE movie | ||
ADD CONSTRAINT PK_movie | ||
PRIMARY KEY (id); | ||
|
||
/* FOREIGN KEY CONSTRAINTS */ | ||
|
||
ALTER TABLE director | ||
ADD CONSTRAINT FK_country_director | ||
FOREIGN KEY (country_id) | ||
REFERENCES country(id); | ||
|
||
ALTER TABLE movie | ||
ADD CONSTRAINT FK_director_movie | ||
CONSTRAINT FK_director_movie | ||
FOREIGN KEY (director_id) | ||
REFERENCES director(id); | ||
REFERENCES director(id), | ||
|
||
ALTER TABLE movie | ||
ADD CONSTRAINT FK_country_movie | ||
CONSTRAINT FK_country_movie | ||
FOREIGN KEY (country_id) | ||
REFERENCES country(id); | ||
REFERENCES country(id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
/* USER */ | ||
/* USERS */ | ||
|
||
INSERT INTO user (id, username, [password], password_salt, [role], created_on, updated_on, is_disabled) | ||
VALUES ('6a5561cc-df87-487e-9966-2bfa342525d4', 'admin-user', '83a6c7696be667964f0f42ac17f7fe93', 'c0695027b298c139700d002f', 'admin', GETDATE(), NULL, 0); | ||
INSERT INTO "user" (id, username, email, "password", password_salt, "role", created_on, updated_on, is_disabled) | ||
VALUES ('6a5561cc-df87-487e-9966-2bfa342525d4', 'gman', 'gman@blackmesa.com', '83a6c7696be667964f0f42ac17f7fe93', 'c0695027b298c139700d002f', 'admin', NOW(), NULL, false); | ||
|
||
INSERT INTO TABLE user (id, username, [password], password_salt, [role], created_on, updated_on, is_disabled) | ||
VALUES ('15e1b955-c9f8-4cfd-bcc0-223f2814358e', 'common-user', '83a6c7696be667964f0f42ac17f7fe93', 'c0695027b298c139700d002f', 'user', GETDATE(), NULL, 0); | ||
INSERT INTO "user" (id, username, email, "password", password_salt, "role", created_on, updated_on, is_disabled) | ||
VALUES ('15e1b955-c9f8-4cfd-bcc0-223f2814358e', 'gordon-freeman', 'gfreeman@blackmesa.com', '83a6c7696be667964f0f42ac17f7fe93', 'c0695027b298c139700d002f', 'user', NOW(), NULL, false); | ||
|
||
/* COUNTRY */ | ||
/* COUNTRIES */ | ||
|
||
INSERT INTO country (id, [name], iso_alpha3_code, created_on, updated_on, is_disabled) | ||
VALUES ('989adb5a-3434-4239-bfaa-8752dcd18e9b', 'United States of America', 'USA', GETDATE(), NULL, 0); | ||
INSERT INTO country (id, "name", iso_alpha3_code, created_on, updated_on, is_disabled) | ||
VALUES ('989adb5a-3434-4239-bfaa-8752dcd18e9b', 'United States of America', 'USA', NOW(), NULL, false); | ||
|
||
INSERT INTO country (id, [name], iso_alpha3_code, created_on, updated_on, is_disabled) | ||
VALUES ('90aa24a3-8cf4-48eb-8164-60351c748ebe', 'Japan', 'JPN', GETDATE(), NULL, 0); | ||
INSERT INTO country (id, "name", iso_alpha3_code, created_on, updated_on, is_disabled) | ||
VALUES ('90aa24a3-8cf4-48eb-8164-60351c748ebe', 'Japan', 'JPN', NOW(), NULL, false); | ||
|
||
/* DIRECTOR */ | ||
/* DIRECTORS */ | ||
|
||
INSERT INTO director (id, country_id, [name], date_of_birth, created_on, updated_on, is_disabled) | ||
VALUES ('c11bfa47-b6a9-471e-a797-b9189d78d3bd', '989adb5a-3434-4239-bfaa-8752dcd18e9b', 'Francis Ford Coppola', '1939-04-07', GETDATE(), NULL, 0); | ||
INSERT INTO director (id, country_id, "name", date_of_birth, created_on, updated_on, is_disabled) | ||
VALUES ('c11bfa47-b6a9-471e-a797-b9189d78d3bd', '989adb5a-3434-4239-bfaa-8752dcd18e9b', 'Francis Ford Coppola', '1939-04-07', NOW(), NULL, false); | ||
|
||
INSERT INTO director (id, country_id, [name], date_of_birth, created_on, updated_on, is_disabled) | ||
VALUES ('9e456246-54e9-48c0-9334-2c6eea386d6b', '90aa24a3-8cf4-48eb-8164-60351c748ebe', 'Hayao Miyazaki', '1941-01-05', GETDATE(), NULL, 0); | ||
INSERT INTO director (id, country_id, "name", date_of_birth, created_on, updated_on, is_disabled) | ||
VALUES ('9e456246-54e9-48c0-9334-2c6eea386d6b', '90aa24a3-8cf4-48eb-8164-60351c748ebe', 'Hayao Miyazaki', '1941-01-05', NOW(), NULL, false); | ||
|
||
/* MOVIE */ | ||
/* MOVIES */ | ||
|
||
INSERT INTO movie (id, director_id, country_id, english_name, ogirinal_name, release_year, runtime_in_minutes, genres, created_on, updated_on, is_disabled) | ||
VALUES ('0015f5e0-aead-4017-99a3-5d189f184fd8', 'c11bfa47-b6a9-471e-a797-b9189d78d3bd', '989adb5a-3434-4239-bfaa-8752dcd18e9b', 'Apocalypse Now', NULL, '1979', 147, 260, GETDATE(), NULL, 0); | ||
INSERT INTO movie (id, director_id, country_id, english_name, original_name, release_year, runtime_in_minutes, genres, created_on, updated_on, is_disabled) | ||
VALUES ('0015f5e0-aead-4017-99a3-5d189f184fd8', 'c11bfa47-b6a9-471e-a797-b9189d78d3bd', '989adb5a-3434-4239-bfaa-8752dcd18e9b', 'Apocalypse Now', NULL, '1979', 147, 260, NOW(), NULL, false); | ||
|
||
INSERT INTO movie (id, director_id, country_id, english_name, ogirinal_name, release_year, runtime_in_minutes, genres, created_on, updated_on, is_disabled) | ||
VALUES ('2197bc6c-c63f-4b15-97a9-d51facdea2bc', '9e456246-54e9-48c0-9334-2c6eea386d6b', '90aa24a3-8cf4-48eb-8164-60351c748ebe', 'Spirited Away', '千と千尋の神隠し', '2001', 125, 18, GETDATE(), NULL, 0); | ||
INSERT INTO movie (id, director_id, country_id, english_name, original_name, release_year, runtime_in_minutes, genres, created_on, updated_on, is_disabled) | ||
VALUES ('2197bc6c-c63f-4b15-97a9-d51facdea2bc', '9e456246-54e9-48c0-9334-2c6eea386d6b', '90aa24a3-8cf4-48eb-8164-60351c748ebe', 'Spirited Away', '千と千尋の神隠し', '2001', 125, 18, NOW(), NULL, false); |