ordabok/migrations/2023-01-03-134426_create_language/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

54 lines
1.3 KiB
SQL

-- Your SQL goes here
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE Release as ENUM ('PUBLIC', 'NONCOMMERCIAL', 'RESEARCH', 'PRIVATE');
CREATE TYPE DictGenre as ENUM ('gen', 'lrn', 'ety', 'spe', 'his', 'ort', 'trm');
CREATE TYPE AgentLanguageRelation as ENUM ('publisher', 'author');
CREATE TABLE Languages (
id UUID DEFAULT uuid_generate_v4 () PRIMARY KEY,
name VARCHAR(255) NOT NULL,
native VARCHAR(255),
release Release NOT NULL,
genre DictGenre[] NOT NULL,
abstract TEXT,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
description TEXT,
rights TEXT,
license TEXT,
owner VARCHAR(31)
REFERENCES Users(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL
);
CREATE TABLE LangTranslatesTo (
id SERIAL PRIMARY KEY,
langfrom UUID
REFERENCES Languages(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
langto UUID
REFERENCES Languages(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL
);
CREATE TABLE LangAndAgents (
id SERIAL PRIMARY KEY,
agent VARCHAR(31)
REFERENCES Users(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
language UUID
REFERENCES Languages(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
relationship AgentLanguageRelation NOT NULL
);