package com.yau.digitalrmb.identity; import com.yau.digitalrmb.identity.infrastructure.persistence.PlatformUserSnapshotSchemaUpgrade; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @ActiveProfiles("test") class PlatformUserSnapshotSchemaUpgradeTest { @Autowired private JdbcTemplate jdbcTemplate; @Autowired private PlatformUserSnapshotSchemaUpgrade schemaUpgrade; @Test void restoresMissingProfileColumnWithPortableAlterStatement() { jdbcTemplate.execute("ALTER TABLE platform_user_snapshot DROP COLUMN student_id"); schemaUpgrade.ensureColumns(); Integer count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE LOWER(TABLE_NAME) = 'platform_user_snapshot' AND LOWER(COLUMN_NAME) = 'student_id'", Integer.class); assertThat(count).isEqualTo(1); } }