ordabok/migrations/2023-01-03-134426_create_language/up.sql

54 lines
1.3 KiB
MySQL
Raw Normal View History

2023-01-03 14:16:10 +00:00
-- Your SQL goes here
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
2023-01-03 14:16:10 +00:00
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,
2023-01-03 14:16:10 +00:00
native VARCHAR(255),
2023-01-03 15:11:43 +00:00
release Release NOT NULL,
2023-01-03 14:16:10 +00:00
genre DictGenre[] NOT NULL,
abstract TEXT,
2023-01-03 15:11:43 +00:00
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
2023-01-03 14:16:10 +00:00
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
);
2023-01-03 14:16:10 +00:00
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)
2023-01-03 14:16:10 +00:00
ON UPDATE CASCADE
ON DELETE CASCADE
NOT NULL,
relationship AgentLanguageRelation NOT NULL
);