Search in sources :

Example 11 with UpdateDatabaseDdlRequest

use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.

the class CreateIndexTest method testCreateSingersFirstNameIndexFromYaml.

@Test
void testCreateSingersFirstNameIndexFromYaml() throws Exception {
    String expectedSql = "CREATE INDEX Idx_Singers_FirstName ON Singers(FirstName DESC)";
    addUpdateDdlStatementsResponse(expectedSql);
    for (String file : new String[] { "create-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);
}
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 12 with UpdateDatabaseDdlRequest

use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.

the class CreateIndexTest method testCreateSingersFirstAndLastNameIndexFromYaml.

@Test
void testCreateSingersFirstAndLastNameIndexFromYaml() throws Exception {
    String expectedSql = "CREATE UNIQUE INDEX Idx_Singers_FirstAndLastName ON Singers(FirstName DESC, LastName)";
    addUpdateDdlStatementsResponse(expectedSql);
    for (String file : new String[] { "create-index-singers-first-and-last-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);
}
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 13 with UpdateDatabaseDdlRequest

use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.

the class CreateIndexTest method testCreateSingersLastNameIndexFromYaml.

@Test
void testCreateSingersLastNameIndexFromYaml() throws Exception {
    String expectedSql = "CREATE INDEX Idx_Singers_LastName ON Singers(LastName)";
    addUpdateDdlStatementsResponse(expectedSql);
    for (String file : new String[] { "create-index-singers-last-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);
}
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 14 with UpdateDatabaseDdlRequest

use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.

the class CreateTableTest method testCreateTableWithAllLiquibaseTypesFromYaml.

@Test
void testCreateTableWithAllLiquibaseTypesFromYaml() throws Exception {
    String expectedSql = "CREATE TABLE TableWithAllLiquibaseTypes (ColBigInt INT64 NOT NULL, ColBlob BYTES(MAX), ColBoolean BOOL, ColChar STRING(100), ColNChar STRING(50), ColNVarchar STRING(100), ColVarchar STRING(200), ColClob STRING(MAX), ColDateTime TIMESTAMP, ColTimestamp timestamp, ColDate date, ColDecimal NUMERIC, ColDouble FLOAT64, ColFloat FLOAT64, ColInt INT64, ColMediumInt INT64, ColNumber NUMERIC, ColSmallInt INT64, ColTime TIMESTAMP, ColTinyInt INT64, ColUUID STRING(36), ColXml STRING(MAX), ColBoolArray ARRAY<BOOL>, ColBytesArray ARRAY<BYTES(100)>, ColBytesMaxArray ARRAY<BYTES(MAX)>, ColDateArray ARRAY<DATE>, ColFloat64Array ARRAY<FLOAT64>, ColInt64Array ARRAY<INT64>, ColNumericArray ARRAY<NUMERIC>, ColStringArray ARRAY<STRING(100)>, ColStringMaxArray ARRAY<STRING(MAX)>, ColTimestampArray ARRAY<TIMESTAMP>) PRIMARY KEY (ColBigInt)";
    addUpdateDdlStatementsResponse(expectedSql);
    for (String file : new String[] { "create-table-with-all-liquibase-types.spanner.yaml" }) {
        try (Connection con = createConnection();
            Liquibase liquibase = getLiquibase(con, file)) {
            liquibase.update(new Contexts("test"), new LabelExpression("version 0.3"));
        }
    }
    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) LabelExpression(liquibase.LabelExpression) Contexts(liquibase.Contexts) UpdateDatabaseDdlRequest(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest) Test(org.junit.jupiter.api.Test)

Example 15 with UpdateDatabaseDdlRequest

use of com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest in project liquibase-spanner by cloudspannerecosystem.

the class CreateDropViewTest method testDropViewFromYaml.

@Test
void testDropViewFromYaml() throws Exception {
    String expectedSql = "DROP VIEW V_Singers";
    addUpdateDdlStatementsResponse(expectedSql);
    for (String file : new String[] { "drop-view.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) AbstractMockServerTest(liquibase.ext.spanner.AbstractMockServerTest)

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