1
0
Fork 0
This repository has been archived on 2025-08-23. 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-backoffice-v3-api/db/migrations/0001_training.up.sql

25 lines
1.3 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,
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;