SET @menu_permission_code_exists = (
    SELECT COUNT(1)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'menu'
      AND COLUMN_NAME = 'permission_code'
);
SET @add_menu_permission_code_sql = IF(
    @menu_permission_code_exists = 0,
    'ALTER TABLE menu ADD COLUMN permission_code VARCHAR(128) NULL AFTER route_path',
    'SELECT 1'
);
PREPARE stmt_add_menu_permission_code FROM @add_menu_permission_code_sql;
EXECUTE stmt_add_menu_permission_code;
DEALLOCATE PREPARE stmt_add_menu_permission_code;

UPDATE menu SET permission_code='project.create' WHERE tenant_id=1 AND route_path='/projects';
UPDATE menu SET permission_code='meeting.create' WHERE tenant_id=1 AND route_path='/meetings';
UPDATE menu SET permission_code='audit.approve' WHERE tenant_id=1 AND route_path='/audits';
UPDATE menu SET permission_code='finance.payment.confirm' WHERE tenant_id=1 AND route_path='/finance';
UPDATE menu SET permission_code='user.read' WHERE tenant_id=1 AND route_path='/users';
UPDATE menu SET permission_code='tenant.manage' WHERE tenant_id=1 AND route_path='/tenants';
UPDATE menu SET permission_code='tenant.manage' WHERE tenant_id=1 AND route_path='/enterprises';
UPDATE menu SET permission_code='role.read' WHERE tenant_id=1 AND route_path='/roles';
UPDATE menu SET permission_code='role.permission.bind' WHERE tenant_id=1 AND route_path='/menus';
UPDATE menu SET permission_code='audit.flow.read' WHERE tenant_id=1 AND route_path='/audit-flows';
UPDATE menu SET permission_code='data.permission.read' WHERE tenant_id=1 AND route_path='/data-permissions';
UPDATE menu SET permission_code='template.read' WHERE tenant_id=1 AND route_path='/templates';
UPDATE menu SET permission_code='template.read' WHERE tenant_id=1 AND route_path='/template-download-logs';
UPDATE menu SET permission_code='audit.log.read' WHERE tenant_id=1 AND route_path='/audit-logs';
UPDATE menu SET permission_code='expert.read' WHERE tenant_id=1 AND route_path='/experts';
UPDATE menu SET permission_code='meeting.field.read' WHERE tenant_id=1 AND route_path='/meeting-fields';
UPDATE menu SET permission_code='invoice.profile.read' WHERE tenant_id=1 AND route_path='/invoice-profiles';
UPDATE menu SET permission_code='notification.policy.read' WHERE tenant_id=1 AND route_path='/notification-policies';
UPDATE menu SET permission_code='export.task.read' WHERE tenant_id=1 AND route_path='/export-tasks';
UPDATE menu SET permission_code='observability.read' WHERE tenant_id=1 AND route_path='/observability';
UPDATE menu SET permission_code='dashboard.read' WHERE tenant_id=1 AND route_path='/operations-dashboard';
