-- ---------------------------- -- 服务商模块:服务商标识列 + 服务商配置表 -- -- 目标库 hugray-account(库名含连字符,任何引用都必须用反引号)。 -- account_user 是加列(表里已有数据),故用幂等过程做存在性判断,绝不 DROP; -- account_provider 是新建,用 CREATE TABLE IF NOT EXISTS。脚本可重复执行。 -- 演示数据另见 hugray_provider_demo_20261012.sql。 -- -- 【服务商为什么落在 account_user】 -- 服务商是「会员的另一个身份」,不是另一套用户体系: -- * 它的「L1/L2/L3 虚拟账号权益」与 account_user.system_level(C/statics/...), -- 换环境后旧值会指向老主机,故给足 500(与 account_certification.license_image 同宽)。 CREATE TABLE IF NOT EXISTS `account_provider` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '服务商编号', `user_id` bigint(20) NOT NULL COMMENT '关联账号(account_user.user_id,1:1)', `company_name` varchar(128) NOT NULL COMMENT '公司名称', `contact_name` varchar(64) NOT NULL COMMENT '联系人(列表「管理人」列)', `contact_phone` varchar(20) NOT NULL COMMENT '手机号码', `credit_code` varchar(64) DEFAULT NULL COMMENT '统一社会信用代码', `legal_person` varchar(64) DEFAULT NULL COMMENT '企业法人', `region` varchar(64) DEFAULT NULL COMMENT '注册地区(存市名文本,取自 account_city.city_name)', `register_date` date DEFAULT NULL COMMENT '注册日期', `address` varchar(255) DEFAULT NULL COMMENT '企业地址', `license_url` varchar(500) DEFAULT NULL COMMENT '营业执照图片地址', `l1_quota` int(11) NOT NULL DEFAULT 0 COMMENT '虚拟账号权益:L1 分配数量', `l2_quota` int(11) NOT NULL DEFAULT 0 COMMENT '虚拟账号权益:L2 分配数量', `l3_quota` int(11) NOT NULL DEFAULT 0 COMMENT '虚拟账号权益:L3 分配数量', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1禁用)', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 2删除)', `create_by` varchar(64) DEFAULT '' COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` varchar(64) DEFAULT '' COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`id`), KEY `idx_provider_user` (`user_id`), KEY `idx_provider_status` (`status`) ) ENGINE=InnoDB AUTO_INCREMENT=33141000 DEFAULT CHARSET=utf8mb4 COMMENT='服务商配置表(一个会员至多一条)'; -- 起始 33141000 对齐原型里的 8 位编号观感(业务上无特殊含义), -- 与城市公司档案的 33140000 段错开,两个模块的编号一眼能分辨。 -- 不建 region 索引:没有按注册地区筛选的查询。 -- ---------- 3. 收尾:删掉临时过程 ---------- DROP PROCEDURE IF EXISTS `hugray_add_column`; -- ---------- 4. 结果核对 ---------- SELECT `table_name`, `table_comment` FROM `information_schema`.`tables` WHERE `table_schema` = 'hugray-account' AND `table_name` = 'account_provider'; SELECT `ordinal_position`, `column_name`, `column_type`, `is_nullable`, `column_default`, `column_comment` FROM `information_schema`.`columns` WHERE `table_schema` = 'hugray-account' AND `table_name` = 'account_provider' ORDER BY `ordinal_position`; -- 应只回 idx_provider_user / idx_provider_status 两个业务索引 SELECT `index_name`, GROUP_CONCAT(`column_name` ORDER BY `seq_in_index`) AS `columns` FROM `information_schema`.`statistics` WHERE `table_schema` = 'hugray-account' AND `table_name` = 'account_provider' GROUP BY `index_name`; -- 标识列应存在且默认 '0' SELECT `column_name`, `column_type`, `is_nullable`, `column_default`, `column_comment` FROM `information_schema`.`columns` WHERE `table_schema` = 'hugray-account' AND `table_name` = 'account_user' AND `column_name` = 'provider_flag'; -- 临时过程必须已经删掉,应返回 0 行 SELECT `routine_name` FROM `information_schema`.`routines` WHERE `routine_schema` = 'hugray-account' AND `routine_name` = 'hugray_add_column';