CREATE TABLE "mf"."reserved_coupons" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "mf"."reserved_coupons_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"secret_code" varchar(50) NOT NULL,
	"coupon_code" varchar(50) NOT NULL,
	"discount_percent" numeric(5, 2),
	"flat_discount" numeric(10, 2),
	"min_order" numeric(10, 2),
	"product_ids" jsonb,
	"max_value" numeric(10, 2),
	"valid_till" timestamp,
	"max_limit_for_user" integer,
	"exclusive_apply" boolean DEFAULT false NOT NULL,
	"is_redeemed" boolean DEFAULT false NOT NULL,
	"redeemed_by" integer,
	"redeemed_at" timestamp,
	"created_by" integer NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "reserved_coupons_secret_code_unique" UNIQUE("secret_code"),
	CONSTRAINT "unique_secret_code" UNIQUE("secret_code")
);
--> statement-breakpoint
ALTER TABLE "mf"."reserved_coupons" ADD CONSTRAINT "reserved_coupons_redeemed_by_users_id_fk" FOREIGN KEY ("redeemed_by") REFERENCES "mf"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "mf"."reserved_coupons" ADD CONSTRAINT "reserved_coupons_created_by_staff_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "mf"."staff_users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "mf"."coupons" DROP COLUMN "applicable_users";