feat: add database migrations and dockerfile for migrations
This commit is contained in:
parent
0c93db2644
commit
aaa1eff0fe
3 changed files with 40 additions and 0 deletions
10
build/package/migrations/Dockerfile
Normal file
10
build/package/migrations/Dockerfile
Normal 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" ]
|
||||
5
db/migrations/0001_training.down.sql
Normal file
5
db/migrations/0001_training.down.sql
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
DROP TABLE IF EXISTS training.prices;
|
||||
|
||||
DROP TABLE IF EXISTS training.trainings;
|
||||
|
||||
DROP SCHEMA IF EXISTS training;
|
||||
25
db/migrations/0001_training.up.sql
Normal file
25
db/migrations/0001_training.up.sql
Normal 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;
|
||||
|
||||
Reference in a new issue