package com.battery.business.runtime; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.InputStream; import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; /** Ticket08 三类测试数据持久化结构契约。 */ class TestDataPersistenceMigrationContractTest { @Test void stepAndCycleRecordsKeepBindingReceptionTimeAndStableDedupeKey() { String sql = resource("db/migration-final/V3__test_data_persistence.sql"); assertTrue(sql.contains("ALTER TABLE t_test_realtime_record")); assertTrue(sql.contains("source_identity VARCHAR(256) NOT NULL")); assertTrue(sql.contains("source_record_id VARCHAR(128) NULL")); assertTrue(sql.contains("ALTER TABLE t_test_step_record")); assertTrue(sql.contains("ALTER TABLE t_test_cycle_record")); assertTrue(sql.contains("binding_id BIGINT NOT NULL")); assertTrue(sql.contains("server_received_at_utc DATETIME(3) NOT NULL")); assertTrue(sql.contains("dedupe_key VARCHAR(512) NOT NULL")); assertTrue(sql.contains("UNIQUE KEY uk_step_dedupe")); assertTrue(sql.contains("UNIQUE KEY uk_cycle_dedupe")); } private static String resource(String path) { try (InputStream stream = TestDataPersistenceMigrationContractTest.class.getClassLoader() .getResourceAsStream(path)) { if (stream == null) throw new AssertionError("缺少资源 " + path); return new String(stream.readAllBytes(), StandardCharsets.UTF_8); } catch (Exception exception) { throw new AssertionError("无法读取资源 " + path, exception); } } }