-- 商户 H5 微信 openid
SET @db := DATABASE();

SET @sql := IF(
  (SELECT COUNT(*) FROM information_schema.COLUMNS
   WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'yw_customer' AND COLUMN_NAME = 'openid') = 0,
  'ALTER TABLE `yw_customer` ADD COLUMN `openid` varchar(64) DEFAULT NULL COMMENT ''微信openid'' AFTER `phone`',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
  (SELECT COUNT(*) FROM information_schema.STATISTICS
   WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'yw_customer' AND INDEX_NAME = 'idx_openid') = 0,
  'ALTER TABLE `yw_customer` ADD INDEX `idx_openid` (`openid`)',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
