-- MSMEBiz v1.3, apply once AFTER migration_v1.2.sql. No existing tables are deleted.
CREATE TABLE IF NOT EXISTS organization_controls (
 org_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
 status ENUM('active','suspended') NOT NULL DEFAULT 'active',
 updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 CONSTRAINT fk_ctrl_org FOREIGN KEY (org_id) REFERENCES organizations(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS onboarding_invite_revocations (
 invite_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
 revoked_by BIGINT UNSIGNED NOT NULL,
 revoked_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
 CONSTRAINT fk_rev_inv FOREIGN KEY (invite_id) REFERENCES onboarding_invites(id),
 CONSTRAINT fk_rev_user FOREIGN KEY (revoked_by) REFERENCES users(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS platform_audit (
 id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
 actor_user_id BIGINT UNSIGNED NOT NULL,
 action_code VARCHAR(64) NOT NULL,
 org_id BIGINT UNSIGNED NULL,
 details TEXT NULL,
 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
 INDEX ix_audit_created(created_at),
 INDEX ix_audit_org(org_id),
 CONSTRAINT fk_audit_user FOREIGN KEY (actor_user_id) REFERENCES users(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
