CREATE TABLE "pay_adjustments" ( "id" serial PRIMARY KEY NOT NULL, "company_id" integer NOT NULL, "user_id" integer NOT NULL, "month" text NOT NULL, "amount" numeric(14, 2) NOT NULL, "currency" text NOT NULL, "note" text NOT NULL, "created_by" integer NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "payouts" ( "id" serial PRIMARY KEY NOT NULL, "company_id" integer NOT NULL, "user_id" integer NOT NULL, "month" text NOT NULL, "amount" numeric(14, 2) NOT NULL, "currency" text NOT NULL, "paid_at" date NOT NULL, "note" text, "snapshot" jsonb NOT NULL, "created_by" integer NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "pay_adjustments" ADD CONSTRAINT "pay_adjustments_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pay_adjustments" ADD CONSTRAINT "pay_adjustments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pay_adjustments" ADD CONSTRAINT "pay_adjustments_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "payouts" ADD CONSTRAINT "payouts_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "payouts" ADD CONSTRAINT "payouts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "payouts" ADD CONSTRAINT "payouts_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint CREATE INDEX "pay_adjustments_user_month_idx" ON "pay_adjustments" USING btree ("company_id","user_id","month");--> statement-breakpoint CREATE UNIQUE INDEX "payouts_user_month_uq" ON "payouts" USING btree ("user_id","month");--> statement-breakpoint CREATE INDEX "payouts_company_idx" ON "payouts" USING btree ("company_id");