更新代码
This commit is contained in:
@@ -6,20 +6,23 @@
|
||||
-- 3) yz_backend_contact_company : company contacts (customers/suppliers),
|
||||
-- shared by project contact picker / address book / customer-supplier
|
||||
-- conversion. This one was missed before: without the column any SELECT
|
||||
-- fails and contact lists show as empty (fixed by the server-side
|
||||
-- migration EnsureErpCompanyContactMobilesColumn on startup).
|
||||
-- fails and contact lists show as empty. Run this script manually
|
||||
-- (server-side auto-migration has been removed).
|
||||
-- All tables get a new column `mobiles` (TEXT, JSON array, max 5).
|
||||
-- The old `mobile` / `phone` column keeps the FIRST number for backward
|
||||
-- compatibility (list display, phone-based dedupe on sync), and existing
|
||||
-- single numbers are backfilled into `mobiles`.
|
||||
-- Run: mysql -h<host> -P<port> -u<user> -p <db> < alter_contact_mobiles.sql
|
||||
-- (re-running only reports "Duplicate column name", which is safe)
|
||||
-- (idempotent: existing columns are skipped, safe to re-run)
|
||||
-- NOTE: keep this file ASCII-only; piping through some shells mangles non-ASCII.
|
||||
-- =============================================================
|
||||
|
||||
-- 1) clue / business / project contacts
|
||||
ALTER TABLE `yz_backend_crm_entity_contact`
|
||||
ADD COLUMN `mobiles` TEXT NULL COMMENT 'phones in JSON array, max 5' AFTER `mobile`;
|
||||
-- idempotent: ALTER only runs when the column is missing (no 1060 on re-run)
|
||||
SET @tbl := (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'yz_backend_crm_entity_contact');
|
||||
SET @col := (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'yz_backend_crm_entity_contact' AND COLUMN_NAME = 'mobiles');
|
||||
SET @ddl := IF(@tbl > 0 AND @col = 0, 'ALTER TABLE `yz_backend_crm_entity_contact` ADD COLUMN `mobiles` TEXT NULL COMMENT ''phones in JSON array, max 5'' AFTER `mobile`', 'DO 0');
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- backfill existing single number as a one-element JSON array
|
||||
UPDATE `yz_backend_crm_entity_contact`
|
||||
@@ -28,8 +31,10 @@ UPDATE `yz_backend_crm_entity_contact`
|
||||
AND `mobile` IS NOT NULL AND `mobile` <> '';
|
||||
|
||||
-- 2) global address book contacts
|
||||
ALTER TABLE `yz_backend_erp_contact`
|
||||
ADD COLUMN `mobiles` TEXT NULL COMMENT 'phones in JSON array, max 5' AFTER `phone`;
|
||||
SET @tbl := (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'yz_backend_erp_contact');
|
||||
SET @col := (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'yz_backend_erp_contact' AND COLUMN_NAME = 'mobiles');
|
||||
SET @ddl := IF(@tbl > 0 AND @col = 0, 'ALTER TABLE `yz_backend_erp_contact` ADD COLUMN `mobiles` TEXT NULL COMMENT ''phones in JSON array, max 5'' AFTER `phone`', 'DO 0');
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
UPDATE `yz_backend_erp_contact`
|
||||
SET `mobiles` = JSON_ARRAY(`phone`)
|
||||
@@ -38,9 +43,11 @@ UPDATE `yz_backend_erp_contact`
|
||||
|
||||
-- 3) company contacts (customers / suppliers) - shared by project contact
|
||||
-- picker / address book / customer-supplier conversion.
|
||||
-- NOTE: also auto-added on server startup (EnsureErpCompanyContactMobilesColumn).
|
||||
ALTER TABLE `yz_backend_contact_company`
|
||||
ADD COLUMN `mobiles` TEXT NULL COMMENT 'phones in JSON array, max 5' AFTER `phone`;
|
||||
-- NOTE: run this script manually (server-side auto-migration has been removed).
|
||||
SET @tbl := (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'yz_backend_contact_company');
|
||||
SET @col := (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'yz_backend_contact_company' AND COLUMN_NAME = 'mobiles');
|
||||
SET @ddl := IF(@tbl > 0 AND @col = 0, 'ALTER TABLE `yz_backend_contact_company` ADD COLUMN `mobiles` TEXT NULL COMMENT ''phones in JSON array, max 5'' AFTER `phone`', 'DO 0');
|
||||
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
UPDATE `yz_backend_contact_company`
|
||||
SET `mobiles` = JSON_ARRAY(`phone`)
|
||||
|
||||
Reference in New Issue
Block a user