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.
This commit is contained in:
2023-01-08 15:58:26 +01:00
parent eb48924761
commit 5c199e2628
9 changed files with 145 additions and 72 deletions

View File

@@ -1,6 +1,8 @@
-- This file should undo anything in `up.sql`
DROP TABLE LangAndAgents;
DROP TABLE LangTranslatesTo;
DROP TABLE Languages;
DROP TYPE Release;
DROP TYPE DictGenre;
DROP TYPE AgentLanguageRelation;
DROP EXTENSION "uuid-ossp";

View File

@@ -1,13 +1,15 @@
-- 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 (
name VARCHAR(255) PRIMARY KEY,
id UUID DEFAULT uuid_generate_v4 () PRIMARY KEY,
name VARCHAR(255) NOT NULL,
native VARCHAR(255),
release Release NOT NULL,
targetLanguage TEXT[] NOT NULL,
genre DictGenre[] NOT NULL,
abstract TEXT,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
@@ -21,6 +23,20 @@ CREATE TABLE Languages (
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)
@@ -28,8 +44,8 @@ CREATE TABLE LangAndAgents (
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
language VARCHAR(255)
REFERENCES Languages(name)
language UUID
REFERENCES Languages(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,