package com.ruoyi.ccdi.project.sql;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CcdiAccountInfoMergeSqlTest {

    @Test
    void accountInfoMergeSql_shouldAddColumnsMigrateDataAndDropLegacyTable() throws IOException {
        Path path = Path.of("..", "sql", "migration",
            "2026-04-16-merge-ccdi-account-result-into-info.sql");

        assertTrue(Files.exists(path), "账户库合表迁移脚本应存在");

        String sql = Files.readString(path, StandardCharsets.UTF_8).toLowerCase();
        assertAll(
            () -> assertTrue(sql.contains("bin/mysql_utf8_exec.sh")),
            () -> assertTrue(sql.contains("ccdi_account_info")),
            () -> assertTrue(sql.contains("add column `is_self_account`")),
            () -> assertTrue(sql.contains("monthly_avg_trans_count")),
            () -> assertTrue(sql.contains("update `ccdi_account_info` ai")),
            () -> assertTrue(sql.contains("join `ccdi_account_result` ar")),
            () -> assertTrue(sql.contains("drop table `ccdi_account_result`"))
        );
    }
}
