ALTER TABLE "ms_options" DROP CONSTRAINT "ms_options_code_unique";--> statement-breakpoint
DROP INDEX "location_id_idx";--> statement-breakpoint
DROP INDEX "type_idx";--> statement-breakpoint
DROP INDEX "parent_id_idx";--> statement-breakpoint
ALTER TABLE "tr_audit_logs" ALTER COLUMN "before_data" SET DATA TYPE jsonb;--> statement-breakpoint
ALTER TABLE "tr_audit_logs" ALTER COLUMN "after_data" SET DATA TYPE jsonb;--> statement-breakpoint
ALTER TABLE "tr_quotations_attachments" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "tr_quotations_attachments" ALTER COLUMN "id" SET DEFAULT gen_random_uuid();--> statement-breakpoint
ALTER TABLE "tr_quotations_attachments" ALTER COLUMN "quotation_id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "tr_quotations_followups" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "tr_quotations_followups" ALTER COLUMN "id" SET DEFAULT gen_random_uuid();--> statement-breakpoint
ALTER TABLE "tr_quotations_followups" ALTER COLUMN "quotation_id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "ms_quotations_template_mappings" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "ms_quotations_template_mappings" ALTER COLUMN "id" SET DEFAULT gen_random_uuid();--> statement-breakpoint
ALTER TABLE "ms_quotations_template_mappings" ALTER COLUMN "template_version_id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "ms_quotations_template_table_columns" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "ms_quotations_template_table_columns" ALTER COLUMN "id" SET DEFAULT gen_random_uuid();--> statement-breakpoint
ALTER TABLE "ms_quotations_template_table_columns" ALTER COLUMN "mapping_id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "ms_quotations_template_versions" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "ms_quotations_template_versions" ALTER COLUMN "id" SET DEFAULT gen_random_uuid();--> statement-breakpoint
ALTER TABLE "ms_quotations_template_versions" ALTER COLUMN "template_id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "tr_quotations_topic_items" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "tr_quotations_topic_items" ALTER COLUMN "id" SET DEFAULT gen_random_uuid();--> statement-breakpoint
ALTER TABLE "tr_quotations_topic_items" ALTER COLUMN "topic_id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "tr_quotations_topics" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "tr_quotations_topics" ALTER COLUMN "id" SET DEFAULT gen_random_uuid();--> statement-breakpoint
ALTER TABLE "tr_quotations_topics" ALTER COLUMN "quotation_id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "ms_options" ALTER COLUMN "sort_order" SET DATA TYPE integer;--> statement-breakpoint
ALTER TABLE "tr_audit_logs" ADD COLUMN "branch_id" text;--> statement-breakpoint
ALTER TABLE "tr_audit_logs" ADD COLUMN "user_id" text;--> statement-breakpoint
ALTER TABLE "tr_audit_logs" ADD COLUMN "action_type" text;--> statement-breakpoint
ALTER TABLE "ms_industrial_estates" ADD COLUMN "branch_id" text NOT NULL;--> statement-breakpoint
ALTER TABLE "ms_industrial_estates" ADD COLUMN "is_active" boolean DEFAULT true;--> statement-breakpoint
ALTER TABLE "ms_locations" ADD COLUMN "branch_id" text NOT NULL;--> statement-breakpoint
ALTER TABLE "ms_options" ADD COLUMN "branch_id" text NOT NULL;--> statement-breakpoint
CREATE INDEX "tr_audit_logs_branch_id_idx" ON "tr_audit_logs" USING btree ("branch_id");--> statement-breakpoint
CREATE INDEX "tr_audit_logs_user_id_idx" ON "tr_audit_logs" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "tr_audit_logs_entity_type_idx" ON "tr_audit_logs" USING btree ("entity_type");--> statement-breakpoint
CREATE INDEX "tr_audit_logs_entity_id_idx" ON "tr_audit_logs" USING btree ("entity_id");--> statement-breakpoint
CREATE INDEX "tr_audit_logs_action_idx" ON "tr_audit_logs" USING btree ("action");--> statement-breakpoint
CREATE INDEX "tr_audit_logs_created_at_idx" ON "tr_audit_logs" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "tr_audit_logs_branch_entity_idx" ON "tr_audit_logs" USING btree ("branch_id","entity_type");--> statement-breakpoint
CREATE INDEX "tr_audit_logs_user_entity_idx" ON "tr_audit_logs" USING btree ("user_id","entity_type");--> statement-breakpoint
CREATE INDEX "ms_industrial_estates_branch_id_idx" ON "ms_industrial_estates" USING btree ("branch_id");--> statement-breakpoint
CREATE INDEX "ms_industrial_estates_location_id_idx" ON "ms_industrial_estates" USING btree ("location_id");--> statement-breakpoint
CREATE INDEX "ms_industrial_estates_branch_location_idx" ON "ms_industrial_estates" USING btree ("branch_id","location_id");--> statement-breakpoint
CREATE INDEX "ms_locations_branch_id_idx" ON "ms_locations" USING btree ("branch_id");--> statement-breakpoint
CREATE INDEX "ms_locations_type_idx" ON "ms_locations" USING btree ("type");--> statement-breakpoint
CREATE INDEX "ms_locations_parent_id_idx" ON "ms_locations" USING btree ("parent_id");--> statement-breakpoint
CREATE INDEX "ms_locations_branch_type_idx" ON "ms_locations" USING btree ("branch_id","type");--> statement-breakpoint
CREATE INDEX "ms_options_branch_id_idx" ON "ms_options" USING btree ("branch_id");--> statement-breakpoint
CREATE INDEX "ms_options_category_idx" ON "ms_options" USING btree ("category");--> statement-breakpoint
CREATE INDEX "ms_options_branch_category_idx" ON "ms_options" USING btree ("branch_id","category");--> statement-breakpoint
CREATE INDEX "ms_options_code_idx" ON "ms_options" USING btree ("code");