feat: add postgres repository for training
This commit is contained in:
parent
8c277ef692
commit
ff7e320481
19 changed files with 1277 additions and 414 deletions
9
migrations/001_trainings.down.sql
Normal file
9
migrations/001_trainings.down.sql
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
DROP TABLE IF EXISTS training.date_attendees;
|
||||
|
||||
DROP TABLE IF EXISTS training.dates;
|
||||
|
||||
DROP TABLE IF EXISTS training.prices;
|
||||
|
||||
DROP TABLE IF EXISTS training.trainings;
|
||||
|
||||
DROP SCHEMA IF EXISTS training;
|
||||
56
migrations/001_trainings.up.sql
Normal file
56
migrations/001_trainings.up.sql
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
BEGIN;
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS training;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS training.trainings (
|
||||
id UUID PRIMARY KEY,
|
||||
name varchar(255) NOT NULL,
|
||||
description text NOT NULL,
|
||||
days smallint NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS training.prices (
|
||||
training_id UUID REFERENCES training.trainings(id),
|
||||
amount NUMERIC(10,4) NOT NULL,
|
||||
currency VARCHAR(3) NOT NULL,
|
||||
CONSTRAINT positive_amount CHECK (amount >= 0),
|
||||
CONSTRAINT allowed_currencies CHECK (currency IN ('USD', 'EUR', 'CZK')),
|
||||
type VARCHAR(10) NOT NULL,
|
||||
CHECK (type IN ('OPEN', 'CORPORATE')),
|
||||
PRIMARY KEY (training_id, currency, type) -- composite primary key
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS training.dates (
|
||||
ID UUID PRIMARY KEY,
|
||||
training_id UUID REFERENCES training.trainings(id),
|
||||
date DATE NOT NULL,
|
||||
start_time TIME NOT NULL,
|
||||
days SMALLINT NOT NULL,
|
||||
is_online BOOLEAN NOT NULL,
|
||||
location VARCHAR(255) NOT NULL,
|
||||
address VARCHAR(500) NOT NULL,
|
||||
capacity SMALLINT NOT NULL,
|
||||
price_amount NUMERIC(10,4) NOT NULL,
|
||||
price_currency VARCHAR(3) NOT NULL,
|
||||
CONSTRAINT positive_amount CHECK (price_amount >= 0),
|
||||
CONSTRAINT allowed_currencies CHECK (price_currency IN ('USD', 'EUR', 'CZK'))
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS training.date_attendees (
|
||||
id UUID PRIMARY KEY,
|
||||
date_id UUID REFERENCES training.dates(id),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
phone VARCHAR(20) NOT NULL,
|
||||
company VARCHAR(255) NOT NULL,
|
||||
position VARCHAR(255) NOT NULL,
|
||||
is_student BOOLEAN NOT NULL,
|
||||
has_paid BOOLEAN NOT NULL,
|
||||
has_attended BOOLEAN NOT NULL,
|
||||
bill_amount NUMERIC(10,4) NOT NULL,
|
||||
bill_currency VARCHAR(3) NOT NULL,
|
||||
CONSTRAINT positive_amount CHECK (bill_amount >= 0),
|
||||
CONSTRAINT allowed_currencies CHECK (bill_currency IN ('USD', 'EUR', 'CZK'))
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
Reference in a new issue