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

25 lines
702 B
MySQL
Raw Normal View History

2023-02-04 23:11:56 +00:00
BEGIN;
CREATE TABLE examples (
2023-02-18 06:41:59 +00:00
-- name type constraints
id BIGSERIAL PRIMARY KEY
2023-02-04 23:11:56 +00:00
);
CREATE TABLE example_texts (
2023-02-18 06:41:59 +00:00
-- 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))
2023-02-04 23:11:56 +00:00
);
CREATE UNIQUE INDEX example_texts_example_language_index
ON example_texts (example_id, language_id, index);
COMMIT;