feat(19-01): update schema with reference item model and tags tables
- Add globalItemId and purchasePriceCents columns to items table - Add globalItemId column to threadCandidates table - Add tags and globalItemTags tables for tag system - Remove itemGlobalLinks table (replaced by direct FK) - Generate migration with data migration step before table drop
This commit is contained in:
27
drizzle-pg/0002_wakeful_vermin.sql
Normal file
27
drizzle-pg/0002_wakeful_vermin.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
CREATE TABLE "tags" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL,
|
||||
CONSTRAINT "tags_name_unique" UNIQUE("name")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "global_item_tags" (
|
||||
"global_item_id" integer NOT NULL,
|
||||
"tag_id" integer NOT NULL,
|
||||
CONSTRAINT "global_item_tags_global_item_id_tag_id_pk" PRIMARY KEY("global_item_id","tag_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "items" ADD COLUMN "global_item_id" integer;--> statement-breakpoint
|
||||
ALTER TABLE "items" ADD COLUMN "purchase_price_cents" integer;--> statement-breakpoint
|
||||
ALTER TABLE "thread_candidates" ADD COLUMN "global_item_id" integer;--> statement-breakpoint
|
||||
UPDATE "items" SET "global_item_id" = (
|
||||
SELECT "global_item_id" FROM "item_global_links"
|
||||
WHERE "item_global_links"."item_id" = "items"."id"
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "item_global_links" DISABLE ROW LEVEL SECURITY;--> statement-breakpoint
|
||||
DROP TABLE "item_global_links" CASCADE;--> statement-breakpoint
|
||||
ALTER TABLE "global_item_tags" ADD CONSTRAINT "global_item_tags_global_item_id_global_items_id_fk" FOREIGN KEY ("global_item_id") REFERENCES "public"."global_items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "global_item_tags" ADD CONSTRAINT "global_item_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "items" ADD CONSTRAINT "items_global_item_id_global_items_id_fk" FOREIGN KEY ("global_item_id") REFERENCES "public"."global_items"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "thread_candidates" ADD CONSTRAINT "thread_candidates_global_item_id_global_items_id_fk" FOREIGN KEY ("global_item_id") REFERENCES "public"."global_items"("id") ON DELETE no action ON UPDATE no action;
|
||||
1171
drizzle-pg/meta/0002_snapshot.json
Normal file
1171
drizzle-pg/meta/0002_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,13 @@
|
||||
"when": 1775386658636,
|
||||
"tag": "0001_tough_boomerang",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "7",
|
||||
"when": 1775413526643,
|
||||
"tag": "0002_wakeful_vermin",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user