1.0.357.sql 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. -- Standard operations are tenant-owned master data. The legacy unique index
  2. -- blocked two tenants from using the same operation/domain code.
  3. SET @std_op_ix_columns := (
  4. SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX)
  5. FROM information_schema.STATISTICS
  6. WHERE TABLE_SCHEMA=DATABASE()
  7. AND TABLE_NAME='StdOpMaster'
  8. AND INDEX_NAME='IX_StdOpMaster'
  9. );
  10. SET @std_op_ix_sql := CASE
  11. WHEN @std_op_ix_columns='tenant_id,StdOp,domain' THEN 'SELECT 1'
  12. WHEN @std_op_ix_columns IS NULL THEN
  13. 'ALTER TABLE `StdOpMaster` ADD UNIQUE INDEX `IX_StdOpMaster` (`tenant_id`,`StdOp`,`domain`)'
  14. ELSE
  15. 'ALTER TABLE `StdOpMaster` DROP INDEX `IX_StdOpMaster`, ADD UNIQUE INDEX `IX_StdOpMaster` (`tenant_id`,`StdOp`,`domain`)'
  16. END;
  17. PREPARE std_op_ix_stmt FROM @std_op_ix_sql;
  18. EXECUTE std_op_ix_stmt;
  19. DEALLOCATE PREPARE std_op_ix_stmt;
  20. -- S6 source business keys can repeat across tenants.
  21. SET @s6_ix_columns := (
  22. SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX)
  23. FROM information_schema.STATISTICS
  24. WHERE TABLE_SCHEMA=DATABASE()
  25. AND TABLE_NAME='mdp_stg_s6_report'
  26. AND INDEX_NAME='uk_source_key'
  27. );
  28. SET @s6_ix_sql := CASE
  29. WHEN @s6_ix_columns='tenant_id,source_system,source_table,source_biz_key' THEN 'SELECT 1'
  30. WHEN @s6_ix_columns IS NULL THEN
  31. 'ALTER TABLE `mdp_stg_s6_report` ADD UNIQUE INDEX `uk_source_key` (`tenant_id`,`source_system`,`source_table`,`source_biz_key`)'
  32. ELSE
  33. 'ALTER TABLE `mdp_stg_s6_report` DROP INDEX `uk_source_key`, ADD UNIQUE INDEX `uk_source_key` (`tenant_id`,`source_system`,`source_table`,`source_biz_key`)'
  34. END;
  35. PREPARE s6_ix_stmt FROM @s6_ix_sql;
  36. EXECUTE s6_ix_stmt;
  37. DEALLOCATE PREPARE s6_ix_stmt;