1
0
Fork 0

feat: add database migrations and dockerfile for migrations

This commit is contained in:
Vojtěch Mareš 2024-10-10 21:29:55 +02:00
parent 0c93db2644
commit aaa1eff0fe
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
3 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,10 @@
# syntax=docker/dockerfile:1
FROM migrate/migrate:v4.17.1 AS migrate
FROM alpine:3.20 AS runtime
COPY --from=migrate /usr/local/bin/migrate /usr/local/bin/migrate
COPY db/migrations/ /srv/migrations/
CMD [ "ash" ]

View file

@ -0,0 +1,5 @@
DROP TABLE IF EXISTS training.prices;
DROP TABLE IF EXISTS training.trainings;
DROP SCHEMA IF EXISTS training;

View file

@ -0,0 +1,25 @@
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;