1
0
Fork 0
database/20230204224830_examples.up.sql

25 lines
702 B
PL/PgSQL

BEGIN;
CREATE TABLE examples (
-- name type constraints
id BIGSERIAL PRIMARY KEY
);
CREATE TABLE example_texts (
-- name type constraints
id BIGSERIAL PRIMARY KEY,
example_id BIGINT NOT NULL REFERENCES examples (id),
language_id BIGINT NOT NULL REFERENCES languages (id),
index BIGINT NOT NULL,
value TEXT NOT NULL,
-- CONSTRAINT name CHECK (condition)
CONSTRAINT index_is_not_negative CHECK (index >= 0),
CONSTRAINT value_is_sane_text CHECK (is_sane_text(value))
);
CREATE UNIQUE INDEX example_texts_example_language_index
ON example_texts (example_id, language_id, index);
COMMIT;