CREATE TABLE "performance_conversion_metric_snapshots" ( "id" TEXT NOT NULL, "source_key" TEXT NOT NULL, "source_row_id" TEXT, "product_id" TEXT NOT NULL, "metric_date" DATE NOT NULL, "product_name" TEXT, "source_brand" TEXT, "category1" TEXT, "category2" TEXT, "category3" TEXT, "payment_amount" TEXT, "payment_users" TEXT, "cart_users" TEXT, "visitors" TEXT, "conversion_rate" TEXT, "favorites" TEXT, "impressions" TEXT, "clicks" TEXT, "click_rate" TEXT, "promotion_spend" TEXT, "promotion_revenue" TEXT, "roi" TEXT, "synced_at" TIMESTAMP(3) NOT NULL, "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" TIMESTAMP(3) NOT NULL, CONSTRAINT "performance_conversion_metric_snapshots_pkey" PRIMARY KEY ("id") ); CREATE UNIQUE INDEX "performance_conversion_metric_snapshots_source_key_key" ON "performance_conversion_metric_snapshots"("source_key"); CREATE INDEX "performance_conversion_metric_product_date_idx" ON "performance_conversion_metric_snapshots"("product_id", "metric_date"); CREATE INDEX "performance_conversion_metric_date_idx" ON "performance_conversion_metric_snapshots"("metric_date"); CREATE TABLE "performance_conversion_sync_states" ( "id" TEXT NOT NULL, "status" TEXT NOT NULL DEFAULT 'idle', "source_cursor_raw" TEXT, "last_started_at" TIMESTAMP(3), "last_completed_at" TIMESTAMP(3), "last_error" TEXT, "lease_owner" TEXT, "lease_expires_at" TIMESTAMP(3), "rows_upserted" INTEGER NOT NULL DEFAULT 0, "products_synced" INTEGER NOT NULL DEFAULT 0, "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" TIMESTAMP(3) NOT NULL, CONSTRAINT "performance_conversion_sync_states_pkey" PRIMARY KEY ("id") ); CREATE INDEX "performance_conversion_sync_states_lease_idx" ON "performance_conversion_sync_states"("lease_expires_at");