-- Migration: rename user prompt config table and adjust prompt_config menu URL
-- Created at: 2026-03-13

BEGIN;

SET @rename_sql = (
  SELECT IF(
    EXISTS (
      SELECT 1 FROM information_schema.tables
      WHERE table_schema = DATABASE()
        AND table_name = 'sys_user_prompt_config'
        AND table_type = 'BASE TABLE'
    ) AND NOT EXISTS (
      SELECT 1 FROM information_schema.tables
      WHERE table_schema = DATABASE()
        AND table_name = 'prompt_config'
        AND table_type = 'BASE TABLE'
    ),
    'RENAME TABLE sys_user_prompt_config TO prompt_config',
    'SELECT 1'
  )
);
PREPARE stmt FROM @rename_sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

UPDATE sys_menus
SET menu_url = '/prompt-config'
WHERE menu_code = 'prompt_config';

COMMIT;
