CREATE TABLE "tr_audit_logs" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "actor_id" text, "entity_type" text NOT NULL, "entity_id" text NOT NULL, "action" text NOT NULL, "before_data" text, "after_data" text, "ip_address" text, "user_agent" text, "request_id" text, "created_at" timestamp DEFAULT now(), "deleted_at" timestamp ); --> statement-breakpoint CREATE TABLE "ms_branches" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "code" text NOT NULL, "name" text NOT NULL, "is_active" boolean DEFAULT true, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now(), CONSTRAINT "ms_branches_code_unique" UNIQUE("code") ); --> statement-breakpoint CREATE TABLE "ms_customer_contact_shares" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "contact_id" uuid NOT NULL, "shared_with_user_id" uuid NOT NULL, "shared_by" uuid NOT NULL, "shared_at" timestamp DEFAULT now(), "notes" text, CONSTRAINT "uq_contact_share" UNIQUE("contact_id","shared_with_user_id") ); --> statement-breakpoint CREATE TABLE "ms_customer_contacts" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "branch_id" uuid NOT NULL, "customer_id" uuid NOT NULL, "name" text NOT NULL, "position" text, "department" text, "phone" text, "mobile" text, "email" text, "is_primary" boolean DEFAULT false, "notes" text, "created_by" uuid NOT NULL, "is_public" boolean DEFAULT false, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now(), "updated_by" uuid, "deleted_at" timestamp ); --> statement-breakpoint CREATE TABLE "ms_customers" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "branch_id" uuid NOT NULL, "crm_customer_code" text NOT NULL, "erp_customer_code" text, "name" text NOT NULL, "abbr" text, "tax_id" text, "address" text, "province" text, "district" text, "sub_district" text, "postal_code" text, "country" text DEFAULT 'Thailand', "phone" text, "email" text, "website" text, "customer_type" text, "customer_old" boolean DEFAULT false, "customer_ref" text, "customer_status" text DEFAULT 'draft', "lead_channel" text, "awareness" text, "customer_group" text, "customer_sub_group" text, "credit_limit" numeric(15, 2) DEFAULT '0', "payment_terms" text, "notes" text, "is_active" boolean DEFAULT true, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now(), "created_by" uuid, "updated_by" uuid, "deleted_at" timestamp, CONSTRAINT "ms_customers_crm_customer_code_unique" UNIQUE("crm_customer_code"), CONSTRAINT "ms_customers_erp_customer_code_unique" UNIQUE("erp_customer_code") ); --> statement-breakpoint CREATE TABLE "document_sequences" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "document_type" text NOT NULL, "prefix" text NOT NULL, "period" text NOT NULL, "current_number" integer DEFAULT 0 NOT NULL, "padding_length" integer DEFAULT 3 NOT NULL, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now(), "deleted_at" timestamp ); --> statement-breakpoint CREATE TABLE "users" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "keycloak_id" text NOT NULL, "email" text NOT NULL, "name" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "users_keycloak_id_unique" UNIQUE("keycloak_id") ); --> statement-breakpoint CREATE TABLE "tr_quotations_attachments" ( "id" serial PRIMARY KEY NOT NULL, "quotation_id" integer NOT NULL, "file_name" text NOT NULL, "original_file_name" text NOT NULL, "file_path" text NOT NULL, "file_size" text NOT NULL, "file_type" text NOT NULL, "uploaded_at" timestamp DEFAULT now(), "uploaded_by" text, "description" text, "deleted_at" timestamp ); --> statement-breakpoint CREATE TABLE "tr_quotations_customers" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "quotation_id" uuid NOT NULL, "customer_id" uuid NOT NULL, "role" text NOT NULL, "is_primary" boolean DEFAULT false, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now(), "deleted_at" timestamp, CONSTRAINT "uq_quotations_customer" UNIQUE("quotation_id","customer_id","role") ); --> statement-breakpoint CREATE TABLE "tr_quotations_followups" ( "id" serial PRIMARY KEY NOT NULL, "quotation_id" integer NOT NULL, "followup_date" date NOT NULL, "followup_type" text, "contact_person" text, "contact_method" text, "outcome" text, "notes" text, "next_followup_date" date, "next_action" text, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "tr_quotations_items" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "quotation_id" uuid NOT NULL, "item_number" text NOT NULL, "product_type" text, "description" text NOT NULL, "quantity" numeric(10, 2) DEFAULT '1', "unit" text DEFAULT 'pcs', "unit_price" numeric(15, 2) DEFAULT '0', "discount" numeric(15, 2) DEFAULT '0', "discount_type" text DEFAULT 'percentage', "tax_rate" numeric(5, 2) DEFAULT '7', "total_price" numeric(15, 2) DEFAULT '0', "notes" text, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now(), "deleted_at" timestamp ); --> statement-breakpoint CREATE TABLE "ms_quotations_template_mappings" ( "id" serial PRIMARY KEY NOT NULL, "template_version_id" integer NOT NULL, "placeholder_key" text NOT NULL, "source_path" text NOT NULL, "data_type" text NOT NULL, "sheet_name" text, "default_value" text, "format_mask" text, "sort_order" integer DEFAULT 0, "created_at" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "ms_quotations_template_table_columns" ( "id" serial PRIMARY KEY NOT NULL, "mapping_id" integer NOT NULL, "column_name" text NOT NULL, "source_field" text NOT NULL, "column_letter" text, "sort_order" integer NOT NULL, "format_mask" text, "created_at" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "ms_quotations_template_versions" ( "id" serial PRIMARY KEY NOT NULL, "template_id" integer NOT NULL, "version" text NOT NULL, "file_path" text NOT NULL, "is_active" boolean DEFAULT false, "description" text, "created_at" timestamp DEFAULT now(), "created_by" text, CONSTRAINT "uq_template_version" UNIQUE("template_id","version") ); --> statement-breakpoint CREATE TABLE "ms_quotations_templates" ( "id" serial PRIMARY KEY NOT NULL, "product_type" text NOT NULL, "file_type" text NOT NULL, "template_name" text NOT NULL, "template_path" text NOT NULL, "is_default" boolean DEFAULT false, "created_at" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "ms_quotations_topic_defaults" ( "id" serial PRIMARY KEY NOT NULL, "product_type" text NOT NULL, "topic_type" text NOT NULL, "content" text NOT NULL, "sort_order" integer DEFAULT 0, "is_active" boolean DEFAULT true, "created_at" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "tr_quotations_topic_items" ( "id" serial PRIMARY KEY NOT NULL, "topic_id" integer NOT NULL, "content" text NOT NULL, "sort_order" integer DEFAULT 0, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "tr_quotations_topics" ( "id" serial PRIMARY KEY NOT NULL, "quotation_id" integer NOT NULL, "topic_type" text NOT NULL, "sort_order" integer DEFAULT 0, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "tr_quotations" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "branch_id" uuid NOT NULL, "code" text NOT NULL, "revision_no" integer DEFAULT 1 NOT NULL, "parent_quotation_id" uuid, "quotation_date" date NOT NULL, "valid_until" date, "quotation_type" text, "competitor" text, "mk_job_no" text, "status" text DEFAULT 'draft', "is_active" boolean DEFAULT true, "revision" text DEFAULT '0', "revision_remark" text, "template_id" integer, "subtotal" numeric(15, 2) DEFAULT '0', "discount" numeric(15, 2) DEFAULT '0', "discount_type" text DEFAULT 'percentage', "tax_rate" numeric(5, 2) DEFAULT '7', "tax_amount" numeric(15, 2) DEFAULT '0', "total_amount" numeric(15, 2) DEFAULT '0', "salesman_id" uuid, "sale_admin_id" uuid, "currency_code" text DEFAULT 'THB' NOT NULL, "exchange_rate" numeric(12, 6) NOT NULL, "base_currency_amount" numeric(15, 2), "notes" text, "reference" text, "project" text, "attention" text, "location_province" text, "location_industrial" text, "location_orther" text, "final_date" date, "delivery_date" date, "chance_percent" integer, "is_hot_project" boolean DEFAULT false, "approved_snapshot" jsonb, "approved_pdf_url" text, "is_sent" boolean DEFAULT false, "sent_at" timestamp, "sent_via" text, "accepted_at" timestamp, "rejected_at" timestamp, "rejection_reason" text, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now(), "created_by" uuid, "updated_by" uuid, "deleted_at" timestamp ); --> statement-breakpoint CREATE TABLE "tr_quotation_contacts" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "quotation_id" uuid NOT NULL, "contact_id" uuid, "snapshot_name" text NOT NULL, "snapshot_email" text, "snapshot_phone" text, "snapshot_mobile" text, "snapshot_position" text, "snapshot_department" text, "created_at" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "ms_industrial_estates" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "code" varchar(255) NOT NULL, "name_th" varchar(255) NOT NULL, "name_en" varchar(255), "location_id" uuid NOT NULL, "latitude" double precision, "longitude" double precision, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "created_by" text, "updated_by" text ); --> statement-breakpoint CREATE TABLE "ms_locations" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "code" varchar(255) NOT NULL, "name_th" varchar(255) NOT NULL, "name_en" varchar(255), "type" varchar(50) NOT NULL, "parent_id" uuid, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "ms_options" ( "id" serial PRIMARY KEY NOT NULL, "code" text NOT NULL, "name" text NOT NULL, "category" text NOT NULL, "description" text, "value" text, "parent_id" integer, "is_active" boolean DEFAULT true, "sort_order" text DEFAULT '0', "level" integer DEFAULT 0, "created_at" timestamp DEFAULT now(), "updated_at" timestamp DEFAULT now(), "created_by" text, "updated_by" text, "deleted_at" timestamp, CONSTRAINT "ms_options_code_unique" UNIQUE("code") ); --> statement-breakpoint ALTER TABLE "ms_customer_contact_shares" ADD CONSTRAINT "ms_customer_contact_shares_contact_id_ms_customer_contacts_id_fk" FOREIGN KEY ("contact_id") REFERENCES "public"."ms_customer_contacts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_customer_contact_shares" ADD CONSTRAINT "ms_customer_contact_shares_shared_with_user_id_users_id_fk" FOREIGN KEY ("shared_with_user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_customer_contact_shares" ADD CONSTRAINT "ms_customer_contact_shares_shared_by_users_id_fk" FOREIGN KEY ("shared_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_customer_contacts" ADD CONSTRAINT "ms_customer_contacts_branch_id_ms_branches_id_fk" FOREIGN KEY ("branch_id") REFERENCES "public"."ms_branches"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_customer_contacts" ADD CONSTRAINT "ms_customer_contacts_customer_id_ms_customers_id_fk" FOREIGN KEY ("customer_id") REFERENCES "public"."ms_customers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_customer_contacts" ADD CONSTRAINT "ms_customer_contacts_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 "ms_customer_contacts" ADD CONSTRAINT "ms_customer_contacts_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_customers" ADD CONSTRAINT "ms_customers_branch_id_ms_branches_id_fk" FOREIGN KEY ("branch_id") REFERENCES "public"."ms_branches"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_customers" ADD CONSTRAINT "ms_customers_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 "ms_customers" ADD CONSTRAINT "ms_customers_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations_attachments" ADD CONSTRAINT "tr_quotations_attachments_quotation_id_tr_quotations_id_fk" FOREIGN KEY ("quotation_id") REFERENCES "public"."tr_quotations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations_customers" ADD CONSTRAINT "tr_quotations_customers_quotation_id_tr_quotations_id_fk" FOREIGN KEY ("quotation_id") REFERENCES "public"."tr_quotations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations_customers" ADD CONSTRAINT "tr_quotations_customers_customer_id_ms_customers_id_fk" FOREIGN KEY ("customer_id") REFERENCES "public"."ms_customers"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations_followups" ADD CONSTRAINT "tr_quotations_followups_quotation_id_tr_quotations_id_fk" FOREIGN KEY ("quotation_id") REFERENCES "public"."tr_quotations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations_items" ADD CONSTRAINT "tr_quotations_items_quotation_id_tr_quotations_id_fk" FOREIGN KEY ("quotation_id") REFERENCES "public"."tr_quotations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_quotations_template_mappings" ADD CONSTRAINT "ms_quotations_template_mappings_template_version_id_ms_quotations_template_versions_id_fk" FOREIGN KEY ("template_version_id") REFERENCES "public"."ms_quotations_template_versions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_quotations_template_table_columns" ADD CONSTRAINT "ms_quotations_template_table_columns_mapping_id_ms_quotations_template_mappings_id_fk" FOREIGN KEY ("mapping_id") REFERENCES "public"."ms_quotations_template_mappings"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_quotations_template_versions" ADD CONSTRAINT "ms_quotations_template_versions_template_id_ms_quotations_templates_id_fk" FOREIGN KEY ("template_id") REFERENCES "public"."ms_quotations_templates"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations_topic_items" ADD CONSTRAINT "tr_quotations_topic_items_topic_id_tr_quotations_topics_id_fk" FOREIGN KEY ("topic_id") REFERENCES "public"."tr_quotations_topics"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations_topics" ADD CONSTRAINT "tr_quotations_topics_quotation_id_tr_quotations_id_fk" FOREIGN KEY ("quotation_id") REFERENCES "public"."tr_quotations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations" ADD CONSTRAINT "tr_quotations_branch_id_ms_branches_id_fk" FOREIGN KEY ("branch_id") REFERENCES "public"."ms_branches"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations" ADD CONSTRAINT "tr_quotations_parent_quotation_id_tr_quotations_id_fk" FOREIGN KEY ("parent_quotation_id") REFERENCES "public"."tr_quotations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations" ADD CONSTRAINT "tr_quotations_salesman_id_users_id_fk" FOREIGN KEY ("salesman_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations" ADD CONSTRAINT "tr_quotations_sale_admin_id_users_id_fk" FOREIGN KEY ("sale_admin_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotations" ADD CONSTRAINT "tr_quotations_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 "tr_quotations" ADD CONSTRAINT "tr_quotations_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotation_contacts" ADD CONSTRAINT "tr_quotation_contacts_quotation_id_tr_quotations_id_fk" FOREIGN KEY ("quotation_id") REFERENCES "public"."tr_quotations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tr_quotation_contacts" ADD CONSTRAINT "tr_quotation_contacts_contact_id_ms_customer_contacts_id_fk" FOREIGN KEY ("contact_id") REFERENCES "public"."ms_customer_contacts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ms_industrial_estates" ADD CONSTRAINT "ms_industrial_estates_location_id_ms_locations_id_fk" FOREIGN KEY ("location_id") REFERENCES "public"."ms_locations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint CREATE INDEX "idx_branches_code" ON "ms_branches" USING btree ("code");--> statement-breakpoint CREATE INDEX "idx_branches_is_active" ON "ms_branches" USING btree ("is_active");--> statement-breakpoint CREATE INDEX "idx_contact_shares_contact" ON "ms_customer_contact_shares" USING btree ("contact_id");--> statement-breakpoint CREATE INDEX "idx_contact_shares_user" ON "ms_customer_contact_shares" USING btree ("shared_with_user_id");--> statement-breakpoint CREATE INDEX "idx_contact_shares_shared_by" ON "ms_customer_contact_shares" USING btree ("shared_by");--> statement-breakpoint CREATE INDEX "idx_contacts_customer" ON "ms_customer_contacts" USING btree ("customer_id");--> statement-breakpoint CREATE INDEX "idx_contacts_branch" ON "ms_customer_contacts" USING btree ("branch_id");--> statement-breakpoint CREATE INDEX "idx_contacts_created_by" ON "ms_customer_contacts" USING btree ("created_by");--> statement-breakpoint CREATE INDEX "idx_contacts_visibility" ON "ms_customer_contacts" USING btree ("customer_id","created_by");--> statement-breakpoint CREATE INDEX "idx_customers_branch" ON "ms_customers" USING btree ("branch_id");--> statement-breakpoint CREATE INDEX "idx_customers_status" ON "ms_customers" USING btree ("customer_status");--> statement-breakpoint CREATE INDEX "idx_customers_crm_code" ON "ms_customers" USING btree ("crm_customer_code");--> statement-breakpoint CREATE INDEX "idx_customers_erp_code" ON "ms_customers" USING btree ("erp_customer_code");--> statement-breakpoint CREATE UNIQUE INDEX "uq_document_period" ON "document_sequences" USING btree ("document_type","period");--> statement-breakpoint CREATE INDEX "idx_qcust_quotation_id" ON "tr_quotations_customers" USING btree ("quotation_id");--> statement-breakpoint CREATE INDEX "idx_qcust_customer_id" ON "tr_quotations_customers" USING btree ("customer_id");--> statement-breakpoint CREATE INDEX "idx_qitem_quotation_id" ON "tr_quotations_items" USING btree ("quotation_id");--> statement-breakpoint CREATE INDEX "idx_mapping_template_version" ON "ms_quotations_template_mappings" USING btree ("template_version_id");--> statement-breakpoint CREATE INDEX "idx_mapping_placeholder" ON "ms_quotations_template_mappings" USING btree ("placeholder_key");--> statement-breakpoint CREATE INDEX "idx_tablecol_mapping" ON "ms_quotations_template_table_columns" USING btree ("mapping_id");--> statement-breakpoint CREATE INDEX "idx_quotations_branch" ON "tr_quotations" USING btree ("branch_id");--> statement-breakpoint CREATE INDEX "idx_quotations_code" ON "tr_quotations" USING btree ("code");--> statement-breakpoint CREATE INDEX "idx_quotation_status" ON "tr_quotations" USING btree ("status");--> statement-breakpoint CREATE INDEX "idx_quotation_date" ON "tr_quotations" USING btree ("quotation_date");--> statement-breakpoint CREATE INDEX "idx_quotations_branch_status" ON "tr_quotations" USING btree ("branch_id","status");--> statement-breakpoint CREATE INDEX "idx_quotations_revision" ON "tr_quotations" USING btree ("parent_quotation_id");--> statement-breakpoint CREATE INDEX "idx_quotation_contact" ON "tr_quotation_contacts" USING btree ("quotation_id");--> statement-breakpoint CREATE INDEX "idx_quotation_contact_contact" ON "tr_quotation_contacts" USING btree ("contact_id");--> statement-breakpoint CREATE INDEX "location_id_idx" ON "ms_industrial_estates" USING btree ("location_id");--> statement-breakpoint CREATE INDEX "type_idx" ON "ms_locations" USING btree ("type");--> statement-breakpoint CREATE INDEX "parent_id_idx" ON "ms_locations" USING btree ("parent_id");