80 lines
3.4 KiB
SQL
80 lines
3.4 KiB
SQL
CREATE TABLE "entry" (
|
|
"id" UUID NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
"createdAt" TIMESTAMPTZ DEFAULT now(),
|
|
"updatedAt" TIMESTAMPTZ DEFAULT now(),
|
|
"userId" UUID NOT NULL REFERENCES "user"("id") ON DELETE CASCADE,
|
|
"type" TEXT NOT NULL,
|
|
"entry" TEXT[] NOT NULL CHECK ("entry"[1] IS NOT NULL),
|
|
-- "reading" -- backref "entry.reading"
|
|
-- "translation" -- backref "entry.translation"
|
|
"description" TEXT NOT NULL DEFAULT '',
|
|
"tag" TEXT[] NOT NULL DEFAULT '{}',
|
|
"level" FLOAT NOT NULL,
|
|
"level.kanji" INT NOT NULL,
|
|
"frequency" FLOAT
|
|
);
|
|
|
|
CREATE TRIGGER "t_entry_updatedAt"
|
|
BEFORE UPDATE ON "entry"
|
|
FOR EACH ROW
|
|
EXECUTE PROCEDURE "f_updatedAt"();
|
|
|
|
CREATE UNIQUE INDEX idx_entry_u ON "entry" (("entry"[1]), "type", "userId");
|
|
|
|
CREATE INDEX "idx_entry_updatedAt" ON "entry" ("updatedAt");
|
|
CREATE INDEX "idx_entry_userId" ON "entry" ("userId");
|
|
CREATE INDEX "idx_entry_type" ON "entry" ("type");
|
|
CREATE INDEX "idx_entry_level" ON "entry" ("level");
|
|
CREATE INDEX "idx_entry_level.kanji" ON "entry" ("level.kanji");
|
|
CREATE INDEX "idx_entry_frequency" ON "entry" ("frequency");
|
|
|
|
CREATE INDEX "idx_entry_description" ON "entry"
|
|
USING pgroonga("description")
|
|
WITH (plugins='token_filters/stem', token_filters='TokenFilterStem');
|
|
|
|
CREATE INDEX "idx_entry_entry" ON "entry"
|
|
USING pgroonga("entry")
|
|
WITH (
|
|
tokenizer='TokenMecab',
|
|
normalizer='NormalizerNFKC100("unify_kana", true)'
|
|
);
|
|
CREATE INDEX "idx_entry_entry_gin" ON "entry" USING GIN("entry");
|
|
CREATE INDEX "idx_entry_tag" ON "entry" USING pgroonga ("tag");
|
|
|
|
CREATE TABLE "entry.reading" (
|
|
"id" UUID NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
"createdAt" TIMESTAMPTZ DEFAULT now(),
|
|
"updatedAt" TIMESTAMPTZ DEFAULT now(),
|
|
"userId" UUID REFERENCES "user"("id") ON DELETE CASCADE,
|
|
"entryId" UUID REFERENCES "entry"("id") ON DELETE CASCADE
|
|
"type" TEXT NOT NULL,
|
|
"reading" TEXT[] NOT NULL DEFAULT '{}' CHECK ("reading"[1] IS NOT NULL)
|
|
);
|
|
|
|
CREATE INDEX "idx_entry.reading_updatedAt" ON "entry.reading" ("updatedAt");
|
|
CREATE INDEX "idx_entry.reading_userId" ON "entry.reading" ("userId")
|
|
CREATE INDEX "idx_entry.reading_type" ON "entry.reading" ("type");
|
|
CREATE INDEX "idx_entry.reading_reading" ON "entry.reading"
|
|
USING pgroonga (normalize_reading("reading"))
|
|
WITH (
|
|
tokenizer='TokenMecab',
|
|
normalizer='NormalizerNFKC100("unify_kana", true)'
|
|
);
|
|
|
|
CREATE TABLE "entry.translation" (
|
|
"id" UUID NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
"createdAt" TIMESTAMPTZ DEFAULT now(),
|
|
"updatedAt" TIMESTAMPTZ DEFAULT now(),
|
|
"userId" UUID REFERENCES "user"("id") ON DELETE CASCADE,
|
|
"entryId" UUID REFERENCES "entry"("id") ON DELETE CASCADE
|
|
"language" TEXT NOT NULL,
|
|
"translation" TEXT[] NOT NULL DEFAULT '{}' CHECK ("translation"[1] IS NOT NULL)
|
|
);
|
|
|
|
CREATE INDEX "idx_entry.translation_updatedAt" ON "entry.translation" ("updatedAt");
|
|
CREATE INDEX "idx_entry.translation_userId" ON "entry.translation" ("userId")
|
|
CREATE INDEX "idx_entry.translation_language" ON "entry.trnalsation" ("language");
|
|
CREATE INDEX "idx_entry.translation_translation" ON "entry.translation"
|
|
USING pgroonga("translation")
|
|
WITH (plugins='token_filters/stem', token_filters='TokenFilterStem');
|