CREATE TABLE "analytic_views" (
	"path_name" varchar(500) NOT NULL,
	"views" integer DEFAULT 0 NOT NULL,
	"post_id" uuid
);
--> 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,"gaViews":0}'::jsonb;--> statement-breakpoint
UPDATE "posts" SET stats = stats || jsonb_build_object('gaViews', 0);
ALTER TABLE "analytic_views" ADD CONSTRAINT "analytic_views_post_id_posts_id_fk" FOREIGN KEY ("post_id") REFERENCES "public"."posts"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "analytic_views_path_name_idx" ON "analytic_views" USING btree ("path_name");