-- Align legacy tables with production: ensure core order/earnings tables use utf8mb4_general_ci.
-- Safe to run multiple times; already-general_ci tables will simply rebuild without data changes.

-- Some historical tables (e.g. sys_tenant_recharge_info) still rely on zero-datetime
-- defaults. MySQL 8 with NO_ZERO_DATE / NO_ZERO_IN_DATE rejects those definitions
-- when the engine rebuilds the table. Temporarily drop those sql_mode flags so the
-- table structure matches production before/after this migration.
SET @OLD_SQL_MODE = @@sql_mode;
SET SESSION sql_mode = REPLACE(REPLACE(@OLD_SQL_MODE, 'NO_ZERO_IN_DATE', ''), 'NO_ZERO_DATE', '');

ALTER TABLE `play_order_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_order_log_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_order_random_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_order_refund_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_order_continue_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_order_demand_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_order_evaluate_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_custom_user_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_custom_gift_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_custom_article_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_custom_follow_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_custom_leave_msg`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_custom_level_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_user_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_user_review_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_level_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_gift_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_classification_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_type_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_type_user_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_personnel_group_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_personnel_admin_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_personnel_waiter_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_coupon_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_coupon_details`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_gift_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_user`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_user_role`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_role`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_role_menu`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_role_dept`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_dept`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_menu`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_tenant`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_tenant_package`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_tenant_recharge_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `blind_box_config`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `blind_box_pool`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `blind_box_reward`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `commodity_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `gen_table`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `gen_table_column`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `order_details_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `order_log_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_account info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_avatar_frame_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_balance_details_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_article_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_commodity_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_data_review_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_operation_log`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_pk`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_ranking_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_resource info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_wages_details_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_wages_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_clerk_waiter_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `shop_ui_setting`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_administrative_area_dict_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_dict`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_dict_data`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_login_log`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `sys_operation_log`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;
ALTER TABLE `play_shop_article_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_shop_carousel_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_commodity_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_commodity_and_level_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_custom_amount details`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_notice_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

ALTER TABLE `play_order_complaint_info`
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_general_ci;

-- Restore original sql_mode flags once the rebuilds are done.
SET SESSION sql_mode = @OLD_SQL_MODE;
