feat: add share schema and Discord account reconciliation
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
CREATE SCHEMA "share";
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "share"."comment" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"share_id" text NOT NULL,
|
||||
"body" text NOT NULL,
|
||||
"author_id" text,
|
||||
"author_discord_id" text NOT NULL,
|
||||
"author_name" text NOT NULL,
|
||||
"author_avatar_url" text,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "share"."text" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"content" text NOT NULL,
|
||||
"description" text,
|
||||
"image_cdn_id" text,
|
||||
"source" text NOT NULL,
|
||||
"author_id" text,
|
||||
"author_discord_id" text NOT NULL,
|
||||
"author_name" text NOT NULL,
|
||||
"author_avatar_url" text,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "share"."comment" ADD CONSTRAINT "comment_share_id_text_id_fk" FOREIGN KEY ("share_id") REFERENCES "share"."text"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "share"."comment" ADD CONSTRAINT "comment_author_id_user_id_fk" FOREIGN KEY ("author_id") REFERENCES "account"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "share"."text" ADD CONSTRAINT "text_image_cdn_id_cdn_id_fk" FOREIGN KEY ("image_cdn_id") REFERENCES "public"."cdn"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "share"."text" ADD CONSTRAINT "text_author_id_user_id_fk" FOREIGN KEY ("author_id") REFERENCES "account"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "share_comment_share_created_id_idx" ON "share"."comment" USING btree ("share_id","created_at","id");--> statement-breakpoint
|
||||
CREATE INDEX "share_text_author_created_idx" ON "share"."text" USING btree ("author_discord_id","created_at");--> statement-breakpoint
|
||||
UPDATE "account"."user" AS "user"
|
||||
SET "discord_id" = "account"."providerAccountId"
|
||||
FROM "account"."account" AS "account"
|
||||
WHERE "account"."provider" = 'discord'
|
||||
AND "account"."userId" = "user"."id"
|
||||
AND "user"."discord_id" IS NULL;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "user_discord_id_unique" ON "account"."user" USING btree ("discord_id");
|
||||
Reference in New Issue
Block a user