fix: verify shadow SQL package ownership
This commit is contained in:
@@ -14,6 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ShadowSqlServerMigrationScriptTest {
|
||||
private static final Set<String> ALLOWED_INSTALL_OBJECTS = Set.of(
|
||||
"table alg.shadow_package_manifest",
|
||||
"table alg.warehouse_policy",
|
||||
"table alg.project_policy",
|
||||
"table alg.space_role",
|
||||
@@ -111,6 +112,36 @@ class ShadowSqlServerMigrationScriptTest {
|
||||
assertThat(normalize(resource("db/sqlserver/diagnostics-shadow.sql"))).contains(readUncommitted);
|
||||
}
|
||||
|
||||
@Test
|
||||
void installRefusesAnyExistingAlgorithmSchemaAndCreatesExactManifest() throws IOException {
|
||||
String install = normalize(resource("db/sqlserver/install-shadow.sql"));
|
||||
|
||||
assertThat(install).contains(
|
||||
"if schema_id(n'alg') is not null",
|
||||
"throw 51000",
|
||||
"create table alg.shadow_package_manifest",
|
||||
"ft546wms_shadow_only",
|
||||
"2026-08-12-1");
|
||||
assertThat(install.indexOf("throw 51000")).isLessThan(install.indexOf("create schema alg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void uninstallValidatesManifestAndObjectAllowListBeforeAnyDrop() throws IOException {
|
||||
String uninstall = normalize(resource("db/sqlserver/uninstall-shadow.sql"));
|
||||
int firstDrop = uninstall.indexOf("drop procedure");
|
||||
|
||||
assertThat(uninstall).contains(
|
||||
"ft546wms_shadow_only",
|
||||
"2026-08-12-1",
|
||||
"shadow package manifest does not match",
|
||||
"unknown object exists in alg schema",
|
||||
"object.parent_object_id = 0",
|
||||
"begin transaction",
|
||||
"rollback transaction");
|
||||
assertThat(uninstall.indexOf("shadow package manifest does not match")).isLessThan(firstDrop);
|
||||
assertThat(uninstall.indexOf("unknown object exists in alg schema")).isLessThan(firstDrop);
|
||||
}
|
||||
|
||||
private Set<String> createdObjects(String sql) {
|
||||
return objects(sql, Pattern.compile(
|
||||
"(?i)create\\s+(table|view|procedure|trigger)\\s+([a-z0-9_]+\\.[a-z0-9_]+)"));
|
||||
|
||||
Reference in New Issue
Block a user