From 05856d624cfb76567aaed132ce0f8435e0fa084a Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 18 Aug 2022 22:31:17 +0200 Subject: [PATCH] Split migrations into separate files --- flake.nix | 6 +- .../{0001_initial.sql => 0001_JMDict.sql} | 196 +----------------- ...s.sql => 0002_JMDict_insert_constants.sql} | 0 migrations/0003_RADKFILE.sql | 11 + migrations/0004_KANJIDIC2.sql | 155 ++++++++++++++ migrations/0005_Connections.sql | 6 + 6 files changed, 176 insertions(+), 198 deletions(-) rename migrations/{0001_initial.sql => 0001_JMDict.sql} (60%) rename migrations/{0002_insert_info_values.sql => 0002_JMDict_insert_constants.sql} (100%) create mode 100644 migrations/0003_RADKFILE.sql create mode 100644 migrations/0004_KANJIDIC2.sql create mode 100644 migrations/0005_Connections.sql diff --git a/flake.nix b/flake.nix index 5406c96..0351739 100644 --- a/flake.nix +++ b/flake.nix @@ -197,15 +197,15 @@ ln -s ${self.packages.${system}.RADKFILE}/* data ln -s ${self.packages.${system}.KANJIDIC2}/* data - sqlite3 ${dbName} < migrations/0001_initial.sql - sqlite3 ${dbName} < migrations/0002_insert_info_values.sql + for migration in migrations/*.sql; do + sqlite3 ${dbName} < $migration + done ja_db ${pkgs.sqlite.out}/lib/libsqlite3.so ''; installPhase = '' mkdir -p $out - cp migrations/0001_initial.sql $out/schema.sql cp ${dbName} $out/${dbName} ''; }; diff --git a/migrations/0001_initial.sql b/migrations/0001_JMDict.sql similarity index 60% rename from migrations/0001_initial.sql rename to migrations/0001_JMDict.sql index 6c987dc..6f7cfae 100644 --- a/migrations/0001_initial.sql +++ b/migrations/0001_JMDict.sql @@ -1,9 +1,3 @@ --- TODO: figure out ondelete functions... - ------------- --- JMdict -- ------------- - CREATE TABLE "JMdict_InfoDialect" ( "id" VARCHAR(4) PRIMARY KEY NOT NULL, "description" TEXT NOT NULL @@ -252,192 +246,4 @@ CREATE TABLE "JMdict_EntryByEnglish" ( PRIMARY KEY ("english", "entryId") ) WITHOUT ROWID; -CREATE INDEX "JMdict_EntryByEnglish_byEnglish" ON "JMdict_EntryByEnglish"("english"); - --------------- --- RADKFILE -- --------------- - -CREATE TABLE "RADKFILE" ( - "kanji" CHAR(1) NOT NULL, - "radical" CHAR(1) NOT NULL, - PRIMARY KEY ("kanji", "radical") -) WITHOUT ROWID; - -CREATE INDEX "RADK" ON "RADKFILE"("radical"); -CREATE INDEX "KRAD" ON "RADKFILE"("kanji"); - -CREATE VIEW "RADKFILE_Radicals" AS -SELECT DISTINCT "radical" FROM "RADKFILE"; - --------------- --- KANJIDIC -- --------------- - -CREATE TABLE "KANJIDIC_Character" ( - "literal" CHAR(1) NOT NULL PRIMARY KEY, - "grade" INTEGER CHECK ("grade" BETWEEN 1 AND 10), - "strokeCount" INTEGER NOT NULL, - "frequency" INTEGER, - "jlpt" INTEGER -) WITHOUT ROWID; - -CREATE TABLE "KANJIDIC_RadicalName" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "name" TEXT NOT NULL, - PRIMARY KEY("kanji", "name") -) WITHOUT ROWID; - -CREATE TABLE "KANJIDIC_Codepoint" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "type" VARCHAR(6) NOT NULL CHECK ("type" IN ('jis208', 'jis212', 'jis213', 'ucs')), - "codepoint" VARCHAR(7) NOT NULL, - PRIMARY KEY ("kanji", "type") -) WITHOUT ROWID; - -CREATE INDEX "KANJIDIC_Codepoint_byCharacter" ON "KANJIDIC_Codepoint"("kanji"); - -CREATE TABLE "KANJIDIC_Radical" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "type" VARCHAR(9) NOT NULL CHECK ("type" IN ('classical', 'nelson_c')), - "radical" INTEGER NOT NULL CHECK ("radical" BETWEEN 1 AND IIF("type" = 'classical', 214, 212)), - PRIMARY KEY("kanji", "type") -) WITHOUT ROWID; - -CREATE TABLE "KANJIDIC_StrokeMiscount" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "strokeCount" INTEGER NOT NULL, - PRIMARY KEY("kanji", "strokeCount") -) WITHOUT ROWID; - -CREATE TABLE "KANJIDIC_Variant" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "variant" TEXT NOT NULL, - "type" VARCHAR(8) NOT NULL CHECK ( - "type" IN ( - 'jis208', - 'jis212', - 'jis213', - 'deroo', - 'njecd', - 's_h', - 'nelson_c', - 'oneill', - 'ucs' - ) - ), - PRIMARY KEY ("kanji", "type", "variant") -) WITHOUT ROWID; - -CREATE TABLE "_KANJIDIC_DictionaryReference_Part1" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "ref" VARCHAR(9) NOT NULL, - "type" VARCHAR(16) NOT NULL CHECK( - "type" IN ( - 'nelson_c', - 'nelson_n', - 'halpern_njecd', - 'halpern_kkd', - 'halpern_kkld', - 'halpern_kkld_2ed', - 'heisig', - 'heisig6', - 'gakken', - 'oneill_names', - 'oneill_kk', - 'henshall', - 'sh_kk', - 'sh_kk2', - 'sakade', - 'jf_cards', - 'henshall3', - 'tutt_cards', - 'crowley', - 'kanji_in_context', - 'busy_people', - 'kodansha_compact', - 'maniette' - ) - ), - PRIMARY KEY("kanji", "type") -) WITHOUT ROWID; - -CREATE TABLE "_KANJIDIC_DictionaryReference_Moro" ( - "kanji" CHAR(1) NOT NULL PRIMARY KEY REFERENCES "KANJIDIC_Character"("literal"), - "ref" VARCHAR(7) NOT NULL, - "volume" INTEGER, - "page" INTEGER -) WITHOUT ROWID; - -CREATE INDEX "KANJIDIC_DictionaryReference_byPart1" ON "_KANJIDIC_DictionaryReference_Part1"("kanji", "ref", "type"); -CREATE INDEX "KANJIDIC_DictionaryReference_byMoro" ON "_KANJIDIC_DictionaryReference_Moro"("kanji", "ref", "volume", "page"); - -CREATE VIEW "KANJIDIC_DictionaryReference" AS -SELECT "kanji", "ref", "type", NULL AS "volume", NULL AS "page" FROM "_KANJIDIC_DictionaryReference_Part1" -UNION -SELECT "kanji", "ref", 'moro' AS "type", "volume", "page" FROM "_KANJIDIC_DictionaryReference_Moro"; - -CREATE TABLE "KANJIDIC_QueryCode" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "code" VARCHAR(7) NOT NULL, - "type" VARCHAR(11) NOT NULL CHECK ("type" IN ('skip', 'sh_desc', 'four_corner', 'deroo', 'misclass')), - "SKIPMisclassification" VARCHAR(15), - PRIMARY KEY ("kanji", "type", "code") -) WITHOUT ROWID; - -CREATE TABLE "KANJIDIC_Reading" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "type" VARCHAR(8) NOT NULL CHECK ("type" IN ('korean_h', 'korean_r', 'pinyin')), - "reading" TEXT NOT NULL, - PRIMARY KEY ("kanji", "type", "reading") -) WITHOUT ROWID; - -CREATE INDEX "KANJIDIC_Reading_byReading" ON "KANJIDIC_Reading"("reading"); - -CREATE TABLE "KANJIDIC_Kunyomi" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "yomi" TEXT NOT NULL, - "isJouyou" BOOLEAN, - PRIMARY KEY ("kanji", "yomi") -) WITHOUT ROWID; - -CREATE INDEX "KANJIDIC_Kunyomi_byYomi" ON "KANJIDIC_Kunyomi"("yomi"); - -CREATE TABLE "KANJIDIC_Onyomi" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "yomi" TEXT NOT NULL, - "type" VARCHAR(7) CHECK ("type" IN ('kan', 'go', 'tou', 'kan''you')), - "isJouyou" BOOLEAN, - PRIMARY KEY ("kanji", "yomi") -) WITHOUT ROWID; - -CREATE INDEX "KANJIDIC_Onyomi_byYomi" ON "KANJIDIC_Onyomi"("yomi"); - -CREATE TABLE "KANJIDIC_Meaning" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "language" CHAR(3) NOT NULL DEFAULT "eng", - "meaning" TEXT NOT NULL, - PRIMARY KEY ("kanji", "language", "meaning") -) WITHOUT ROWID; - -CREATE INDEX "KANJIDIC_Meaning_byMeaning" ON "KANJIDIC_Meaning"("meaning"); - -CREATE TABLE "KANJIDIC_Nanori" ( - "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), - "nanori" TEXT NOT NULL, - PRIMARY KEY ("kanji", "nanori") -) WITHOUT ROWID; - -CREATE INDEX "KANJIDIC_Nanori_byNanori" ON "KANJIDIC_Nanori"("nanori"); - -------------------------- --- Interdict relations -- -------------------------- - --- Radk - kanjidic --- kanjireading -> filter kanji regex - kanjidic --- index kanji search by romaji --- index kanji search by hiragana --- index word search by romaji --- index word search by hiragana - +CREATE INDEX "JMdict_EntryByEnglish_byEnglish" ON "JMdict_EntryByEnglish"("english"); \ No newline at end of file diff --git a/migrations/0002_insert_info_values.sql b/migrations/0002_JMDict_insert_constants.sql similarity index 100% rename from migrations/0002_insert_info_values.sql rename to migrations/0002_JMDict_insert_constants.sql diff --git a/migrations/0003_RADKFILE.sql b/migrations/0003_RADKFILE.sql new file mode 100644 index 0000000..7081b4a --- /dev/null +++ b/migrations/0003_RADKFILE.sql @@ -0,0 +1,11 @@ +CREATE TABLE "RADKFILE" ( + "kanji" CHAR(1) NOT NULL, + "radical" CHAR(1) NOT NULL, + PRIMARY KEY ("kanji", "radical") +) WITHOUT ROWID; + +CREATE INDEX "RADK" ON "RADKFILE"("radical"); +CREATE INDEX "KRAD" ON "RADKFILE"("kanji"); + +CREATE VIEW "RADKFILE_Radicals" AS +SELECT DISTINCT "radical" FROM "RADKFILE"; \ No newline at end of file diff --git a/migrations/0004_KANJIDIC2.sql b/migrations/0004_KANJIDIC2.sql new file mode 100644 index 0000000..5ba7a89 --- /dev/null +++ b/migrations/0004_KANJIDIC2.sql @@ -0,0 +1,155 @@ +CREATE TABLE "KANJIDIC_Character" ( + "literal" CHAR(1) NOT NULL PRIMARY KEY, + "grade" INTEGER CHECK ("grade" BETWEEN 1 AND 10), + "strokeCount" INTEGER NOT NULL, + "frequency" INTEGER, + "jlpt" INTEGER +) WITHOUT ROWID; + +CREATE TABLE "KANJIDIC_RadicalName" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "name" TEXT NOT NULL, + PRIMARY KEY("kanji", "name") +) WITHOUT ROWID; + +CREATE TABLE "KANJIDIC_Codepoint" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "type" VARCHAR(6) NOT NULL CHECK ("type" IN ('jis208', 'jis212', 'jis213', 'ucs')), + "codepoint" VARCHAR(7) NOT NULL, + PRIMARY KEY ("kanji", "type") +) WITHOUT ROWID; + +CREATE INDEX "KANJIDIC_Codepoint_byCharacter" ON "KANJIDIC_Codepoint"("kanji"); + +CREATE TABLE "KANJIDIC_Radical" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "type" VARCHAR(9) NOT NULL CHECK ("type" IN ('classical', 'nelson_c')), + "radical" INTEGER NOT NULL CHECK ("radical" BETWEEN 1 AND IIF("type" = 'classical', 214, 212)), + PRIMARY KEY("kanji", "type") +) WITHOUT ROWID; + +CREATE TABLE "KANJIDIC_StrokeMiscount" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "strokeCount" INTEGER NOT NULL, + PRIMARY KEY("kanji", "strokeCount") +) WITHOUT ROWID; + +CREATE TABLE "KANJIDIC_Variant" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "variant" TEXT NOT NULL, + "type" VARCHAR(8) NOT NULL CHECK ( + "type" IN ( + 'jis208', + 'jis212', + 'jis213', + 'deroo', + 'njecd', + 's_h', + 'nelson_c', + 'oneill', + 'ucs' + ) + ), + PRIMARY KEY ("kanji", "type", "variant") +) WITHOUT ROWID; + +CREATE TABLE "_KANJIDIC_DictionaryReference_Part1" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "ref" VARCHAR(9) NOT NULL, + "type" VARCHAR(16) NOT NULL CHECK( + "type" IN ( + 'nelson_c', + 'nelson_n', + 'halpern_njecd', + 'halpern_kkd', + 'halpern_kkld', + 'halpern_kkld_2ed', + 'heisig', + 'heisig6', + 'gakken', + 'oneill_names', + 'oneill_kk', + 'henshall', + 'sh_kk', + 'sh_kk2', + 'sakade', + 'jf_cards', + 'henshall3', + 'tutt_cards', + 'crowley', + 'kanji_in_context', + 'busy_people', + 'kodansha_compact', + 'maniette' + ) + ), + PRIMARY KEY("kanji", "type") +) WITHOUT ROWID; + +CREATE TABLE "_KANJIDIC_DictionaryReference_Moro" ( + "kanji" CHAR(1) NOT NULL PRIMARY KEY REFERENCES "KANJIDIC_Character"("literal"), + "ref" VARCHAR(7) NOT NULL, + "volume" INTEGER, + "page" INTEGER +) WITHOUT ROWID; + +CREATE INDEX "KANJIDIC_DictionaryReference_byPart1" ON "_KANJIDIC_DictionaryReference_Part1"("kanji", "ref", "type"); +CREATE INDEX "KANJIDIC_DictionaryReference_byMoro" ON "_KANJIDIC_DictionaryReference_Moro"("kanji", "ref", "volume", "page"); + +CREATE VIEW "KANJIDIC_DictionaryReference" AS +SELECT "kanji", "ref", "type", NULL AS "volume", NULL AS "page" FROM "_KANJIDIC_DictionaryReference_Part1" +UNION +SELECT "kanji", "ref", 'moro' AS "type", "volume", "page" FROM "_KANJIDIC_DictionaryReference_Moro"; + +CREATE TABLE "KANJIDIC_QueryCode" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "code" VARCHAR(7) NOT NULL, + "type" VARCHAR(11) NOT NULL CHECK ("type" IN ('skip', 'sh_desc', 'four_corner', 'deroo', 'misclass')), + "SKIPMisclassification" VARCHAR(15), + PRIMARY KEY ("kanji", "type", "code") +) WITHOUT ROWID; + +CREATE TABLE "KANJIDIC_Reading" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "type" VARCHAR(8) NOT NULL CHECK ("type" IN ('korean_h', 'korean_r', 'pinyin')), + "reading" TEXT NOT NULL, + PRIMARY KEY ("kanji", "type", "reading") +) WITHOUT ROWID; + +CREATE INDEX "KANJIDIC_Reading_byReading" ON "KANJIDIC_Reading"("reading"); + +CREATE TABLE "KANJIDIC_Kunyomi" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "yomi" TEXT NOT NULL, + "isJouyou" BOOLEAN, + PRIMARY KEY ("kanji", "yomi") +) WITHOUT ROWID; + +CREATE INDEX "KANJIDIC_Kunyomi_byYomi" ON "KANJIDIC_Kunyomi"("yomi"); + +CREATE TABLE "KANJIDIC_Onyomi" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "yomi" TEXT NOT NULL, + "type" VARCHAR(7) CHECK ("type" IN ('kan', 'go', 'tou', 'kan''you')), + "isJouyou" BOOLEAN, + PRIMARY KEY ("kanji", "yomi") +) WITHOUT ROWID; + +CREATE INDEX "KANJIDIC_Onyomi_byYomi" ON "KANJIDIC_Onyomi"("yomi"); + +CREATE TABLE "KANJIDIC_Meaning" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "language" CHAR(3) NOT NULL DEFAULT "eng", + "meaning" TEXT NOT NULL, + PRIMARY KEY ("kanji", "language", "meaning") +) WITHOUT ROWID; + +CREATE INDEX "KANJIDIC_Meaning_byMeaning" ON "KANJIDIC_Meaning"("meaning"); + +CREATE TABLE "KANJIDIC_Nanori" ( + "kanji" CHAR(1) NOT NULL REFERENCES "KANJIDIC_Character"("literal"), + "nanori" TEXT NOT NULL, + PRIMARY KEY ("kanji", "nanori") +) WITHOUT ROWID; + +CREATE INDEX "KANJIDIC_Nanori_byNanori" ON "KANJIDIC_Nanori"("nanori"); \ No newline at end of file diff --git a/migrations/0005_Connections.sql b/migrations/0005_Connections.sql new file mode 100644 index 0000000..5289e7f --- /dev/null +++ b/migrations/0005_Connections.sql @@ -0,0 +1,6 @@ +-- Radk - kanjidic +-- kanjireading -> filter kanji regex - kanjidic +-- index kanji search by romaji +-- index kanji search by hiragana +-- index word search by romaji +-- index word search by hiragana \ No newline at end of file