1
0
Fork 0
This repository has been archived on 2025-09-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mareshq-yggdrasil/migrations/001_trainings.up.sql
Vojtech Mares 2d32c80182
feat!: add slug to training
BREAKING CHANGE: update init migration
2024-06-26 22:24:36 +02:00

57 lines
1.8 KiB
PL/PgSQL

BEGIN;
CREATE SCHEMA IF NOT EXISTS training;
CREATE TABLE IF NOT EXISTS training.trainings (
id SERIAL PRIMARY KEY,
name varchar(255) NOT NULL,
slug varchar(255) NOT NULL,
description text NOT NULL,
days smallint NOT NULL
);
CREATE TABLE IF NOT EXISTS training.prices (
training_id SERIAL 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 SERIAL PRIMARY KEY,
training_id SERIAL 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.attendees (
id SERIAL PRIMARY KEY,
date_id SERIAL 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;