-- 数据库初始化验证脚本
-- 在所有初始化脚本执行完成后运行

USE `anxin`;

-- 验证数据库字符集
SELECT 
    SCHEMA_NAME as 'Database',
    DEFAULT_CHARACTER_SET_NAME as 'Character Set',
    DEFAULT_COLLATION_NAME as 'Collation'
FROM information_schema.SCHEMATA 
WHERE SCHEMA_NAME = 'anxin';

-- 验证时区设置
SELECT @@global.time_zone as 'Global Timezone', @@session.time_zone as 'Session Timezone';

-- 验证用户权限
SELECT 
    User as 'Username',
    Host as 'Host',
    Select_priv as 'SELECT',
    Insert_priv as 'INSERT',
    Update_priv as 'UPDATE',
    Delete_priv as 'DELETE'
FROM mysql.user 
WHERE User IN ('anxin', 'root');

-- 验证数据库表数量
SELECT COUNT(*) as 'Total Tables' FROM information_schema.tables WHERE table_schema = 'anxin';

-- 验证关键表是否存在
SELECT 
    TABLE_NAME as 'Table Name',
    TABLE_ROWS as 'Row Count',
    CREATE_TIME as 'Created Time'
FROM information_schema.tables 
WHERE table_schema = 'anxin' 
    AND TABLE_NAME IN (
        'sys_user', 'sys_role', 'sys_menu', 'sys_dept',
        'dc_service_contract', 'dc_employee', 'dc_financing_application'
    )
ORDER BY TABLE_NAME;

-- 验证字符集配置
SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';

-- 显示初始化完成状态
SELECT 
    'Database initialization completed successfully' as Status,
    NOW() as CompletionTime,
    @@version as MySQLVersion;