ordabok/migrations/2023-01-03-134426_create_language/up.sql
Lucien Cartier-Tilet c5f5e770e2
All checks were successful
continuous-integration/drone/push Build is passing
Fix word name collision, add two new user-related features
This commit changes the primary key of words to a serial number. That
way, two words with the same normalized value will not collide with
one another.

It also adds two new tables in the database:
- Users following languages
- Users learning words

The former can represent two stages of learning a word:
- Either the user is currently learning it
- Or they consider they know it and don’t need to work on it anymore

These two new tables now have their API query available through the
GraphQL API.

This commit also fixes the issue of word-related tables and types not
being dropped when resetting the database.
2023-01-18 10:26:45 +01:00

68 lines
1.5 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
);
CREATE TABLE UserFollowLanguage (
id SERIAL PRIMARY KEY,
lang UUID
REFERENCES Languages(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
userid VARCHAR(31)
REFERENCES Users(id)
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL
);