diff --git a/20230218081558_do_not_require_language_names.down.sql b/20230218081558_do_not_require_language_names.down.sql new file mode 100644 index 0000000..4e0e925 --- /dev/null +++ b/20230218081558_do_not_require_language_names.down.sql @@ -0,0 +1,4 @@ +BEGIN; +ALTER TABLE languages ALTER COLUMN english_name SET NOT NULL; +ALTER TABLE languages ALTER COLUMN self_name SET NOT NULL; +COMMIT; diff --git a/20230218081558_do_not_require_language_names.up.sql b/20230218081558_do_not_require_language_names.up.sql new file mode 100644 index 0000000..2d60930 --- /dev/null +++ b/20230218081558_do_not_require_language_names.up.sql @@ -0,0 +1,4 @@ +BEGIN; +ALTER TABLE languages ALTER COLUMN english_name DROP NOT NULL; +ALTER TABLE languages ALTER COLUMN self_name DROP NOT NULL; +COMMIT; diff --git a/20230218083503_translate.down.sql b/20230218083503_translate.down.sql new file mode 100644 index 0000000..a8494f3 --- /dev/null +++ b/20230218083503_translate.down.sql @@ -0,0 +1,15 @@ +BEGIN; + +DROP TABLE language_names; + +ALTER TABLE languages ADD COLUMN english_name VARCHAR; +ALTER TABLE languages ADD COLUMN self_name VARCHAR; + +ALTER TABLE languages ADD CONSTRAINT english_name_is_sane_text + CHECK (english_name IS NULL OR is_sane_text(english_name)); +ALTER TABLE languages ADD CONSTRAINT self_name_is_sane_text + CHECK (self_name IS NULL OR is_sane_text(self_name)); + +CREATE UNIQUE INDEX languages_english_name ON languages (english_name); + +COMMIT; diff --git a/20230218083503_translate.up.sql b/20230218083503_translate.up.sql new file mode 100644 index 0000000..795b625 --- /dev/null +++ b/20230218083503_translate.up.sql @@ -0,0 +1,20 @@ +BEGIN; + +ALTER TABLE languages DROP COLUMN english_name; +ALTER TABLE languages DROP COLUMN self_name; + +CREATE TABLE language_names ( +-- name type constraints + id BIGSERIAL PRIMARY KEY, + lang_id BIGINT NOT NULL REFERENCES languages (id), + name_lang_id BIGINT NOT NULL REFERENCES languages (id), + value VARCHAR NOT NULL, + +-- CONSTRAINT name CHECK (condition) + CONSTRAINT value_is_sane_text CHECK (is_sane_text(value)) +); + +CREATE UNIQUE INDEX languages_lang_name_lang + ON language_names (lang_id, name_lang_id); + +COMMIT;