-- 泰额版：在【平台主库】登记默认租户（业务数据在独立库）
-- 前置：已执行 create_platform_host_database.sql
-- 执行库：antis-foodlabeling-host（与 appsettings DbConnOptions.Url 一致）
-- 勿在业务库 fl_* 上执行；业务表不需要 TenantId

USE `antis-foodlabeling-host`;

SET @default_tenant_id = '11111111-1111-1111-1111-111111111111';
SET @default_tenant_name = 'Default';

-- 默认租户业务库连接串（现有数据所在库）
SET @default_business_conn = 'server=rm-bp19ohrgc6111ynzh1o.mysql.rds.aliyuncs.com;port=3306;database=antis-foodlabeling-us;uid=netteam;pwd=netteam;CharSet=utf8mb4;';

INSERT INTO yitenant (
  Id, Name, EntityVersion, TenantConnectionString, DbType,
  IsDeleted, CreationTime, ConcurrencyStamp)
SELECT
  @default_tenant_id, @default_tenant_name, 0, @default_business_conn, 0,
  0, NOW(), ''
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM yitenant WHERE Id = @default_tenant_id);

UPDATE yitenant
SET TenantConnectionString = @default_business_conn,
    DbType = 0,
    Name = @default_tenant_name
WHERE Id = @default_tenant_id;
