CREATE TABLE "product_info_change" ( "id" serial PRIMARY KEY NOT NULL, "product_id" text NOT NULL, "by_id" text, "kind" text NOT NULL, "changes" jsonb NOT NULL, "reason" text DEFAULT '' NOT NULL, "revert_of" integer, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "product" ADD COLUMN "status" text DEFAULT 'published' NOT NULL;--> statement-breakpoint ALTER TABLE "product" ADD COLUMN "published_at" timestamp with time zone;--> statement-breakpoint ALTER TABLE "product" ADD COLUMN "listed" boolean DEFAULT true NOT NULL;--> statement-breakpoint ALTER TABLE "product" ADD COLUMN "tags" jsonb DEFAULT '[]'::jsonb NOT NULL;--> statement-breakpoint ALTER TABLE "product" ADD COLUMN "locked" jsonb DEFAULT '[]'::jsonb NOT NULL;--> statement-breakpoint ALTER TABLE "product_info_change" ADD CONSTRAINT "product_info_change_product_id_product_id_fk" FOREIGN KEY ("product_id") REFERENCES "public"."product"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "product_info_change" ADD CONSTRAINT "product_info_change_by_id_user_id_fk" FOREIGN KEY ("by_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint CREATE INDEX "product_info_change_product" ON "product_info_change" USING btree ("product_id","id");--> statement-breakpoint CREATE INDEX "product_tags" ON "product" USING gin ("tags");--> statement-breakpoint -- Products from before drafts were published when made. UPDATE "product" SET "published_at" = "created_at" WHERE "published_at" IS NULL;