CREATE TABLE "department_domain_assignment_history" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "department_domain_assignment_history_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"assignment_id" integer NOT NULL,
	"action" varchar(20) NOT NULL,
	"previous_values" text,
	"new_values" text,
	"changed_by" integer,
	"change_reason" text,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "department_domain_assignments" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "department_domain_assignments_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"company_code" varchar(10) NOT NULL,
	"department_code" varchar(50) NOT NULL,
	"department_name" varchar(255) NOT NULL,
	"assigned_domain" varchar(20) NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"description" text,
	"created_by" integer,
	"updated_by" integer,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "department_domain_mappings" (
	"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "department_domain_mappings_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"assignment_id" integer NOT NULL,
	"old_company_code" varchar(10) NOT NULL,
	"old_department_code" varchar(50) NOT NULL,
	"old_department_name" varchar(255),
	"new_company_code" varchar(10),
	"new_department_code" varchar(50),
	"new_department_name" varchar(255),
	"mapping_status" varchar(20) DEFAULT 'pending' NOT NULL,
	"mapped_by" integer,
	"mapped_at" timestamp,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "users" ADD COLUMN "deptCode" varchar(50);