From 1dbf4b868f886b7ba34db9c40bae3d810b9ddf90 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sat, 11 Feb 2023 09:09:19 +0400 Subject: [PATCH] Add words --- 20230211045705_words.down.sql | 5 +++++ 20230211045705_words.up.sql | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 20230211045705_words.down.sql create mode 100644 20230211045705_words.up.sql diff --git a/20230211045705_words.down.sql b/20230211045705_words.down.sql new file mode 100644 index 0000000..171e69f --- /dev/null +++ b/20230211045705_words.down.sql @@ -0,0 +1,5 @@ +BEGIN; +DROP TABLE word_form_example_texts; +DROP TABLE word_forms; +DROP TABLE words; +COMMIT; diff --git a/20230211045705_words.up.sql b/20230211045705_words.up.sql new file mode 100644 index 0000000..0796111 --- /dev/null +++ b/20230211045705_words.up.sql @@ -0,0 +1,25 @@ +BEGIN; + +CREATE TABLE words ( + id BIGSERIAL PRIMARY KEY, + language_id BIGINT NOT NULL REFERENCES languages (id), + primary_form VARCHAR NOT NULL, + CONSTRAINT primary_form_is_sane_text CHECK (is_sane_text(primary_form)) +); + +CREATE TABLE word_forms ( + id BIGSERIAL PRIMARY KEY, + word_id BIGINT NOT NULL REFERENCES words (id), + value VARCHAR NOT NULL, + CONSTRAINT value_is_sane_text CHECK (is_sane_text(value)) +); + +CREATE TABLE word_form_example_texts ( + id BIGSERIAL PRIMARY KEY, + word_form_id BIGINT NOT NULL REFERENCES word_forms (id), + example_text_id BIGINT NOT NULL REFERENCES example_texts (id) +); + +CREATE UNIQUE INDEX word_forms_word_value_index ON word_forms (word_id, value); + +COMMIT;