-- Template-level personalization overrides (null = inherit tenant)

SET @col_exists := (SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'company_workflow_lobster' AND COLUMN_NAME = 'enable_content_personalization');
SET @ddl := IF(@col_exists = 0,
    'ALTER TABLE company_workflow_lobster ADD COLUMN enable_content_personalization tinyint DEFAULT NULL COMMENT ''null=inherit tenant'' AFTER execution_mode',
    'SELECT 1');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @col_exists := (SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'company_workflow_lobster' AND COLUMN_NAME = 'enable_flow_personalization');
SET @ddl := IF(@col_exists = 0,
    'ALTER TABLE company_workflow_lobster ADD COLUMN enable_flow_personalization tinyint DEFAULT NULL COMMENT ''null=inherit tenant'' AFTER enable_content_personalization',
    'SELECT 1');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @col_exists := (SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'company_workflow_lobster' AND COLUMN_NAME = 'strict_fixed_workflow');
SET @ddl := IF(@col_exists = 0,
    'ALTER TABLE company_workflow_lobster ADD COLUMN strict_fixed_workflow tinyint DEFAULT NULL COMMENT ''null=inherit tenant'' AFTER enable_flow_personalization',
    'SELECT 1');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @col_exists := (SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'company_workflow_lobster' AND COLUMN_NAME = 'auto_start_instance_on_tag');
SET @ddl := IF(@col_exists = 0,
    'ALTER TABLE company_workflow_lobster ADD COLUMN auto_start_instance_on_tag tinyint DEFAULT NULL COMMENT ''null=inherit tenant'' AFTER strict_fixed_workflow',
    'SELECT 1');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
