Search in sources :

Example 26 with UpdateDatabaseDdlRequest

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);
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) Contexts(liquibase.Contexts) UpdateDatabaseDdlRequest(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest) Test(org.junit.jupiter.api.Test)

Example 27 with UpdateDatabaseDdlRequest

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);
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) Contexts(liquibase.Contexts) UpdateDatabaseDdlRequest(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest) Test(org.junit.jupiter.api.Test)

Example 28 with UpdateDatabaseDdlRequest

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);
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) Contexts(liquibase.Contexts) UpdateDatabaseDdlRequest(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest) Test(org.junit.jupiter.api.Test)

Example 29 with UpdateDatabaseDdlRequest

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);
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) Contexts(liquibase.Contexts) UpdateDatabaseDdlRequest(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest) Test(org.junit.jupiter.api.Test)

Example 30 with UpdateDatabaseDdlRequest

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]);
    }
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) Contexts(liquibase.Contexts) UpdateDatabaseDdlRequest(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateDatabaseDdlRequest (com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest)39 Connection (java.sql.Connection)35 Contexts (liquibase.Contexts)29 Liquibase (liquibase.Liquibase)29 Test (org.junit.jupiter.api.Test)29 Test (org.junit.Test)9 Statement (java.sql.Statement)5 AbstractMessage (com.google.protobuf.AbstractMessage)4 Empty (com.google.protobuf.Empty)4 BeginTransactionRequest (com.google.spanner.v1.BeginTransactionRequest)4 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)4 IntermediateStatement (com.google.cloud.spanner.pgadapter.statements.IntermediateStatement)3 Operation (com.google.longrunning.Operation)3 UpdateDatabaseDdlMetadata (com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata)3 ResultSet (java.sql.ResultSet)3 LabelExpression (liquibase.LabelExpression)3 AbstractMockServerTest (liquibase.ext.spanner.AbstractMockServerTest)3 SpannerException (com.google.cloud.spanner.SpannerException)2 ByteString (com.google.protobuf.ByteString)2 CommitRequest (com.google.spanner.v1.CommitRequest)2