Fix word name collision, add two new user-related features
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
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.
This commit is contained in:
@@ -1 +1,7 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE WordRelation;
|
||||
DROP TABLE WordLearning;
|
||||
DROP TABLE Words;
|
||||
DROP TYPE WordLearningStatus;
|
||||
DROP TYPE WordRelationship;
|
||||
DROP TYPE PartOfSpeech;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
-- 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 TYPE WordLearningStatus as ENUM('learning', 'learned');
|
||||
|
||||
CREATE TABLE Words (
|
||||
norm VARCHAR(255) PRIMARY KEY, -- normalized word
|
||||
id UUID DEFAULT uuid_generate_v4 () PRIMARY KEY,
|
||||
norm VARCHAR(255) NOT NULL, -- normalized word, generally in latin alphabet
|
||||
native VARCHAR(255),
|
||||
lemma VARCHAR(255)
|
||||
REFERENCES Words(norm)
|
||||
lemma UUID
|
||||
REFERENCES Words(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE SET NULL,
|
||||
language UUID
|
||||
@@ -26,15 +28,30 @@ CREATE TABLE Words (
|
||||
|
||||
CREATE TABLE WordRelation (
|
||||
id SERIAL PRIMARY KEY,
|
||||
wordsource VARCHAR(255)
|
||||
REFERENCES Words(norm)
|
||||
wordsource UUID
|
||||
REFERENCES Words(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
NOT NULL,
|
||||
wordtarget VARCHAR(255)
|
||||
REFERENCES Words(norm)
|
||||
wordtarget UUID
|
||||
REFERENCES Words(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
NOT NULL,
|
||||
relationship WordRelationship NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE WordLearning (
|
||||
id SERIAL PRIMARY KEY,
|
||||
word UUID
|
||||
REFERENCES Words(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
NOT NULL,
|
||||
userid VARCHAR(31)
|
||||
REFERENCES Users(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
NOT NULL,
|
||||
status WordLearningStatus DEFAULT 'learning' NOT NULL
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user