CREATE TYPE "public"."staff_permission" AS ENUM('crud_product', 'make_coupon');--> statement-breakpoint
CREATE TYPE "public"."staff_role" AS ENUM('admin', 'marketer', 'delivery_staff');--> statement-breakpoint
CREATE TABLE "mf"."staff_permissions" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "mf"."staff_permissions_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"permission_name" "staff_permission" NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "unique_permission_name" UNIQUE("permission_name")
);
--> statement-breakpoint
CREATE TABLE "mf"."staff_role_permissions" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "mf"."staff_role_permissions_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"staff_role_id" integer NOT NULL,
	"staff_permission_id" integer NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "unique_role_permission" UNIQUE("staff_role_id","staff_permission_id")
);
--> statement-breakpoint
CREATE TABLE "mf"."staff_roles" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "mf"."staff_roles_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"role_name" "staff_role" NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "unique_role_name" UNIQUE("role_name")
);
--> statement-breakpoint
ALTER TABLE "mf"."staff_users" ADD COLUMN "staff_role_id" integer;--> statement-breakpoint
ALTER TABLE "mf"."staff_role_permissions" ADD CONSTRAINT "staff_role_permissions_staff_role_id_staff_roles_id_fk" FOREIGN KEY ("staff_role_id") REFERENCES "mf"."staff_roles"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "mf"."staff_role_permissions" ADD CONSTRAINT "staff_role_permissions_staff_permission_id_staff_permissions_id_fk" FOREIGN KEY ("staff_permission_id") REFERENCES "mf"."staff_permissions"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "mf"."staff_users" ADD CONSTRAINT "staff_users_staff_role_id_staff_roles_id_fk" FOREIGN KEY ("staff_role_id") REFERENCES "mf"."staff_roles"("id") ON DELETE no action ON UPDATE no action;