Initial commit with basic DB layout
This commit is contained in:
0
migrations/.keep
Normal file
0
migrations/.keep
Normal file
6
migrations/00000000000000_diesel_initial_setup/down.sql
Normal file
6
migrations/00000000000000_diesel_initial_setup/down.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- This file was automatically created by Diesel to setup helper functions
|
||||
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||
-- changes will be added to existing projects as new migrations.
|
||||
|
||||
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
|
||||
DROP FUNCTION IF EXISTS diesel_set_updated_at();
|
||||
36
migrations/00000000000000_diesel_initial_setup/up.sql
Normal file
36
migrations/00000000000000_diesel_initial_setup/up.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
-- This file was automatically created by Diesel to setup helper functions
|
||||
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||
-- changes will be added to existing projects as new migrations.
|
||||
|
||||
|
||||
|
||||
|
||||
-- Sets up a trigger for the given table to automatically set a column called
|
||||
-- `updated_at` whenever the row is modified (unless `updated_at` was included
|
||||
-- in the modified columns)
|
||||
--
|
||||
-- # Example
|
||||
--
|
||||
-- ```sql
|
||||
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
|
||||
--
|
||||
-- SELECT diesel_manage_updated_at('users');
|
||||
-- ```
|
||||
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
|
||||
BEGIN
|
||||
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
|
||||
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
IF (
|
||||
NEW IS DISTINCT FROM OLD AND
|
||||
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
|
||||
) THEN
|
||||
NEW.updated_at := current_timestamp;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
3
migrations/2023-01-03-134423_create_user/down.sql
Normal file
3
migrations/2023-01-03-134423_create_user/down.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE UserFollows;
|
||||
DROP TABLE Users;
|
||||
20
migrations/2023-01-03-134423_create_user/up.sql
Normal file
20
migrations/2023-01-03-134423_create_user/up.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- Your SQL goes here
|
||||
|
||||
CREATE TABLE Users (
|
||||
id VARCHAR(31) PRIMARY KEY, -- Appwrite User ID
|
||||
username VARCHAR(64) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE UserFollows (
|
||||
id SERIAL PRIMARY KEY,
|
||||
follower VARCHAR(31)
|
||||
REFERENCES Users(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
NOT NULL,
|
||||
following VARCHAR(31)
|
||||
REFERENCES Users(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
NOT NULL
|
||||
);
|
||||
6
migrations/2023-01-03-134426_create_language/down.sql
Normal file
6
migrations/2023-01-03-134426_create_language/down.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE LangAndAgents;
|
||||
DROP TABLE Languages;
|
||||
DROP TYPE Release;
|
||||
DROP TYPE DictGenre;
|
||||
DROP TYPE AgentLanguageRelation;
|
||||
37
migrations/2023-01-03-134426_create_language/up.sql
Normal file
37
migrations/2023-01-03-134426_create_language/up.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
-- Your SQL goes here
|
||||
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,
|
||||
native VARCHAR(255),
|
||||
relese Release NOT NULL,
|
||||
targetLanguage TEXT[] NOT NULL,
|
||||
genre DictGenre[] NOT NULL,
|
||||
abstract TEXT,
|
||||
created TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
description TEXT,
|
||||
rights TEXT,
|
||||
license TEXT,
|
||||
owner VARCHAR(31)
|
||||
REFERENCES Users(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 VARCHAR(255)
|
||||
REFERENCES Languages(name)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
NOT NULL,
|
||||
relationship AgentLanguageRelation NOT NULL
|
||||
);
|
||||
1
migrations/2023-01-03-134434_create_word/down.sql
Normal file
1
migrations/2023-01-03-134434_create_word/down.sql
Normal file
@@ -0,0 +1 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
40
migrations/2023-01-03-134434_create_word/up.sql
Normal file
40
migrations/2023-01-03-134434_create_word/up.sql
Normal file
@@ -0,0 +1,40 @@
|
||||
-- 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 VARCHAR(255)
|
||||
REFERENCES Languages(name)
|
||||
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
|
||||
);
|
||||
Reference in New Issue
Block a user