-- Migration 064: Rename featureXTab to themeTab in all policy tables
-- The Android app now uses the canonical ID "themeTab" instead of the
-- legacy placeholder "featureXTab". Also renames the admin config key
-- from "feature_x_enabled" to "theme_enabled" (already correct in most
-- installs - UPDATE is a no-op if the key is already "theme_enabled").

UPDATE app_tabs
    SET tab_id = 'themeTab'
    WHERE tab_id = 'featureXTab';

UPDATE ftt_app_tabs
    SET tab_id = 'themeTab'
    WHERE tab_id = 'featureXTab';

UPDATE ftt_app_feature_policy
    SET tab_id = 'themeTab'
    WHERE tab_id = 'featureXTab';

UPDATE app_feature_policy
    SET tab_id = 'themeTab'
    WHERE tab_id = 'featureXTab';

UPDATE ftt_tab_section_policy
    SET tab_id = 'themeTab'
    WHERE tab_id = 'featureXTab';

UPDATE ftt_tab_feature_toggles
    SET tab_id = 'themeTab'
    WHERE tab_id = 'featureXTab';

-- Rename admin config key if still using the old placeholder name
UPDATE app_admin_config
    SET config_key = 'theme_enabled'
    WHERE config_key = 'feature_x_enabled';

UPDATE ftt_app_admin_config
    SET config_key = 'theme_enabled'
    WHERE config_key = 'feature_x_enabled';

-- Ensure canonical row exists
INSERT IGNORE INTO app_admin_config (config_key, config_value)
VALUES ('theme_enabled', '1');

INSERT IGNORE INTO ftt_app_admin_config (config_key, config_value)
VALUES ('theme_enabled', '1');
