BEGIN;

CREATE SCHEMA IF NOT EXISTS training;

CREATE TABLE IF NOT EXISTS training.trainings (
                                                id          SERIAL PRIMARY KEY,
                                                name        varchar(255) NOT NULL,
                                                days        smallint NOT NULL,
                                                published   boolean NOT NULL DEFAULT FALSE,
                                                retired     boolean NOT NULL DEFAULT FALSE
);

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
);

COMMIT;

