ordabok/migrations/2023-01-03-134434_create_word/up.sql
Lucien Cartier-Tilet 5c199e2628
Change Serials to UUIDs, fix translation table
Languages now refer to other languages they are translated to through
an additional table rather than an array of identifiers. This ensures
no orphan identifier remains when a language is deleted.

The primary key of languages is now a unique identifier rather than
the name of the language itself. It now allows for multiple languages
to have the same name. Their unique identifier is now a v4 UUID.

Set Diesel to specific version 2.0.2, since 2.0 apparently does not
mean the latest version of 2.0.z and 2.0 has issues with its uuid
feature.

Cleanup and simplify some code.

Some more GraphQL documentation on available queries.
2023-01-08 15:58:26 +01:00

41 lines
1.1 KiB
SQL

-- Your SQL goes here
CREATE TYPE PartOfSpeech as ENUM ('ADJ', 'ADP', 'ADV', 'AUX', 'CCONJ', 'DET', 'INTJ', 'NOUN', 'NUM', 'PART', 'PRON', 'PROPN', 'PUNCT', 'SCONJ', 'SYM', 'VERB', 'X');
CREATE TYPE WordRelationship as ENUM('def', 'related');
CREATE TABLE Words (
norm VARCHAR(255) PRIMARY KEY, -- normalized word
native VARCHAR(255),
lemma VARCHAR(255)
REFERENCES Words(norm)
ON UPDATE CASCADE
ON DELETE SET NULL,
language UUID
REFERENCES Languages(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
partofspeech PartOfSpeech NOT NULL,
audio VARCHAR(511),
video VARCHAR(511),
image VARCHAR(511),
description TEXT, -- Markdown
etymology TEXT, -- Markdown
lusage TEXT, -- Markdown
morphology TEXT -- Markdown
);
CREATE TABLE WordRelation (
id SERIAL PRIMARY KEY,
wordsource VARCHAR(255)
REFERENCES Words(norm)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
wordtarget VARCHAR(255)
REFERENCES Words(norm)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
relationship WordRelationship NOT NULL
);