use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.
the class DropIndexTest method testDropIndexSingersFirstNameWithTableNameFromYaml.
@Test
void testDropIndexSingersFirstNameWithTableNameFromYaml() throws Exception {
String expectedSql = "DROP INDEX Idx_Singers_FirstName";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "drop-singers-firstname-index-with-tablename.spanner.yaml" }) {
try (Connection con = createConnection();
Liquibase liquibase = getLiquibase(con, file)) {
liquibase.update(new Contexts("test"));
}
}
assertThat(mockAdmin.getRequests()).hasSize(1);
assertThat(mockAdmin.getRequests().get(0)).isInstanceOf(UpdateDatabaseDdlRequest.class);
UpdateDatabaseDdlRequest request = (UpdateDatabaseDdlRequest) mockAdmin.getRequests().get(0);
assertThat(request.getStatementsList()).hasSize(1);
assertThat(request.getStatementsList().get(0)).isEqualTo(expectedSql);
}
use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.
the class DropIndexTest method testDropIndexSingersLastNameFromYaml.
@Test
void testDropIndexSingersLastNameFromYaml() throws Exception {
String expectedSql = "DROP INDEX Idx_Singers_LastName";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "drop-singers-lastname-index.spanner.yaml" }) {
try (Connection con = createConnection();
Liquibase liquibase = getLiquibase(con, file)) {
liquibase.update(new Contexts("test"));
}
}
assertThat(mockAdmin.getRequests()).hasSize(1);
assertThat(mockAdmin.getRequests().get(0)).isInstanceOf(UpdateDatabaseDdlRequest.class);
UpdateDatabaseDdlRequest request = (UpdateDatabaseDdlRequest) mockAdmin.getRequests().get(0);
assertThat(request.getStatementsList()).hasSize(1);
assertThat(request.getStatementsList().get(0)).isEqualTo(expectedSql);
}
use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.
the class DropTableTest method testDropSingersTableFromYaml.
@Test
void testDropSingersTableFromYaml() throws Exception {
String expectedSql = "DROP TABLE Singers";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "drop-singers-table.spanner.yaml" }) {
try (Connection con = createConnection();
Liquibase liquibase = getLiquibase(con, file)) {
liquibase.update(new Contexts("test"));
}
}
assertThat(mockAdmin.getRequests()).hasSize(1);
assertThat(mockAdmin.getRequests().get(0)).isInstanceOf(UpdateDatabaseDdlRequest.class);
UpdateDatabaseDdlRequest request = (UpdateDatabaseDdlRequest) mockAdmin.getRequests().get(0);
assertThat(request.getStatementsList()).hasSize(1);
assertThat(request.getStatementsList().get(0)).isEqualTo(expectedSql);
}
use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.
the class AddForeignKeyTest method testAddFKSongsAlbumsFromYaml.
@Test
void testAddFKSongsAlbumsFromYaml() throws Exception {
String expectedSql = "ALTER TABLE Songs ADD CONSTRAINT FK_Songs_Albums FOREIGN KEY (SingerId, AlbumId) REFERENCES Albums (SingerId, AlbumId)";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "add-foreign-key-songs-albums.spanner.yaml" }) {
try (Connection con = createConnection();
Liquibase liquibase = getLiquibase(con, file)) {
liquibase.update(new Contexts("test"));
}
}
assertThat(mockAdmin.getRequests()).hasSize(1);
assertThat(mockAdmin.getRequests().get(0)).isInstanceOf(UpdateDatabaseDdlRequest.class);
UpdateDatabaseDdlRequest request = (UpdateDatabaseDdlRequest) mockAdmin.getRequests().get(0);
assertThat(request.getStatementsList()).hasSize(1);
assertThat(request.getStatementsList().get(0)).isEqualTo(expectedSql);
}
use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.
the class AddLookupTableTest method testAddLookupTableSingersCountriesFromYaml.
@Test
void testAddLookupTableSingersCountriesFromYaml() throws Exception {
String[] expectedSql = new String[] { "CREATE TABLE Countries (Name STRING(100) NOT NULL) PRIMARY KEY (Name)", "ALTER TABLE Singers ADD CONSTRAINT FK_Singers_Countries FOREIGN KEY (Country) REFERENCES Countries (Name)" };
for (String sql : expectedSql) {
addUpdateDdlStatementsResponse(sql);
}
final String insert = "INSERT INTO Countries (Name) SELECT DISTINCT Country FROM Singers WHERE Country IS NOT NULL";
mockSpanner.putStatementResult(StatementResult.update(Statement.of(insert), 100L));
for (String file : new String[] { "add-lookup-table-singers-countries.spanner.yaml" }) {
try (Connection con = createConnection();
Liquibase liquibase = getLiquibase(con, file)) {
liquibase.update(new Contexts("test"));
}
}
mockSpanner.waitForRequestsToContain(new Predicate<AbstractMessage>() {
@Override
public boolean apply(AbstractMessage input) {
if (input instanceof ExecuteSqlRequest) {
ExecuteSqlRequest request = (ExecuteSqlRequest) input;
return request.getSql().equals(insert);
}
return false;
}
}, 500L);
assertThat(mockAdmin.getRequests()).hasSize(expectedSql.length);
for (int i = 0; i < expectedSql.length; i++) {
assertThat(mockAdmin.getRequests().get(i)).isInstanceOf(UpdateDatabaseDdlRequest.class);
UpdateDatabaseDdlRequest request = (UpdateDatabaseDdlRequest) mockAdmin.getRequests().get(i);
assertThat(request.getStatementsList()).hasSize(1);
assertThat(request.getStatementsList().get(0)).isEqualTo(expectedSql[i]);
}
}
Aggregations