Add words, senses, translations schema migration

This commit is contained in:
lila 2026-07-24 00:23:56 +02:00
parent 061b05afb6
commit 63f27e8e13
3 changed files with 1102 additions and 0 deletions

View file

@ -0,0 +1,46 @@
CREATE TABLE "senses" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"word_id" uuid NOT NULL,
"sense_index" smallint DEFAULT 0 NOT NULL,
"difficulty" varchar(20) NOT NULL,
"definitions" text[] DEFAULT '{}' NOT NULL,
"examples" text[] DEFAULT '{}' NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "unique_sense_per_word" UNIQUE("word_id","sense_index"),
CONSTRAINT "senses_difficulty_check" CHECK ("senses"."difficulty" IN ('easy', 'medium', 'hard'))
);
--> statement-breakpoint
CREATE TABLE "translations" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"sense_id" uuid NOT NULL,
"target_language_code" varchar(10) NOT NULL,
"translation" text NOT NULL,
"gender" varchar(20),
"difficulty" varchar(20) NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "unique_translation_per_sense" UNIQUE("sense_id","target_language_code","translation"),
CONSTRAINT "translations_language_code_check" CHECK ("translations"."target_language_code" IN ('en', 'it', 'de', 'fr', 'es')),
CONSTRAINT "translations_difficulty_check" CHECK ("translations"."difficulty" IN ('easy', 'medium', 'hard')),
CONSTRAINT "translations_gender_check" CHECK ("translations"."gender" IS NULL OR "translations"."gender" IN ('masculine', 'feminine', 'neuter'))
);
--> statement-breakpoint
CREATE TABLE "words" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"headword" text NOT NULL,
"language_code" varchar(10) NOT NULL,
"pos" varchar(20) NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "unique_word_per_language_and_pos" UNIQUE("headword","language_code","pos"),
CONSTRAINT "words_language_code_check" CHECK ("words"."language_code" IN ('en', 'it', 'de', 'fr', 'es')),
CONSTRAINT "words_pos_check" CHECK ("words"."pos" IN ('noun', 'verb', 'adjective', 'adverb'))
);
--> statement-breakpoint
ALTER TABLE "entry_translations" DROP CONSTRAINT "difficulty_check";--> statement-breakpoint
ALTER TABLE "vocabulary_entries" DROP CONSTRAINT "difficulty_check";--> statement-breakpoint
ALTER TABLE "senses" ADD CONSTRAINT "senses_word_id_words_id_fk" FOREIGN KEY ("word_id") REFERENCES "public"."words"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "translations" ADD CONSTRAINT "translations_sense_id_senses_id_fk" FOREIGN KEY ("sense_id") REFERENCES "public"."senses"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_word_sense_difficulty" ON "senses" USING btree ("word_id","difficulty");--> statement-breakpoint
CREATE INDEX "idx_translations_sense_language_difficulty" ON "translations" USING btree ("sense_id","target_language_code","difficulty");--> statement-breakpoint
CREATE INDEX "idx_language_code_pos" ON "words" USING btree ("language_code","pos");--> statement-breakpoint
ALTER TABLE "entry_translations" ADD CONSTRAINT "difficulty_check" CHECK ("entry_translations"."difficulty" IS NULL OR "entry_translations"."difficulty" IN ('easy', 'medium', 'hard'));--> statement-breakpoint
ALTER TABLE "vocabulary_entries" ADD CONSTRAINT "difficulty_check" CHECK ("vocabulary_entries"."difficulty" IS NULL OR "vocabulary_entries"."difficulty" IN ('easy', 'medium', 'hard'));

File diff suppressed because it is too large Load diff

View file

@ -85,6 +85,13 @@
"when": 1777994750330,
"tag": "0011_nice_spyke",
"breakpoints": true
},
{
"idx": 12,
"version": "7",
"when": 1784844527683,
"tag": "0012_graceful_psynapse",
"breakpoints": true
}
]
}