fix(education): validate adopted unique indexes

This commit is contained in:
2026-07-30 14:23:36 +08:00
parent 191811b643
commit 4be9c8147e
4 changed files with 72 additions and 10 deletions

View File

@@ -83,6 +83,31 @@ class EducationFlywayMigrationIntegrationTest {
.isEqualTo(1L);
}
@Test
void shouldFailClosedWhenAdoptedUniqueIndexHasWrongDefinition() throws SQLException {
String schema = createSchema("wrong_index");
createCompatibleManualPracticeFixture(schema);
execute(schema, """
CREATE TABLE education_favorite (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
tenant_id BIGINT NOT NULL, user_id BIGINT NOT NULL,
target_type VARCHAR(32) NOT NULL, target_id VARCHAR(64) NOT NULL,
creator VARCHAR(64) DEFAULT '', create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updater VARCHAR(64) DEFAULT '', update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted BOOLEAN NOT NULL DEFAULT false
);
CREATE INDEX uk_education_favorite_tenant_user_target
ON education_favorite (tenant_id, user_id, target_type, target_id);
""");
assertThatThrownBy(() -> configureFlyway(schema, true).load().migrate())
.hasMessageContaining("Practice unique index uk_education_favorite_tenant_user_target")
.hasMessageContaining("must be UNIQUE");
assertThat(queryLong(schema,
"SELECT COUNT(*) FROM flyway_schema_history WHERE version = '4060' AND success = TRUE"))
.isZero();
}
@Test
void shouldMigratePlatformSchemaFromBaseline4009() throws SQLException {
String schema = createSchema("baseline");
@@ -94,7 +119,7 @@ class EducationFlywayMigrationIntegrationTest {
assertThat(queryStrings(schema,
"SELECT COALESCE(version, 'BASELINE') FROM flyway_schema_history ORDER BY installed_rank"))
.containsExactly("4009", "4010", "4020", "4030", "4040", "4050");
.containsExactly("4009", "4010", "4020", "4030", "4040", "4050", "4060");
assertThat(queryLong(schema,
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = current_schema() " +
"AND table_name = 'education_idempotency'"))
@@ -156,7 +181,7 @@ class EducationFlywayMigrationIntegrationTest {
assertThat(queryStrings(schema,
"SELECT version FROM flyway_schema_history WHERE success = TRUE ORDER BY installed_rank"))
.containsExactly("4010", "4020", "4030", "4040", "4050");
.containsExactly("4010", "4020", "4030", "4040", "4050", "4060");
assertThat(queryStrings(schema,
"SELECT table_name FROM information_schema.tables " +
"WHERE table_schema = current_schema() AND table_name IN (" +