-- CreateTable CREATE TABLE `geo_cities` ( `code` VARCHAR(12) NOT NULL, `province_code` VARCHAR(12) NOT NULL, `province_name` VARCHAR(80) NOT NULL, `city_code` VARCHAR(12) NOT NULL, `city_name` VARCHAR(80) NOT NULL, `city_level` VARCHAR(32) NOT NULL, `status` ENUM('ENABLED', 'DISABLED') NOT NULL DEFAULT 'ENABLED', `effective_from` DATETIME(3) NULL, `effective_to` DATETIME(3) NULL, `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), `updated_at` DATETIME(3) NOT NULL, `created_by` VARCHAR(32) NULL, `updated_by` VARCHAR(32) NULL, `version` INTEGER NOT NULL DEFAULT 1, `deleted_at` DATETIME(3) NULL, UNIQUE INDEX `geo_cities_city_code_key`(`city_code`), INDEX `geo_cities_province_code_idx`(`province_code`), INDEX `geo_cities_province_name_city_name_idx`(`province_name`, `city_name`), INDEX `geo_cities_status_idx`(`status`), INDEX `geo_cities_deleted_at_idx`(`deleted_at`), PRIMARY KEY (`code`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `phone_number_segments` ( `segment7` CHAR(7) NOT NULL, `city_code` VARCHAR(12) NOT NULL, `province_name` VARCHAR(80) NOT NULL, `city_name` VARCHAR(80) NOT NULL, `carrier` ENUM('MOBILE', 'UNICOM', 'TELECOM', 'BROADCAST', 'MVNO', 'UNKNOWN') NOT NULL DEFAULT 'UNKNOWN', `source` VARCHAR(120) NULL, `batch_id` VARCHAR(64) NULL, `effective_from` DATETIME(3) NULL, `effective_to` DATETIME(3) NULL, `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), `updated_at` DATETIME(3) NOT NULL, `created_by` VARCHAR(32) NULL, `updated_by` VARCHAR(32) NULL, `version` INTEGER NOT NULL DEFAULT 1, `deleted_at` DATETIME(3) NULL, INDEX `phone_number_segments_city_code_idx`(`city_code`), INDEX `phone_number_segments_carrier_idx`(`carrier`), INDEX `phone_number_segments_batch_id_idx`(`batch_id`), INDEX `phone_number_segments_deleted_at_idx`(`deleted_at`), PRIMARY KEY (`segment7`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `phone_area_codes` ( `area_code` VARCHAR(8) NOT NULL, `city_code` VARCHAR(12) NOT NULL, `province_name` VARCHAR(80) NOT NULL, `city_name` VARCHAR(80) NOT NULL, `source` VARCHAR(120) NULL, `batch_id` VARCHAR(64) NULL, `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), `updated_at` DATETIME(3) NOT NULL, `created_by` VARCHAR(32) NULL, `updated_by` VARCHAR(32) NULL, `version` INTEGER NOT NULL DEFAULT 1, `deleted_at` DATETIME(3) NULL, INDEX `phone_area_codes_city_code_idx`(`city_code`), INDEX `phone_area_codes_batch_id_idx`(`batch_id`), INDEX `phone_area_codes_deleted_at_idx`(`deleted_at`), PRIMARY KEY (`area_code`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `carrier_prefix_rules` ( `prefix` VARCHAR(4) NOT NULL, `carrier` ENUM('MOBILE', 'UNICOM', 'TELECOM', 'BROADCAST', 'MVNO', 'UNKNOWN') NOT NULL, `priority` INTEGER NOT NULL DEFAULT 100, `source` VARCHAR(120) NULL, `batch_id` VARCHAR(64) NULL, `effective_from` DATETIME(3) NULL, `effective_to` DATETIME(3) NULL, `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), `updated_at` DATETIME(3) NOT NULL, `created_by` VARCHAR(32) NULL, `updated_by` VARCHAR(32) NULL, `version` INTEGER NOT NULL DEFAULT 1, `deleted_at` DATETIME(3) NULL, INDEX `carrier_prefix_rules_carrier_idx`(`carrier`), INDEX `carrier_prefix_rules_priority_idx`(`priority`), INDEX `carrier_prefix_rules_batch_id_idx`(`batch_id`), INDEX `carrier_prefix_rules_deleted_at_idx`(`deleted_at`), PRIMARY KEY (`prefix`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `vendor_gateway_blocked_regions` ( `id` VARCHAR(32) NOT NULL, `vendor_gateway_id` VARCHAR(32) NOT NULL, `region_scope` ENUM('PROVINCE', 'CITY') NOT NULL, `province_code` VARCHAR(12) NULL, `province_name` VARCHAR(80) NULL, `city_code` VARCHAR(12) NULL, `city_name` VARCHAR(80) NULL, `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), `created_by` VARCHAR(32) NULL, INDEX `vendor_gateway_blocked_regions_vendor_gateway_id_idx`(`vendor_gateway_id`), INDEX `vendor_gateway_blocked_regions_province_code_idx`(`province_code`), INDEX `vendor_gateway_blocked_regions_city_code_idx`(`city_code`), UNIQUE INDEX `vendor_gateway_blocked_regions_vendor_gateway_id_region_scope_province_code_city_code_key`(`vendor_gateway_id`, `region_scope`, `province_code`, `city_code`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- AlterTable ALTER TABLE `raw_cdrs` ADD COLUMN `callee_city_code` VARCHAR(12) NULL, ADD COLUMN `callee_city_name` VARCHAR(80) NULL, ADD COLUMN `callee_province_name` VARCHAR(80) NULL, ADD COLUMN `callee_operator` ENUM('MOBILE', 'UNICOM', 'TELECOM', 'BROADCAST', 'MVNO', 'UNKNOWN') NOT NULL DEFAULT 'UNKNOWN', ADD COLUMN `callee_number_type` ENUM('MOBILE', 'LANDLINE', 'INTERNATIONAL', 'UNKNOWN') NOT NULL DEFAULT 'UNKNOWN'; -- CreateIndex CREATE INDEX `raw_cdrs_callee_city_code_started_at_idx` ON `raw_cdrs`(`callee_city_code`, `started_at`); -- CreateIndex CREATE INDEX `raw_cdrs_callee_operator_started_at_idx` ON `raw_cdrs`(`callee_operator`, `started_at`); -- AddForeignKey ALTER TABLE `phone_number_segments` ADD CONSTRAINT `phone_number_segments_city_code_fkey` FOREIGN KEY (`city_code`) REFERENCES `geo_cities`(`city_code`) ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `phone_area_codes` ADD CONSTRAINT `phone_area_codes_city_code_fkey` FOREIGN KEY (`city_code`) REFERENCES `geo_cities`(`city_code`) ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `vendor_gateway_blocked_regions` ADD CONSTRAINT `vendor_gateway_blocked_regions_vendor_gateway_id_fkey` FOREIGN KEY (`vendor_gateway_id`) REFERENCES `vendor_gateways`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `vendor_gateway_blocked_regions` ADD CONSTRAINT `vendor_gateway_blocked_regions_city_code_fkey` FOREIGN KEY (`city_code`) REFERENCES `geo_cities`(`city_code`) ON DELETE RESTRICT ON UPDATE CASCADE;