CREATE TABLE "post_reaction" (
	"post_id" uuid NOT NULL,
	"user_id" uuid NOT NULL,
	"type" varchar(10) NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "post_reaction_post_id_user_id_pk" PRIMARY KEY("post_id","user_id")
);
--> statement-breakpoint
ALTER TABLE "reactions" DISABLE ROW LEVEL SECURITY;--> statement-breakpoint
DROP TABLE "reactions" CASCADE;--> statement-breakpoint
ALTER TABLE "posts" ALTER COLUMN "stats" SET DEFAULT '{"views":0,"viewsDay":0,"viewsYear":0,"shares":0,"sharesDay":0,"sharesYear":0,"upvotes":0,"downvotes":0}'::jsonb;--> statement-breakpoint
ALTER TABLE "post_reaction" ADD CONSTRAINT "post_reaction_post_id_posts_id_fk" FOREIGN KEY ("post_id") REFERENCES "public"."posts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "post_reaction" ADD CONSTRAINT "post_reaction_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "post_reaction_user_id_index" ON "post_reaction" USING btree ("user_id");--> statement-breakpoint
UPDATE "posts" SET stats = stats || jsonb_build_object('upvotes', 0, 'downvotes', 0);--> statement-breakpoint
CREATE INDEX "posts_stats_upvotes_index" ON "posts" USING btree ((("stats"->>'upvotes')::int));--> statement-breakpoint
CREATE INDEX "posts_stats_downvotes_index" ON "posts" USING btree ((("stats"->>'downvotes')::int));