CREATE TABLE "projects" (
	"id" varchar(64) PRIMARY KEY NOT NULL,
	"user_id" varchar(64) NOT NULL,
	"name" varchar(120) NOT NULL,
	"color" varchar(16),
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "receipts" ADD COLUMN "project_id" varchar(64);--> statement-breakpoint
ALTER TABLE "users" ADD COLUMN "monthly_volume" varchar(50);--> statement-breakpoint
ALTER TABLE "users" ADD COLUMN "export_format" varchar(100);--> statement-breakpoint
ALTER TABLE "users" ADD COLUMN "main_pain_point" varchar(100);--> statement-breakpoint
ALTER TABLE "projects" ADD CONSTRAINT "projects_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_projects_user_id" ON "projects" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "idx_projects_user_created" ON "projects" USING btree ("user_id","created_at");--> statement-breakpoint
CREATE UNIQUE INDEX "uq_projects_user_name" ON "projects" USING btree ("user_id","name");--> statement-breakpoint
ALTER TABLE "receipts" ADD CONSTRAINT "receipts_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_receipts_project" ON "receipts" USING btree ("user_id","project_id");