use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.
the class AddColumnTest method testAddSingerToConcertsFromYaml.
@Test
void testAddSingerToConcertsFromYaml() throws Exception {
String[] expectedSql = new String[] { "ALTER TABLE Concerts ADD COLUMN SingerId INT64 NOT NULL", "ALTER TABLE Concerts ADD CONSTRAINT FK_Concerts_Singer FOREIGN KEY (SingerId) REFERENCES Singers (SingerId)" };
for (String sql : expectedSql) {
addUpdateDdlStatementsResponse(sql);
}
for (String file : new String[] { "add-singer-to-concerts-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]);
}
}
use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.
the class AddColumnTest method testAddSingerInfoToSingersFromYaml.
@Test
void testAddSingerInfoToSingersFromYaml() throws Exception {
// The following statement does not include the COLUMN keyword. According to the Cloud Spanner
// documentation the keyword is required, but the documentation is slightly off here. The COLUMN
// keyword is actually optional in Cloud Spanner (as in most other DBMS's).
String expectedSql = "ALTER TABLE Singers ADD COLUMN SingerInfo BYTES(MAX)";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "add-singerinfo-to-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 testAddFKAlbumsSingersFromYaml.
@Test
void testAddFKAlbumsSingersFromYaml() throws Exception {
String expectedSql = "ALTER TABLE Albums ADD CONSTRAINT FK_Albums_Singers FOREIGN KEY (SingerId) REFERENCES Singers (SingerId)";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "add-foreign-key-albums-singers.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 CreateIndexTest method testCreateNullFilteredIndexFromYaml.
@Test
void testCreateNullFilteredIndexFromYaml() throws Exception {
String expectedSql = "CREATE NULL_FILTERED INDEX Idx_Singers_FirstName ON Singers(FirstName)";
addUpdateDdlStatementsResponse(expectedSql);
for (String file : new String[] { "create-null-filtered-index-singers-first-name.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 CreateMultipleTablesTest method testCreateMultipleTablesFromYaml.
@Test
void testCreateMultipleTablesFromYaml() throws Exception {
String createSingers = "CREATE TABLE Singers (SingerId INT64, FirstName STRING(255), LastName STRING(255) NOT NULL, SingerInfo BYTES(MAX)) PRIMARY KEY (SingerId)";
String createAlbums = "CREATE TABLE Albums (AlbumId INT64, Title STRING(255), Singer INT64) PRIMARY KEY (AlbumId)";
addUpdateDdlStatementsResponse(Arrays.asList(createSingers, createAlbums));
for (String file : new String[] { "create-multiple-tables.spanner.yaml" }) {
try (Connection con = createConnection();
Liquibase liquibase = getLiquibase(con, file)) {
// Update to version v0.1.
liquibase.update(new Contexts("test"), new LabelExpression("version 0.1"));
// Register result for tagging the last update and then tag it.
mockSpanner.putStatementResult(StatementResult.update(Statement.of("UPDATE DATABASECHANGELOG SET TAG = 'rollback-v0.1' WHERE DATEEXECUTED = (SELECT MAX(DATEEXECUTED) FROM DATABASECHANGELOG)"), 1L));
liquibase.tag("rollback-v0.1");
}
}
assertThat(mockAdmin.getRequests()).hasSize(1);
assertThat(mockAdmin.getRequests().get(0)).isInstanceOf(UpdateDatabaseDdlRequest.class);
UpdateDatabaseDdlRequest request = (UpdateDatabaseDdlRequest) mockAdmin.getRequests().get(0);
assertThat(request.getStatementsList()).hasSize(2);
assertThat(request.getStatementsList().get(0)).isEqualTo(createSingers);
assertThat(request.getStatementsList().get(1)).isEqualTo(createAlbums);
}
Aggregations