use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.
the class ModifyDataTypeTest method testModifySingersLastNameToLongerStringFromYaml.
@Test
void testModifySingersLastNameToLongerStringFromYaml() throws Exception {
String expectedSql = "ALTER TABLE Singers ALTER COLUMN LastName STRING(1000) NOT NULL";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "modify-data-type-singers-lastname.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 ModifyDataTypeTest method testModifySingersSingerInfoToStringFromYaml.
@Test
void testModifySingersSingerInfoToStringFromYaml() throws Exception {
String expectedSql = "ALTER TABLE Singers ALTER COLUMN SingerInfo STRING(MAX)";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "modify-data-type-singers-singerinfo.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 SetNullableConstraintTest method testDropSingersLastNameNotNullFromYaml.
@Test
void testDropSingersLastNameNotNullFromYaml() throws Exception {
// Dropping a NOT NULL constraint in Cloud Spanner is done by not adding the NOT NULL constraint
// at the end of the column definition.
String expectedSql = "ALTER TABLE Singers ALTER COLUMN LastName STRING(100)";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "drop-not-null-constraint-singers-lastname.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 SetNullableConstraintTest method testAddSingersLastNameNotNullFromYaml.
@Test
void testAddSingersLastNameNotNullFromYaml() throws Exception {
String expectedSql = "ALTER TABLE Singers ALTER COLUMN LastName STRING(100) NOT NULL";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "add-not-null-constraint-singers-lastname.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 AddColumnTest method testAddTrackAndLyricsToSongsFromYaml.
@Test
void testAddTrackAndLyricsToSongsFromYaml() throws Exception {
String[] expectedSql = new String[] { "ALTER TABLE Songs ADD COLUMN Track INT64 NOT NULL", "ALTER TABLE Songs ADD COLUMN Lyrics STRING(MAX)" };
for (String sql : expectedSql) {
addUpdateDdlStatementsResponse(sql);
}
for (String file : new String[] { "add-track-and-lyrics-to-songs-table.spanner.yaml" }) {
try (Connection con = createConnection();
Liquibase liquibase = getLiquibase(con, file)) {
liquibase.update(new Contexts("test"));
}
}
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