ALTER TABLE audit_flow
    ADD COLUMN is_default TINYINT(1) NOT NULL DEFAULT 0 AFTER status,
    ADD COLUMN effective_start_at DATETIME DEFAULT NULL AFTER is_default,
    ADD COLUMN effective_end_at DATETIME DEFAULT NULL AFTER effective_start_at;

CREATE TABLE IF NOT EXISTS audit_flow_node_assignee (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    flow_node_id BIGINT UNSIGNED NOT NULL,
    assignee_type VARCHAR(32) NOT NULL COMMENT 'USER/ROLE/PROJECT_OWNER',
    assignee_ref_id BIGINT UNSIGNED DEFAULT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    KEY idx_flow_node (flow_node_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

UPDATE audit_flow
SET is_default = 1
WHERE tenant_id = 1 AND flow_code = 'DEFAULT';
