From e5e652cd5ff4d86dcfff34d181cf6f83375f2aa8 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 25 Apr 2024 14:46:58 +0300 Subject: [PATCH 01/32] Update junit version to 5 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a7c33b3f..91871526 100644 --- a/pom.xml +++ b/pom.xml @@ -52,10 +52,10 @@ - junit - junit + org.junit.jupiter + junit-jupiter + 5.10.2 test - 4.13.2 com.simba.googlebigquery.jdbc From 057d603eed19a86714d2c29503e6687995cf630e Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 25 Apr 2024 14:47:25 +0300 Subject: [PATCH 02/32] Add sqlgenerator unit tests --- .../BigQueryAddColumnGeneratorTest.java | 30 ++++++++++ ...yAddForeignKeyConstraintGeneratorTest.java | 41 +++++++++++++ ...yAddPrimaryKeyConstraintGeneratorTest.java | 37 ++++++++++++ .../BigQueryCreateTableGeneratorTest.java | 32 ++++++++++ ...DropForeignKeyConstraintGeneratorTest.java | 32 ++++++++++ ...DropPrimaryKeyConstraintGeneratorTest.java | 32 ++++++++++ .../BigQueryInsertOrUpdateGeneratorTest.java | 58 +++++++++++++++++++ .../BigQueryModifyDataTypeGeneratorTest.java | 32 ++++++++++ .../BigQueryRenameTableGeneratorTest.java | 32 ++++++++++ .../BigQueryRenameViewGeneratorTest.java | 32 ++++++++++ .../BigQuerySetNullableGeneratorTest.java | 30 ++++++++++ .../BigQueryUpdateGeneratorTest.java | 32 ++++++++++ ...tabaseChangeLogLockTableGeneratorTest.java | 32 ++++++++++ .../BigqueryDeleteGeneratorTest.java | 32 ++++++++++ 14 files changed, 484 insertions(+) create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java new file mode 100644 index 00000000..3f44a557 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java @@ -0,0 +1,30 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.AddColumnStatement; +import liquibase.statement.core.RenameTableStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQueryAddColumnGeneratorTest { + + private BigQueryAddColumnGenerator generator; + private BigqueryDatabase database; + private AddColumnStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryAddColumnGenerator(); + statement = new AddColumnStatement(); + } + + @Test + void generateSingleColumnSQL() { + String sql = generator.generateSingleColumnSQL(statement, database); + assertEquals(" ADD COLUMN null", sql); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java new file mode 100644 index 00000000..591e98e6 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java @@ -0,0 +1,41 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.change.ColumnConfig; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.AddForeignKeyConstraintStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class BigQueryAddForeignKeyConstraintGeneratorTest { + + private BigQueryAddForeignKeyConstraintGenerator generator; + private BigqueryDatabase database; + private AddForeignKeyConstraintStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryAddForeignKeyConstraintGenerator(); + statement = new AddForeignKeyConstraintStatement( + "constraintName", + "baseTableCatalogName", + "baseTableSchemaName", + "baseTableName", + new ColumnConfig[]{new ColumnConfig()}, + "referencedTableCatalogName", + "referencedTableSchemaName", + "referencedTableName", + new ColumnConfig[]{new ColumnConfig()}); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("SELECT 1", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java new file mode 100644 index 00000000..8b042f5b --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java @@ -0,0 +1,37 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.change.ColumnConfig; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.AddPrimaryKeyStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class BigQueryAddPrimaryKeyConstraintGeneratorTest { + + private BigQueryAddPrimaryKeyConstraintGenerator generator; + private BigqueryDatabase database; + private AddPrimaryKeyStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryAddPrimaryKeyConstraintGenerator(); + statement = new AddPrimaryKeyStatement( + "catalogName", + "schemaName", + "tableName", + new ColumnConfig[]{new ColumnConfig()}, + "constraintName"); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("SELECT 1", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java new file mode 100644 index 00000000..840e4008 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.CreateTableStatement; +import liquibase.statement.core.RenameTableStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQueryCreateTableGeneratorTest { + + private BigQueryCreateTableGenerator generator; + private BigqueryDatabase database; + private CreateTableStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryCreateTableGenerator(); + statement = new CreateTableStatement("catalog", "schema", "table"); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("CREATE TABLE schema.table ()", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGeneratorTest.java new file mode 100644 index 00000000..dd1b9980 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.DropForeignKeyConstraintStatement; +import liquibase.statement.core.RenameTableStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQueryDropForeignKeyConstraintGeneratorTest { + + private BigQueryDropForeignKeyConstraintGenerator generator; + private BigqueryDatabase database; + private DropForeignKeyConstraintStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryDropForeignKeyConstraintGenerator(); + statement = new DropForeignKeyConstraintStatement(null, null, null, null); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("SELECT 1", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGeneratorTest.java new file mode 100644 index 00000000..63963b8e --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.DropPrimaryKeyStatement; +import liquibase.statement.core.RenameTableStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQueryDropPrimaryKeyConstraintGeneratorTest { + + private BigQueryDropPrimaryKeyConstraintGenerator generator; + private BigqueryDatabase database; + private DropPrimaryKeyStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryDropPrimaryKeyConstraintGenerator(); + statement = new DropPrimaryKeyStatement("catalogName", "schemaName", "tableName", "columnName"); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("SELECT 1", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java new file mode 100644 index 00000000..07791396 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java @@ -0,0 +1,58 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.change.ColumnConfig; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.statement.core.InsertOrUpdateStatement; +import liquibase.statement.core.InsertStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class BigQueryInsertOrUpdateGeneratorTest { + + private BigQueryInsertOrUpdateGenerator generator; + private BigqueryDatabase database; + private InsertOrUpdateStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryInsertOrUpdateGenerator(); + statement = new InsertOrUpdateStatement("catalog", "schema", "table", "column", false); + ColumnConfig columnConfig = new ColumnConfig(); + columnConfig.setName("columnName"); + columnConfig.setType("columnType"); + columnConfig.setValueBoolean("valueBoolean"); + statement.addColumn(columnConfig); + } + + @Test + void getInsertStatement() { + String insertStatement = generator.getInsertStatement(statement, database, null); + assertNotNull(insertStatement); + assertEquals("INSERT (columnName) VALUES (valueBoolean)", insertStatement); + } + + @Test + void getUpdateStatement() { + String updateStatement = generator.getUpdateStatement(statement, database, "", null); + assertNotNull(updateStatement); + assertEquals("UPDATE SET columnName = valueBoolean", updateStatement); + } + + @Test + void getRecordEmptyCheck() { + String recordCheck = generator.getRecordCheck(statement, database, null); + assertNotNull(recordCheck); + assertEquals("MERGE INTO table USING (SELECT 1) ON WHERE 1 = 1 WHEN NOT MATCHED THEN ", recordCheck); + } + + @Test + void getRecordWhereCheck() { + String recordCheck = generator.getRecordCheck(statement, database, "WHERE ID = 1"); + assertNotNull(recordCheck); + assertEquals("MERGE INTO table USING (SELECT 1) ON WHERE ID = 1 WHEN NOT MATCHED THEN ", recordCheck); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java new file mode 100644 index 00000000..b791bc7f --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.ModifyDataTypeStatement; +import liquibase.statement.core.RenameTableStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQueryModifyDataTypeGeneratorTest { + + private BigQueryModifyDataTypeGenerator generator; + private BigqueryDatabase database; + private ModifyDataTypeStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryModifyDataTypeGenerator(); + statement = new ModifyDataTypeStatement("catalogName", "schemaName", "tableName", "columnName", "newDataType"); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("ALTER TABLE schemaName.tableName ALTER COLUMN columnName SET DATA TYPE NEWDATATYPE", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java new file mode 100644 index 00000000..24c7971b --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.RenameTableStatement; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQueryRenameTableGeneratorTest { + + private BigQueryRenameTableGenerator generator; + private BigqueryDatabase database; + private RenameTableStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryRenameTableGenerator(); + statement = new RenameTableStatement("catalogName", "schemaName", "oldTableName", "newTableName"); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("ALTER TABLE schemaName.oldTableName RENAME TO newTableName", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java new file mode 100644 index 00000000..e0c5ed1a --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.RenameTableStatement; +import liquibase.statement.core.RenameViewStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQueryRenameViewGeneratorTest { + + private BigQueryRenameViewGenerator generator; + private BigqueryDatabase database; + private RenameViewStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryRenameViewGenerator(); + statement = new RenameViewStatement("catalogName", "schemaName", "oldTableName", "newTableName"); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("ALTER VIEW schemaName.oldTableName RENAME TO schemaName.newTableName", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java new file mode 100644 index 00000000..9419ed41 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java @@ -0,0 +1,30 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.RenameTableStatement; +import liquibase.statement.core.SetNullableStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQuerySetNullableGeneratorTest { + + private BigQuerySetNullableGenerator generator; + private BigqueryDatabase database; + private SetNullableStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQuerySetNullableGenerator(); + statement = new SetNullableStatement("catalogName", "schemaName", "tableName", "columnName", "columnDataType", false); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(0, sql.length); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java new file mode 100644 index 00000000..d96a2de5 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.RenameTableStatement; +import liquibase.statement.core.UpdateStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigQueryUpdateGeneratorTest { + + private BigQueryUpdateGenerator generator; + private BigqueryDatabase database; + private UpdateStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigQueryUpdateGenerator(); + statement = new UpdateStatement("catalogName", "schemaName", "tableName"); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("UPDATE schemaName.tableName SET WHERE 1 = 1", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java new file mode 100644 index 00000000..cb7aab83 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.CreateDatabaseChangeLogLockTableStatement; +import liquibase.statement.core.RenameTableStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigqueryCreateDatabaseChangeLogLockTableGeneratorTest { + + private BigqueryCreateDatabaseChangeLogLockTableGenerator generator; + private BigqueryDatabase database; + private CreateDatabaseChangeLogLockTableStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigqueryCreateDatabaseChangeLogLockTableGenerator(); + statement = new CreateDatabaseChangeLogLockTableStatement(); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("CREATE TABLE DATABASECHANGELOGLOCK (ID INT, LOCKED BOOLEAN, LOCKGRANTED datetime, LOCKEDBY STRING(255))", sql[0].toSql()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java new file mode 100644 index 00000000..4023bc4d --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java @@ -0,0 +1,32 @@ +package liquibase.ext.bigquery.sqlgenerator; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.sql.Sql; +import liquibase.statement.core.DeleteStatement; +import liquibase.statement.core.RenameTableStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigqueryDeleteGeneratorTest { + + private BigqueryDeleteGenerator generator; + private BigqueryDatabase database; + private DeleteStatement statement; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + generator = new BigqueryDeleteGenerator(); + statement = new DeleteStatement("catalog", "schema", "table"); + } + + @Test + void generateSql() { + Sql[] sql = generator.generateSql(statement, database, null); + assertEquals(1, sql.length); + assertEquals(";", sql[0].getEndDelimiter()); + assertEquals("DELETE FROM schema.table WHERE 1 = 1", sql[0].toSql()); + } +} \ No newline at end of file From b1c9e66553ed577b80679a81dc923c00a7745c35 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 25 Apr 2024 15:53:41 +0300 Subject: [PATCH 03/32] Add change unit test --- .../change/BigQueryMergeColumnChangeTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java diff --git a/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java b/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java new file mode 100644 index 00000000..94b6b00e --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java @@ -0,0 +1,57 @@ +package liquibase.ext.bigquery.change; + +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.statement.SqlStatement; +import liquibase.statement.core.AddColumnStatement; +import liquibase.statement.core.DropColumnStatement; +import liquibase.statement.core.RawSqlStatement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +class BigQueryMergeColumnChangeTest { + + private BigqueryDatabase database; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + } + + @Test + void generateStatements() { + BigQueryMergeColumnChange change = new BigQueryMergeColumnChange(); + change.setTableName("tableName"); + change.setColumn1Name("column1Name"); + change.setColumn2Name("column2Name"); + change.setSchemaName("schemaName"); + change.setCatalogName("catalogName"); + change.setFinalColumnName("finalColumnName"); + change.setFinalColumnType("finalColumnName"); + change.setJoinString("joinString"); + + SqlStatement[] sqlStatements = change.generateStatements(database); + assertEquals(4, sqlStatements.length); + assertInstanceOf(AddColumnStatement.class, sqlStatements[0]); + assertInstanceOf(RawSqlStatement.class, sqlStatements[1]); + assertInstanceOf(DropColumnStatement.class, sqlStatements[2]); + assertInstanceOf(DropColumnStatement.class, sqlStatements[3]); + + AddColumnStatement addColumnStatement = (AddColumnStatement) sqlStatements[0]; + assertEquals("finalColumnName", addColumnStatement.getColumnName()); + assertEquals("finalColumnName", addColumnStatement.getColumnType()); + + RawSqlStatement rawSqlStatement = (RawSqlStatement) sqlStatements[1]; + assertEquals("UPDATE schemaName.tableName SET finalColumnName = column1Name || 'joinString' || column2Name WHERE 1 = 1 ", rawSqlStatement.getSql()); + + DropColumnStatement drop1ColumnStatement = (DropColumnStatement) sqlStatements[2]; + assertEquals("column1Name", drop1ColumnStatement.getColumnName()); + + DropColumnStatement drop2ColumnStatement = (DropColumnStatement) sqlStatements[3]; + assertEquals("column2Name", drop2ColumnStatement.getColumnName()); + + + } +} \ No newline at end of file From ed01eec84a59ce9c59d89d771bce3d1e306c06cb Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 25 Apr 2024 16:44:11 +0300 Subject: [PATCH 04/32] Add lombok dependency --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 91871526..70de70b1 100644 --- a/pom.xml +++ b/pom.xml @@ -91,6 +91,10 @@ 1.5.1 test + + org.projectlombok + lombok + From f9890bebd8e3e2c9f86b85b2c0fceab78ed66169 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 25 Apr 2024 16:44:37 +0300 Subject: [PATCH 05/32] Add database unit tests --- .../database/BigqueryDatabaseUnitTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java diff --git a/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java b/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java new file mode 100644 index 00000000..d0311907 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java @@ -0,0 +1,48 @@ +package liquibase.ext.bigquery.database; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class BigqueryDatabaseUnitTest { + + private BigqueryDatabase database; + + @BeforeEach + void setUp() { + database = new BigqueryDatabase(); + } + + @Test + void getShortName() { + assertEquals("bigquery", database.getShortName()); + } + + @Test + void getDefaultDatabaseProductName() { + assertEquals("Google BigQuery", database.getDefaultDatabaseProductName()); + } + + @Test + void supportsDatabaseChangeLogHistory() { + assertTrue(database.supportsDatabaseChangeLogHistory()); + } + + @Test + void getCurrentDateTimeFunction() { + assertEquals("CURRENT_DATETIME()", database.getCurrentDateTimeFunction()); + } + + @Test + void getQuotingStartCharacter() { + assertEquals("`", database.getQuotingStartCharacter()); + } + + @Test + void getQuotingEndCharacter() { + assertEquals("`", database.getQuotingEndCharacter()); + } + +} \ No newline at end of file From 8b84b842ca871213105ad5eb235f65afd6f9c2e5 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Fri, 26 Apr 2024 14:30:30 +0300 Subject: [PATCH 06/32] Add data type unit tests --- .../core/BignumericDataTypeBigQueryTest.java | 19 +++++++++++ .../core/BoolDataTypeBigQueryTest.java | 19 +++++++++++ .../core/Float64DataTypeBigQueryTest.java | 19 +++++++++++ .../core/GeographyDataTypeBigQueryTest.java | 18 ++++++++++ .../core/Int64DataTypeBigQueryTest.java | 19 +++++++++++ .../core/NumberDataTypeBigQueryTest.java | 19 +++++++++++ .../core/StringDataTypeBigQueryTest.java | 33 +++++++++++++++++++ 7 files changed, 146 insertions(+) create mode 100644 src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java create mode 100644 src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java new file mode 100644 index 00000000..b6f8ed36 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java @@ -0,0 +1,19 @@ +package liquibase.ext.bigquery.datatype.core; + +import liquibase.datatype.DatabaseDataType; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class BignumericDataTypeBigQueryTest { + + @Test + void toDatabaseDataType() { + BignumericDataTypeBigQuery bignumericDataTypeBigQuery = new BignumericDataTypeBigQuery(); + DatabaseDataType databaseDataType = bignumericDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + assertNotNull(databaseDataType); + assertEquals("BIGNUMERIC", databaseDataType.getType()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java new file mode 100644 index 00000000..b076bd7a --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java @@ -0,0 +1,19 @@ +package liquibase.ext.bigquery.datatype.core; + +import liquibase.datatype.DatabaseDataType; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class BoolDataTypeBigQueryTest { + + @Test + void toDatabaseDataType() { + BoolDataTypeBigQuery boolDataTypeBigQuery = new BoolDataTypeBigQuery(); + DatabaseDataType databaseDataType = boolDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + assertNotNull(databaseDataType); + assertEquals("BOOL", databaseDataType.getType()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java new file mode 100644 index 00000000..7d0ca204 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java @@ -0,0 +1,19 @@ +package liquibase.ext.bigquery.datatype.core; + +import liquibase.datatype.DatabaseDataType; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class Float64DataTypeBigQueryTest { + + @Test + void toDatabaseDataType() { + Float64DataTypeBigQuery float64DataTypeBigQuery = new Float64DataTypeBigQuery(); + DatabaseDataType databaseDataType = float64DataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + assertNotNull(databaseDataType); + assertEquals("FLOAT64", databaseDataType.getType()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java new file mode 100644 index 00000000..31afa2f0 --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java @@ -0,0 +1,18 @@ +package liquibase.ext.bigquery.datatype.core; + +import liquibase.datatype.DatabaseDataType; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class GeographyDataTypeBigQueryTest { + + @Test + void toDatabaseDataType() { + GeographyDataTypeBigQuery datatype = new GeographyDataTypeBigQuery(); + DatabaseDataType databaseDataType = datatype.toDatabaseDataType(new BigqueryDatabase()); + assertEquals("GEOGRAPHY", databaseDataType.getType()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java new file mode 100644 index 00000000..7c46bb1e --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java @@ -0,0 +1,19 @@ +package liquibase.ext.bigquery.datatype.core; + +import liquibase.datatype.DatabaseDataType; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class Int64DataTypeBigQueryTest { + + @Test + void toDatabaseDataType() { + Int64DataTypeBigQuery int64DataTypeBigQuery = new Int64DataTypeBigQuery(); + DatabaseDataType databaseDataType = int64DataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + assertNotNull(databaseDataType); + assertEquals("INT64", databaseDataType.getType()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java new file mode 100644 index 00000000..1e5db85b --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java @@ -0,0 +1,19 @@ +package liquibase.ext.bigquery.datatype.core; + +import liquibase.datatype.DatabaseDataType; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class NumberDataTypeBigQueryTest { + + @Test + void toDatabaseDataType() { + NumberDataTypeBigQuery numberDataTypeBigQuery = new NumberDataTypeBigQuery(); + DatabaseDataType databaseDataType = numberDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + assertNotNull(databaseDataType); + assertEquals("NUMERIC", databaseDataType.getType()); + } +} \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java new file mode 100644 index 00000000..d2c8855e --- /dev/null +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java @@ -0,0 +1,33 @@ +package liquibase.ext.bigquery.datatype.core; + +import liquibase.datatype.DatabaseDataType; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class StringDataTypeBigQueryTest { + + @Test + void toDatabaseDataType() { + StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); + DatabaseDataType databaseDataType = stringDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + assertNotNull(databaseDataType); + assertEquals("STRING", databaseDataType.getType()); + } + + @Test + void objectToSql() { + StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); + String sql = stringDataTypeBigQuery.objectToSql("TEST", new BigqueryDatabase()); + assertEquals("'TEST'", sql); + } + + @Test + void objectToSqlNewLineCharacter() { + StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); + String sql = stringDataTypeBigQuery.objectToSql("TEST\n NEW LINE", new BigqueryDatabase()); + assertEquals("'''TEST\n NEW LINE'''", sql); + } +} \ No newline at end of file From d4083e0939a7edd660bdd8793e04d589074262de Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Wed, 29 May 2024 12:18:48 +0300 Subject: [PATCH 07/32] Fix FOSSA build --- .github/workflows/fossa_ai.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fossa_ai.yml b/.github/workflows/fossa_ai.yml index df1aa222..a3318a0c 100644 --- a/.github/workflows/fossa_ai.yml +++ b/.github/workflows/fossa_ai.yml @@ -1,14 +1,22 @@ name: FOSSA License Compliance and Security Check on: - pull_request: + workflow_dispatch: + pull_request_target: types: - opened - reopened - synchronize jobs: + authorize: + environment: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }} + runs-on: ubuntu-latest + steps: + - run: true + fossa: + needs: authorize uses: liquibase/build-logic/.github/workflows/fossa_ai.yml@main secrets: inherit with: From 3cdcc2187386723ffb5d5a185e814609585cfaac Mon Sep 17 00:00:00 2001 From: KushnirykOleh Date: Mon, 13 May 2024 20:30:32 +0300 Subject: [PATCH 08/32] fixed FK --- .../BigQueryForeignKeySnapshotGenerator.java | 126 ++++++++++++++++++ ...ueryUniqueConstraintSnapshotGenerator.java | 2 +- ...QueryAddForeignKeyConstraintGenerator.java | 18 ++- ...ueryDropForeignKeyConstraintGenerator.java | 32 ----- .../liquibase.snapshot.SnapshotGenerator | 1 + .../liquibase.sqlgenerator.SqlGenerator | 1 - .../changelogs/bigquery/addForeignKey.xml | 20 +++ .../changelogs/bigquery/dropForeignKey.xml | 19 +++ .../bigquery/addForeignKey.json | 13 ++ .../bigquery/dropForeignKey.json | 14 ++ .../expectedSql/bigquery/addForeignKey.sql | 2 +- .../expectedSql/bigquery/addPrimaryKey.sql | 1 - .../expectedSql/bigquery/dropForeignKey.sql | 3 +- .../expectedSql/bigquery/dropPrimaryKey.sql | 1 - .../expectedSql/bigquery/renameTrigger.sql | 2 +- 15 files changed, 214 insertions(+), 41 deletions(-) create mode 100644 src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java delete mode 100644 src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGenerator.java create mode 100644 src/test/resources/liquibase/harness/change/changelogs/bigquery/addForeignKey.xml create mode 100644 src/test/resources/liquibase/harness/change/changelogs/bigquery/dropForeignKey.xml create mode 100644 src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/addForeignKey.json create mode 100644 src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/dropForeignKey.json delete mode 100644 src/test/resources/liquibase/harness/change/expectedSql/bigquery/addPrimaryKey.sql delete mode 100644 src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropPrimaryKey.sql diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java new file mode 100644 index 00000000..24ce8502 --- /dev/null +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java @@ -0,0 +1,126 @@ +package liquibase.ext.bigquery.snapshot.jvm; + +import liquibase.CatalogAndSchema; +import liquibase.Scope; +import liquibase.database.AbstractJdbcDatabase; +import liquibase.database.Database; +import liquibase.exception.DatabaseException; +import liquibase.executor.ExecutorService; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.snapshot.*; +import liquibase.snapshot.jvm.ForeignKeySnapshotGenerator; +import liquibase.snapshot.jvm.PrimaryKeySnapshotGenerator; +import liquibase.statement.core.RawSqlStatement; +import liquibase.structure.DatabaseObject; +import liquibase.structure.core.*; + +import java.util.*; + +public class BigQueryForeignKeySnapshotGenerator extends ForeignKeySnapshotGenerator { + + @Override + public int getPriority(Class objectType, Database database) { + if (database instanceof BigqueryDatabase) { + return super.getPriority(objectType, database) + PRIORITY_DATABASE; + } else { + return PRIORITY_NONE; + } + } + + @Override + public Class[] replaces() { + return new Class[]{PrimaryKeySnapshotGenerator.class}; + } + + @Override + protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { + Database database = snapshot.getDatabase(); + Table fkTable = ((ForeignKey) example).getForeignKeyTable(); + String fkName = example.getName(); + String searchCatalog = ((AbstractJdbcDatabase) database).getJdbcCatalogName(fkTable.getSchema()); + String searchSchema = ((AbstractJdbcDatabase) database).getJdbcSchemaName(fkTable.getSchema()); + String searchTableName = database.correctObjectName(fkTable.getName(), Table.class); + String systemSchema = database.getSystemSchema().toUpperCase(); + String query = new StringBuilder("SELECT ") + .append("TC.CONSTRAINT_NAME as CONSTRAINT_NAME, ") + .append("KCU.TABLE_CATALOG as FOREIGN_KEY_TABLE_CATALOG, ") + .append("KCU.TABLE_SCHEMA as FOREIGN_KEY_TABLE_SCHEMA, ") + .append("KCU.TABLE_NAME as FOREIGN_KEY_TABLE, ") + .append("KCU.COLUMN_NAME as FOREIGN_KEY_COLUMN, ") + .append("CCU.TABLE_CATALOG as PRIMARY_KEY_TABLE_CATALOG, ") + .append("CCU.TABLE_SCHEMA as PRIMARY_KEY_TABLE_SCHEMA, ") + .append("CCU.TABLE_NAME as PRIMARY_KEY_TABLE, ") + .append("CCU.COLUMN_NAME as PRIMARY_KEY_COLUMN ") + .append(String.format("FROM %1$s.%2$s.TABLE_CONSTRAINTS as TC JOIN %1$s.%2$s.CONSTRAINT_COLUMN_USAGE as CCU on " + + "TC.CONSTRAINT_NAME=CCU.CONSTRAINT_NAME JOIN %1$s.%2$s.KEY_COLUMN_USAGE as KCU on KCU.CONSTRAINT_NAME=TC.CONSTRAINT_NAME ", + searchSchema, systemSchema)) + .append(String.format("WHERE TC.TABLE_NAME='%s' AND TC.table_schema='%s' AND TC.table_catalog='%s' AND TC" + + ".constraint_type='FOREIGN KEY' AND TC.CONSTRAINT_NAME='%s'", searchTableName, searchSchema, searchCatalog, fkName)) + .toString(); + List> results = Scope.getCurrentScope().getSingleton(ExecutorService.class) + .getExecutor("jdbc", database).queryForList(new RawSqlStatement(query)); + + if (!results.isEmpty()) { + ForeignKey foreignKey = null; + for (Map resultMap : results) { + String foreignKeyName = Objects.toString(resultMap.get("CONSTRAINT_NAME")); + + Table foreignKeyTable = new Table().setName(Objects.toString(resultMap.get("FOREIGN_KEY_TABLE"))); + foreignKeyTable.setSchema(new Schema(new Catalog(Objects.toString(resultMap.get("FOREIGN_KEY_TABLE_CATALOG"))), + Objects.toString(resultMap.get("FOREIGN_KEY_TABLE_SCHEMA")))); + + Table primaryKeyTable = new Table().setName(Objects.toString(resultMap.get("PRIMARY_KEY_TABLE"))); + primaryKeyTable.setSchema( + new Schema(new Catalog(Objects.toString(resultMap.get("PRIMARY_KEY_TABLE_CATALOG"))), + Objects.toString(resultMap.get("PRIMARY_KEY_TABLE_SCHEMA")))); + Column fkColumn = new Column(Objects.toString(resultMap.get("FOREIGN_KEY_COLUMN"))).setRelation(foreignKeyTable); + Column pkColumn = new Column(Objects.toString(resultMap.get("PRIMARY_KEY_COLUMN"))).setRelation(primaryKeyTable); + + if (foreignKey != null) { + if (!foreignKey.getForeignKeyColumns().contains(fkColumn)) { + foreignKey.addForeignKeyColumn(fkColumn); + } + if (!foreignKey.getPrimaryKeyColumns().contains(pkColumn)) { + foreignKey.addPrimaryKeyColumn(pkColumn); + } + } else { + foreignKey = new ForeignKey(foreignKeyName); + + foreignKey.setForeignKeyTable(foreignKeyTable); + foreignKey.setPrimaryKeyTable(primaryKeyTable); + + foreignKey.addForeignKeyColumn(fkColumn); + foreignKey.addPrimaryKeyColumn(pkColumn); + + } + } + return foreignKey; + } + return null; + } + + @Override + protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException { + if (!snapshot.getSnapshotControl().shouldInclude(ForeignKey.class)) { + return; + } + if (foundObject instanceof Table) { + Table table = (Table) foundObject; + Database database = snapshot.getDatabase(); + Schema schema = table.getSchema(); + + CatalogAndSchema catalogAndSchema = (new CatalogAndSchema(schema.getCatalogName(), schema.getName())).customize(database); + String jdbcSchemaName = database.correctObjectName(((AbstractJdbcDatabase) database).getJdbcSchemaName(catalogAndSchema), Schema.class); + String query = String.format("SELECT CONSTRAINT_NAME FROM %s.%s.TABLE_CONSTRAINTS WHERE table_name='%s' AND table_schema='%s' AND " + + "table_catalog='%s' AND CONSTRAINT_TYPE='FOREIGN KEY';", + jdbcSchemaName, database.getSystemSchema().toUpperCase(), table.getName(), schema.getName(), schema.getCatalogName()); + List> tableConstraints = Scope.getCurrentScope().getSingleton(ExecutorService.class) + .getExecutor("jdbc", database).queryForList(new RawSqlStatement(query)); + for (Map row : tableConstraints) { + ForeignKey fk = new ForeignKey().setName(Objects.toString(row.get("CONSTRAINT_NAME"))).setForeignKeyTable(table); + table.getOutgoingForeignKeys().add(fk); + } + } + } +} + diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java index be2b7dbe..440cff41 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java @@ -39,7 +39,7 @@ public Class[] replaces() { @Override protected List listConstraints(Table table, DatabaseSnapshot snapshot, Schema schema) throws DatabaseException, SQLException { - Scope.getCurrentScope().getLog(this.getClass()).info("Constraints not supported by BigQuery"); + Scope.getCurrentScope().getLog(this.getClass()).info("Unique Constraints not supported by BigQuery"); return new ArrayList<>(); //new BigQueryResultSetConstraintsExtractor(snapshot, schema.getCatalogName(), schema.getName(), table.getName())).fastFetch(); } diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGenerator.java index 54572b4e..23eea1d3 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGenerator.java @@ -1,6 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.database.Database; +import liquibase.database.core.*; import liquibase.ext.bigquery.database.BigqueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; @@ -23,9 +24,22 @@ public boolean supports(AddForeignKeyConstraintStatement statement, Database dat @Override public Sql[] generateSql(AddForeignKeyConstraintStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { - String sql = "SELECT 1"; + StringBuilder sb = new StringBuilder(); + sb.append("ALTER TABLE ") + .append(database.escapeTableName(statement.getBaseTableCatalogName(), statement.getBaseTableSchemaName(), statement.getBaseTableName())) + .append(" ADD CONSTRAINT ") + .append(database.escapeConstraintName(statement.getConstraintName())) + .append(" FOREIGN KEY (") + .append(database.escapeColumnNameList(statement.getBaseColumnNames())) + .append(") REFERENCES ") + .append(database.escapeTableName(statement.getReferencedTableCatalogName(), statement.getReferencedTableSchemaName(), + statement.getReferencedTableName())) + .append(" (") + .append(database.escapeColumnNameList(statement.getReferencedColumnNames())) + .append(") NOT ENFORCED"); + return new Sql[]{ - new UnparsedSql(sql, getAffectedForeignKey(statement)) + new UnparsedSql(sb.toString(), getAffectedForeignKey(statement)) }; } } diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGenerator.java deleted file mode 100644 index 1524a468..00000000 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGenerator.java +++ /dev/null @@ -1,32 +0,0 @@ -package liquibase.ext.bigquery.sqlgenerator; - -import liquibase.database.Database; -import liquibase.ext.bigquery.database.BigqueryDatabase; -import liquibase.sql.Sql; -import liquibase.sql.UnparsedSql; -import liquibase.sqlgenerator.SqlGenerator; -import liquibase.sqlgenerator.SqlGeneratorChain; -import liquibase.sqlgenerator.core.DropForeignKeyConstraintGenerator; -import liquibase.statement.core.AddForeignKeyConstraintStatement; -import liquibase.statement.core.DropForeignKeyConstraintStatement; - -public class BigQueryDropForeignKeyConstraintGenerator extends DropForeignKeyConstraintGenerator { - - @Override - public int getPriority() { - return SqlGenerator.PRIORITY_DATABASE; - } - - @Override - public boolean supports(DropForeignKeyConstraintStatement statement, Database database) { - return database instanceof BigqueryDatabase; - } - - @Override - public Sql[] generateSql(DropForeignKeyConstraintStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { - String sql = "SELECT 1"; - return new Sql[]{ - new UnparsedSql(sql, getAffectedForeignKey(statement)) - }; - } -} diff --git a/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator b/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator index e6666938..92eb16f6 100644 --- a/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator +++ b/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator @@ -2,4 +2,5 @@ liquibase.ext.bigquery.snapshot.jvm.BigQueryDatasetSnapshotGenerator liquibase.ext.bigquery.snapshot.jvm.BigQueryUniqueConstraintSnapshotGenerator liquibase.ext.bigquery.snapshot.jvm.BigQuerySequenceSnapshotGenerator liquibase.ext.bigquery.snapshot.jvm.BigQueryViewSnapshotGenerator +liquibase.ext.bigquery.snapshot.jvm.BigQueryForeignKeySnapshotGenerator diff --git a/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator b/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator index 5a5ce104..7659212f 100644 --- a/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator +++ b/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator @@ -1,7 +1,6 @@ liquibase.ext.bigquery.sqlgenerator.BigQueryAddColumnGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryAddForeignKeyConstraintGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryAddPrimaryKeyConstraintGenerator -liquibase.ext.bigquery.sqlgenerator.BigQueryDropForeignKeyConstraintGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryDropPrimaryKeyConstraintGenerator liquibase.ext.bigquery.sqlgenerator.BigqueryCreateDatabaseChangeLogLockTableGenerator liquibase.ext.bigquery.sqlgenerator.BigqueryCreateDatabaseChangeLogTableGenerator diff --git a/src/test/resources/liquibase/harness/change/changelogs/bigquery/addForeignKey.xml b/src/test/resources/liquibase/harness/change/changelogs/bigquery/addForeignKey.xml new file mode 100644 index 00000000..0292745a --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/bigquery/addForeignKey.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/changelogs/bigquery/dropForeignKey.xml b/src/test/resources/liquibase/harness/change/changelogs/bigquery/dropForeignKey.xml new file mode 100644 index 00000000..42e8d66f --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/bigquery/dropForeignKey.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/addForeignKey.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/addForeignKey.json new file mode 100644 index 00000000..999683cf --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/addForeignKey.json @@ -0,0 +1,13 @@ +{ + "snapshot": { + "objects": { + "liquibase.structure.core.ForeignKey": [ + { + "foreignKey": { + "name": "posts.fk_posts_authors_test" + } + } + ] + } + } +} \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/dropForeignKey.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/dropForeignKey.json new file mode 100644 index 00000000..0c7a16b2 --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/dropForeignKey.json @@ -0,0 +1,14 @@ +{ + "snapshot": { + "objects": { + "_noMatch": true, + "liquibase.structure.core.ForeignKey": [ + { + "foreignKey": { + "name": "posts.fk_posts_authors_test" + } + } + ] + } + } +} \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql index 7b237cc0..4f152c88 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql @@ -1 +1 @@ -INVALID TEST -- BigQuery does not support FK \ No newline at end of file +ALTER TABLE harness_test_ds.posts ADD CONSTRAINT fk_posts_authors_test FOREIGN KEY (author_id) REFERENCES harness_test_ds.authors (id) NOT ENFORCED \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addPrimaryKey.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addPrimaryKey.sql deleted file mode 100644 index be9fd23b..00000000 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addPrimaryKey.sql +++ /dev/null @@ -1 +0,0 @@ -INVALID TEST -- BigQuery does not support PK \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropForeignKey.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropForeignKey.sql index 7b237cc0..cdc2379c 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropForeignKey.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropForeignKey.sql @@ -1 +1,2 @@ -INVALID TEST -- BigQuery does not support FK \ No newline at end of file +ALTER TABLE harness_test_ds.posts ADD CONSTRAINT fk_posts_authors_test FOREIGN KEY (author_id) REFERENCES harness_test_ds.authors (id) NOT ENFORCED +ALTER TABLE harness_test_ds.posts DROP CONSTRAINT fk_posts_authors_test \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropPrimaryKey.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropPrimaryKey.sql deleted file mode 100644 index be9fd23b..00000000 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropPrimaryKey.sql +++ /dev/null @@ -1 +0,0 @@ -INVALID TEST -- BigQuery does not support PK \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/renameTrigger.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/renameTrigger.sql index 0eb7e1ef..1258dfb6 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/renameTrigger.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/renameTrigger.sql @@ -1 +1 @@ -INVALID TEST -- BigQuery doesn't support rename \ No newline at end of file +INVALID TEST -- BigQuery doesn't support triggers \ No newline at end of file From c5da23c8772d83c22a404462783b8216be5a8b4c Mon Sep 17 00:00:00 2001 From: KushnirykOleh Date: Thu, 16 May 2024 16:41:01 +0300 Subject: [PATCH 09/32] fixed FK name --- .../BigQueryForeignKeySnapshotGenerator.java | 27 ++++++++++++++----- .../expectedSql/bigquery/addForeignKey.sql | 1 - 2 files changed, 20 insertions(+), 8 deletions(-) delete mode 100644 src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java index 24ce8502..10bb5b47 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java @@ -4,16 +4,22 @@ import liquibase.Scope; import liquibase.database.AbstractJdbcDatabase; import liquibase.database.Database; +import liquibase.database.jvm.JdbcConnection; import liquibase.exception.DatabaseException; import liquibase.executor.ExecutorService; import liquibase.ext.bigquery.database.BigqueryDatabase; import liquibase.snapshot.*; import liquibase.snapshot.jvm.ForeignKeySnapshotGenerator; import liquibase.snapshot.jvm.PrimaryKeySnapshotGenerator; +import liquibase.statement.core.RawParameterizedSqlStatement; import liquibase.statement.core.RawSqlStatement; import liquibase.structure.DatabaseObject; import liquibase.structure.core.*; +import org.apache.commons.lang3.StringUtils; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.*; public class BigQueryForeignKeySnapshotGenerator extends ForeignKeySnapshotGenerator { @@ -36,10 +42,10 @@ public Class[] replaces() { protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { Database database = snapshot.getDatabase(); Table fkTable = ((ForeignKey) example).getForeignKeyTable(); - String fkName = example.getName(); + String searchTableName = database.correctObjectName(fkTable.getName(), Table.class); + String fkFullName = searchTableName + "." + example.getName(); String searchCatalog = ((AbstractJdbcDatabase) database).getJdbcCatalogName(fkTable.getSchema()); String searchSchema = ((AbstractJdbcDatabase) database).getJdbcSchemaName(fkTable.getSchema()); - String searchTableName = database.correctObjectName(fkTable.getName(), Table.class); String systemSchema = database.getSystemSchema().toUpperCase(); String query = new StringBuilder("SELECT ") .append("TC.CONSTRAINT_NAME as CONSTRAINT_NAME, ") @@ -55,17 +61,21 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot "TC.CONSTRAINT_NAME=CCU.CONSTRAINT_NAME JOIN %1$s.%2$s.KEY_COLUMN_USAGE as KCU on KCU.CONSTRAINT_NAME=TC.CONSTRAINT_NAME ", searchSchema, systemSchema)) .append(String.format("WHERE TC.TABLE_NAME='%s' AND TC.table_schema='%s' AND TC.table_catalog='%s' AND TC" + - ".constraint_type='FOREIGN KEY' AND TC.CONSTRAINT_NAME='%s'", searchTableName, searchSchema, searchCatalog, fkName)) + ".constraint_type='FOREIGN KEY' AND TC.CONSTRAINT_NAME='%s'", searchTableName, searchSchema, searchCatalog, fkFullName)) .toString(); List> results = Scope.getCurrentScope().getSingleton(ExecutorService.class) - .getExecutor("jdbc", database).queryForList(new RawSqlStatement(query)); + .getExecutor("jdbc", database).queryForList(new RawParameterizedSqlStatement(query)); if (!results.isEmpty()) { ForeignKey foreignKey = null; for (Map resultMap : results) { - String foreignKeyName = Objects.toString(resultMap.get("CONSTRAINT_NAME")); - Table foreignKeyTable = new Table().setName(Objects.toString(resultMap.get("FOREIGN_KEY_TABLE"))); + + String foreignKeyName = + Optional.ofNullable((String)resultMap.get("CONSTRAINT_NAME")) + .map(s-> s.replace(foreignKeyTable.getName()+".", "")) + .orElse("null"); + foreignKeyTable.setSchema(new Schema(new Catalog(Objects.toString(resultMap.get("FOREIGN_KEY_TABLE_CATALOG"))), Objects.toString(resultMap.get("FOREIGN_KEY_TABLE_SCHEMA")))); @@ -117,7 +127,10 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro List> tableConstraints = Scope.getCurrentScope().getSingleton(ExecutorService.class) .getExecutor("jdbc", database).queryForList(new RawSqlStatement(query)); for (Map row : tableConstraints) { - ForeignKey fk = new ForeignKey().setName(Objects.toString(row.get("CONSTRAINT_NAME"))).setForeignKeyTable(table); + String foreignKeyName = Objects.toString(row.get("CONSTRAINT_NAME")); + ForeignKey fk = new ForeignKey() + .setName(foreignKeyName.replace(table.getName()+".", "")) + .setForeignKeyTable(table); table.getOutgoingForeignKeys().add(fk); } } diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql deleted file mode 100644 index 4f152c88..00000000 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE harness_test_ds.posts ADD CONSTRAINT fk_posts_authors_test FOREIGN KEY (author_id) REFERENCES harness_test_ds.authors (id) NOT ENFORCED \ No newline at end of file From 687e2b111c0a8fc77554b285191b7586f06594b1 Mon Sep 17 00:00:00 2001 From: KushnirykOleh Date: Thu, 16 May 2024 19:48:06 +0300 Subject: [PATCH 10/32] updated query generation --- .../BigQueryForeignKeySnapshotGenerator.java | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java index 10bb5b47..3650f07f 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java @@ -4,22 +4,16 @@ import liquibase.Scope; import liquibase.database.AbstractJdbcDatabase; import liquibase.database.Database; -import liquibase.database.jvm.JdbcConnection; import liquibase.exception.DatabaseException; import liquibase.executor.ExecutorService; import liquibase.ext.bigquery.database.BigqueryDatabase; -import liquibase.snapshot.*; +import liquibase.snapshot.DatabaseSnapshot; +import liquibase.snapshot.SnapshotGenerator; import liquibase.snapshot.jvm.ForeignKeySnapshotGenerator; -import liquibase.snapshot.jvm.PrimaryKeySnapshotGenerator; import liquibase.statement.core.RawParameterizedSqlStatement; -import liquibase.statement.core.RawSqlStatement; import liquibase.structure.DatabaseObject; import liquibase.structure.core.*; -import org.apache.commons.lang3.StringUtils; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.*; public class BigQueryForeignKeySnapshotGenerator extends ForeignKeySnapshotGenerator { @@ -35,11 +29,11 @@ public int getPriority(Class objectType, Database data @Override public Class[] replaces() { - return new Class[]{PrimaryKeySnapshotGenerator.class}; + return new Class[]{ForeignKeySnapshotGenerator.class}; } @Override - protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { + protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException { Database database = snapshot.getDatabase(); Table fkTable = ((ForeignKey) example).getForeignKeyTable(); String searchTableName = database.correctObjectName(fkTable.getName(), Table.class); @@ -47,6 +41,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot String searchCatalog = ((AbstractJdbcDatabase) database).getJdbcCatalogName(fkTable.getSchema()); String searchSchema = ((AbstractJdbcDatabase) database).getJdbcSchemaName(fkTable.getSchema()); String systemSchema = database.getSystemSchema().toUpperCase(); + String query = new StringBuilder("SELECT ") .append("TC.CONSTRAINT_NAME as CONSTRAINT_NAME, ") .append("KCU.TABLE_CATALOG as FOREIGN_KEY_TABLE_CATALOG, ") @@ -60,11 +55,10 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot .append(String.format("FROM %1$s.%2$s.TABLE_CONSTRAINTS as TC JOIN %1$s.%2$s.CONSTRAINT_COLUMN_USAGE as CCU on " + "TC.CONSTRAINT_NAME=CCU.CONSTRAINT_NAME JOIN %1$s.%2$s.KEY_COLUMN_USAGE as KCU on KCU.CONSTRAINT_NAME=TC.CONSTRAINT_NAME ", searchSchema, systemSchema)) - .append(String.format("WHERE TC.TABLE_NAME='%s' AND TC.table_schema='%s' AND TC.table_catalog='%s' AND TC" + - ".constraint_type='FOREIGN KEY' AND TC.CONSTRAINT_NAME='%s'", searchTableName, searchSchema, searchCatalog, fkFullName)) + .append("WHERE TC.TABLE_NAME=? AND TC.TABLE_SCHEMA=? AND TC.TABLE_CATALOG=? AND TC.CONSTRAINT_TYPE='FOREIGN KEY' AND TC.CONSTRAINT_NAME=?") .toString(); List> results = Scope.getCurrentScope().getSingleton(ExecutorService.class) - .getExecutor("jdbc", database).queryForList(new RawParameterizedSqlStatement(query)); + .getExecutor("jdbc", database).queryForList(new RawParameterizedSqlStatement(query, searchTableName, searchSchema, searchCatalog, fkFullName)); if (!results.isEmpty()) { ForeignKey foreignKey = null; @@ -72,8 +66,8 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot Table foreignKeyTable = new Table().setName(Objects.toString(resultMap.get("FOREIGN_KEY_TABLE"))); String foreignKeyName = - Optional.ofNullable((String)resultMap.get("CONSTRAINT_NAME")) - .map(s-> s.replace(foreignKeyTable.getName()+".", "")) + Optional.ofNullable((String) resultMap.get("CONSTRAINT_NAME")) + .map(s -> s.replace(foreignKeyTable.getName() + ".", "")) .orElse("null"); foreignKeyTable.setSchema(new Schema(new Catalog(Objects.toString(resultMap.get("FOREIGN_KEY_TABLE_CATALOG"))), @@ -121,19 +115,18 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro CatalogAndSchema catalogAndSchema = (new CatalogAndSchema(schema.getCatalogName(), schema.getName())).customize(database); String jdbcSchemaName = database.correctObjectName(((AbstractJdbcDatabase) database).getJdbcSchemaName(catalogAndSchema), Schema.class); - String query = String.format("SELECT CONSTRAINT_NAME FROM %s.%s.TABLE_CONSTRAINTS WHERE table_name='%s' AND table_schema='%s' AND " + - "table_catalog='%s' AND CONSTRAINT_TYPE='FOREIGN KEY';", - jdbcSchemaName, database.getSystemSchema().toUpperCase(), table.getName(), schema.getName(), schema.getCatalogName()); + String query = String.format("SELECT CONSTRAINT_NAME FROM %s.%s.TABLE_CONSTRAINTS WHERE TABLE_NAME=? AND TABLE_SCHEMA=? AND TABLE_CATALOG=? AND " + + "CONSTRAINT_TYPE='FOREIGN KEY';", jdbcSchemaName, database.getSystemSchema().toUpperCase()); List> tableConstraints = Scope.getCurrentScope().getSingleton(ExecutorService.class) - .getExecutor("jdbc", database).queryForList(new RawSqlStatement(query)); + .getExecutor("jdbc", database).queryForList(new RawParameterizedSqlStatement(query, table.getName(), schema.getName(), + schema.getCatalogName())); for (Map row : tableConstraints) { String foreignKeyName = Objects.toString(row.get("CONSTRAINT_NAME")); ForeignKey fk = new ForeignKey() - .setName(foreignKeyName.replace(table.getName()+".", "")) - .setForeignKeyTable(table); + .setName(foreignKeyName.replace(table.getName() + ".", "")) + .setForeignKeyTable(table); table.getOutgoingForeignKeys().add(fk); } } } -} - +} \ No newline at end of file From ce7e5ea290465e99e997cc54b671a4071cc40022 Mon Sep 17 00:00:00 2001 From: KushnirykOleh Date: Fri, 17 May 2024 18:22:49 +0300 Subject: [PATCH 11/32] replaced null by undefined, fixed creating constraints when creating table --- .../BigQueryForeignKeySnapshotGenerator.java | 2 +- .../BigQueryCreateTableGenerator.java | 31 ++++++++++++++++-- .../changelogs/bigquery/createTable.xml | 10 ++++-- .../bigquery/addForeignKey.json | 2 +- .../bigquery/createTable.json | 32 +++++++++++++++++++ .../expectedSql/bigquery/createTable.sql | 2 +- 6 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/createTable.json diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java index 3650f07f..ec0c8159 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java @@ -68,7 +68,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot String foreignKeyName = Optional.ofNullable((String) resultMap.get("CONSTRAINT_NAME")) .map(s -> s.replace(foreignKeyTable.getName() + ".", "")) - .orElse("null"); + .orElse("undefined"); foreignKeyTable.setSchema(new Schema(new Catalog(Objects.toString(resultMap.get("FOREIGN_KEY_TABLE_CATALOG"))), Objects.toString(resultMap.get("FOREIGN_KEY_TABLE_SCHEMA")))); diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java index 483d11a5..3f681c5a 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java @@ -9,7 +9,10 @@ import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.CreateTableGenerator; import liquibase.statement.DatabaseFunction; +import liquibase.statement.ForeignKeyConstraint; import liquibase.statement.core.CreateTableStatement; +import liquibase.structure.core.Schema; +import liquibase.structure.core.Table; import java.util.ArrayList; import java.util.Iterator; @@ -62,7 +65,6 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG buffer.append(statement.getColumnTypes().get(column).objectToSql(defaultValue, database)); } } - if (statement.getNotNullColumns().get(column) != null) { Scope.getCurrentScope().getLog(this.getClass()).fine("Not null constraints are not supported by BigQuery"); } @@ -70,9 +72,32 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG buffer.append(", "); } } - - buffer.append(","); + for (ForeignKeyConstraint fkConstraint : statement.getForeignKeyConstraints()) { + if(fkConstraint.getForeignKeyName()!=null) { + buffer.append(" CONSTRAINT "); + buffer.append(database.escapeConstraintName(fkConstraint.getForeignKeyName())); + } + String referencesString = fkConstraint.getReferences(); + buffer.append(" FOREIGN KEY (") + .append(database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), fkConstraint.getColumn())) + .append(") REFERENCES "); + if (referencesString != null) { + if (!referencesString.contains(".") && (database.getDefaultSchemaName() != null) && database + .getOutputDefaultSchema() && (database.supportsSchemas() || database.supportsCatalogs())) { + referencesString = database.escapeObjectName(database.getDefaultSchemaName(), Schema.class) + "." + referencesString; + } + buffer.append(referencesString); + } else { + buffer.append(database.escapeObjectName(fkConstraint.getReferencedTableCatalogName(), fkConstraint.getReferencedTableSchemaName(), fkConstraint.getReferencedTableName(), Table.class)) + .append("(") + .append(database.escapeColumnNameList(fkConstraint.getReferencedColumnNames())) + .append(")"); + + } + buffer.append(" NOT ENFORCED");//BiqQuery support only NOT ENFORCED FKs, and Liquibase doesn't have attribute to specify that in changelog + buffer.append(","); // so hardcoding this property + } String sql = buffer.toString().replaceFirst(",\\s*$", "") + ")"; additionalSql.add(0, new UnparsedSql(sql, this.getAffectedTable(statement))); diff --git a/src/test/resources/liquibase/harness/change/changelogs/bigquery/createTable.xml b/src/test/resources/liquibase/harness/change/changelogs/bigquery/createTable.xml index 5d86749f..f94f272a 100644 --- a/src/test/resources/liquibase/harness/change/changelogs/bigquery/createTable.xml +++ b/src/test/resources/liquibase/harness/change/changelogs/bigquery/createTable.xml @@ -5,11 +5,17 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> - + + - + + + + + \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/addForeignKey.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/addForeignKey.json index 999683cf..d9852ece 100644 --- a/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/addForeignKey.json +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/addForeignKey.json @@ -4,7 +4,7 @@ "liquibase.structure.core.ForeignKey": [ { "foreignKey": { - "name": "posts.fk_posts_authors_test" + "name": "fk_posts_authors_test" } } ] diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/createTable.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/createTable.json new file mode 100644 index 00000000..3dce7a8d --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/bigquery/createTable.json @@ -0,0 +1,32 @@ +{ + "snapshot": { + "objects": { + "liquibase.structure.core.Table": [ + { + "table": { + "name": "test_table" + } + } + ], + "liquibase.structure.core.Column": [ + { + "column": { + "name": "test_id" + } + }, + { + "column": { + "name": "test_FK_column" + } + } + ], + "liquibase.structure.core.ForeignKey": [ + { + "foreignKey": { + "name": "fk_test" + } + } + ] + } + } +} diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/createTable.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/createTable.sql index 6a7679a3..8b0fd898 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/createTable.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/createTable.sql @@ -1 +1 @@ -CREATE TABLE harness_test_ds.test_table (test_id INT, test_column STRING) \ No newline at end of file +CREATE TABLE harness_test_ds.test_table (test_id INT, test_FK_column INT, CONSTRAINT fk_test FOREIGN KEY (test_FK_column) REFERENCES harness_test_ds.authors(id) NOT ENFORCED) \ No newline at end of file From 3191d086a0b84a3e1d302218111d1a930327c1df Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 30 May 2024 16:53:52 +0300 Subject: [PATCH 12/32] Fix merge conflicts --- ...yAddForeignKeyConstraintGeneratorTest.java | 2 +- ...DropForeignKeyConstraintGeneratorTest.java | 32 ------------------- 2 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGeneratorTest.java diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java index 591e98e6..7a89736e 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java @@ -36,6 +36,6 @@ void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); - assertEquals("SELECT 1", sql[0].toSql()); + assertEquals("ALTER TABLE baseTableSchemaName.baseTableName ADD CONSTRAINT constraintName FOREIGN KEY (`null`) REFERENCES referencedTableSchemaName.referencedTableName (`null`) NOT ENFORCED", sql[0].toSql()); } } \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGeneratorTest.java deleted file mode 100644 index dd1b9980..00000000 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropForeignKeyConstraintGeneratorTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package liquibase.ext.bigquery.sqlgenerator; - -import liquibase.ext.bigquery.database.BigqueryDatabase; -import liquibase.sql.Sql; -import liquibase.statement.core.DropForeignKeyConstraintStatement; -import liquibase.statement.core.RenameTableStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class BigQueryDropForeignKeyConstraintGeneratorTest { - - private BigQueryDropForeignKeyConstraintGenerator generator; - private BigqueryDatabase database; - private DropForeignKeyConstraintStatement statement; - - @BeforeEach - void setUp() { - database = new BigqueryDatabase(); - generator = new BigQueryDropForeignKeyConstraintGenerator(); - statement = new DropForeignKeyConstraintStatement(null, null, null, null); - } - - @Test - void generateSql() { - Sql[] sql = generator.generateSql(statement, database, null); - assertEquals(1, sql.length); - assertEquals(";", sql[0].getEndDelimiter()); - assertEquals("SELECT 1", sql[0].toSql()); - } -} \ No newline at end of file From 02d5cec77863f503ed097febd837728f21733a45 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Wed, 29 May 2024 16:27:42 +0300 Subject: [PATCH 13/32] Add PrimaryKey support --- .../BigQueryPrimaryKeySnapshotGenerator.java | 111 ++++++++++++++++++ .../BigQueryAddColumnGenerator.java | 52 +++++++- ...QueryAddPrimaryKeyConstraintGenerator.java | 5 +- .../BigQueryCreateTableGenerator.java | 19 +++ ...ueryDropPrimaryKeyConstraintGenerator.java | 32 ----- .../liquibase.snapshot.SnapshotGenerator | 2 +- .../liquibase.sqlgenerator.SqlGenerator | 1 - ...yAddPrimaryKeyConstraintGeneratorTest.java | 2 +- ...DropPrimaryKeyConstraintGeneratorTest.java | 32 ----- 9 files changed, 186 insertions(+), 70 deletions(-) create mode 100644 src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryPrimaryKeySnapshotGenerator.java delete mode 100644 src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGenerator.java delete mode 100644 src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGeneratorTest.java diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryPrimaryKeySnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryPrimaryKeySnapshotGenerator.java new file mode 100644 index 00000000..72c18728 --- /dev/null +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryPrimaryKeySnapshotGenerator.java @@ -0,0 +1,111 @@ +package liquibase.ext.bigquery.snapshot.jvm; + +import liquibase.CatalogAndSchema; +import liquibase.Scope; +import liquibase.database.Database; +import liquibase.exception.DatabaseException; +import liquibase.executor.Executor; +import liquibase.executor.ExecutorService; +import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.snapshot.DatabaseSnapshot; +import liquibase.snapshot.InvalidExampleException; +import liquibase.snapshot.SnapshotGenerator; +import liquibase.snapshot.jvm.PrimaryKeySnapshotGenerator; +import liquibase.statement.core.RawParameterizedSqlStatement; +import liquibase.structure.DatabaseObject; +import liquibase.structure.core.Column; +import liquibase.structure.core.Index; +import liquibase.structure.core.PrimaryKey; +import liquibase.structure.core.Schema; +import liquibase.structure.core.Table; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class BigQueryPrimaryKeySnapshotGenerator extends PrimaryKeySnapshotGenerator { + + @Override + public int getPriority(Class objectType, Database database) { + if (!(database instanceof BigqueryDatabase)) { + return PRIORITY_NONE; + } + int priority = super.getPriority(objectType, database); + if (priority > PRIORITY_NONE) { + priority += PRIORITY_DATABASE; + } + return priority; + } + + @Override + public Class[] replaces() { + return new Class[]{PrimaryKeySnapshotGenerator.class}; + } + + @Override + protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { + Database database = snapshot.getDatabase(); + Schema schema = example.getSchema(); + String searchTableName = null; + if (((PrimaryKey) example).getTable() != null) { + searchTableName = ((PrimaryKey) example).getTable().getName(); + searchTableName = database.correctObjectName(searchTableName, Table.class); + } + PrimaryKey returnKey = null; + + String keyColumnUsageStatement = String.format("SELECT * FROM %s.INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_name = ?", schema.getSchema()); + Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database); + List> maps = executor.queryForList(new RawParameterizedSqlStatement(keyColumnUsageStatement, searchTableName)); + String columnName; + for (Map map : maps) { + columnName = Objects.toString(map.get("COLUMN_NAME"), null); + int position = ((Long) map.get("ORDINAL_POSITION")).intValue(); + + if (returnKey == null) { + returnKey = new PrimaryKey(); + String catalogName = (String) map.get("TABLE_CATALOG"); + String schemaName = (String) map.get("TABLE_SCHEMA"); + CatalogAndSchema tableSchema = new CatalogAndSchema(catalogName, schemaName); + returnKey.setTable((Table) new Table().setName(Objects.toString(map.get("TABLE_NAME"), null)).setSchema(new Schema(tableSchema.getCatalogName(), tableSchema.getSchemaName()))); + returnKey.setName(Objects.toString(map.get("CONSTRAINT_NAME"), null)); + } + + returnKey.addColumn(position - 1, new Column(columnName) + .setRelation(((PrimaryKey) example).getTable())); + } + if (returnKey != null) { + Index exampleIndex = new Index().setRelation(returnKey.getTable()); + exampleIndex.setColumns(returnKey.getColumns()); + returnKey.setBackingIndex(exampleIndex); + } + return returnKey; + } + + @Override + protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException { + if (!snapshot.getSnapshotControl().shouldInclude(PrimaryKey.class)) { + return; + } + + if (foundObject instanceof Table) { + Table table = (Table) foundObject; + Database database = snapshot.getDatabase(); + Schema schema = table.getSchema(); + + Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database); + String tableConstraintsStatement = String.format("SELECT * FROM %s.INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE table_name = ?", schema.getSchema()); + List> maps = executor.queryForList(new RawParameterizedSqlStatement(tableConstraintsStatement, table.getName())); + + for (Map map : maps) { + if (map.containsKey("CONSTRAINT_NAME")) { + String constraintName = Objects.toString(map.get("CONSTRAINT_NAME"), null); + PrimaryKey primaryKey = new PrimaryKey().setName(constraintName); + primaryKey.setTable((Table) foundObject); + if (!database.isSystemObject(primaryKey)) { + table.setPrimaryKey(primaryKey.setTable(table)); + } + } + } + } + } +} diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGenerator.java index 56bdbb9f..5dbfb030 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGenerator.java @@ -2,16 +2,66 @@ import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import liquibase.Scope; import liquibase.database.Database; +import liquibase.datatype.DataTypeFactory; +import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigqueryDatabase; import liquibase.sqlgenerator.core.AddColumnGenerator; +import liquibase.statement.AutoIncrementConstraint; import liquibase.statement.core.AddColumnStatement; public class BigQueryAddColumnGenerator extends AddColumnGenerator { @Override protected String generateSingleColumnSQL(AddColumnStatement statement, Database database) { - return super.generateSingleColumnSQL(statement, database).replace(" ADD ", " ADD COLUMN "); + DatabaseDataType columnType = null; + + if (statement.getColumnType() != null) { + columnType = DataTypeFactory.getInstance().fromDescription(statement.getColumnType() + (statement.isAutoIncrement() ? "{autoIncrement:true}" : ""), database).toDatabaseDataType(database); + } + + String alterTable = " ADD COLUMN " + database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName()); + + if (columnType != null) { + alterTable += " " + columnType; + } + + if (statement.isAutoIncrement() && database.supportsAutoIncrement()) { + AutoIncrementConstraint autoIncrementConstraint = statement.getAutoIncrementConstraint(); + alterTable += " " + database.getAutoIncrementClause(autoIncrementConstraint.getStartWith(), autoIncrementConstraint.getIncrementBy(), autoIncrementConstraint.getGenerationType(), autoIncrementConstraint.getDefaultOnNull()); + } + + if (statement.getDefaultValue() != null) { + // TODO add default value + // Add field with default value to an existing table schema is not supported. + // You can achieve the same result by executing the following 3 statements: + // 1. ALTER TABLE tableName ADD COLUMN columnName; + // 2. ALTER TABLE tableName ALTER COLUMN columnName SET DEFAULT columnDefaultValue; + // 3. UPDATE tableName SET columnName = columnDefaultValue WHERE TRUE; + Scope.getCurrentScope().getLog(this.getClass()).fine("Default clauses are not supported during column creation by BigQuery"); + } + + if (!statement.isNullable()) { + Scope.getCurrentScope().getLog(this.getClass()).fine("Not null constraints are not supported by BigQuery"); + } + + if (statement.isPrimaryKey()) { + String baseSQL = generateSingleColumBaseSQL(statement, database); + alterTable += "; " + baseSQL + " ADD PRIMARY KEY (" + + database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName()) + + ") NOT ENFORCED"; + } + + if ((statement.getAddBeforeColumn() != null) && !statement.getAddBeforeColumn().isEmpty()) { + Scope.getCurrentScope().getLog(this.getClass()).fine("Before clauses are not supported by BigQuery"); + } + + if ((statement.getAddAfterColumn() != null) && !statement.getAddAfterColumn().isEmpty()) { + Scope.getCurrentScope().getLog(this.getClass()).fine("After clauses are not supported by BigQuery"); + } + + return alterTable; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGenerator.java index acbfd056..cba13f40 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGenerator.java @@ -23,8 +23,9 @@ public boolean supports(AddPrimaryKeyStatement statement, Database database) { @Override public Sql[] generateSql(AddPrimaryKeyStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { - String sql = "SELECT 1"; - + String sql = String.format("ALTER TABLE %s ADD PRIMARY KEY (%s) NOT ENFORCED", + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()), + database.escapeColumnNameList(statement.getColumnNames())); return new Sql[]{ new UnparsedSql(sql, getAffectedPrimaryKey(statement)) }; diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java index 3f681c5a..ff611e7e 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java @@ -10,6 +10,7 @@ import liquibase.sqlgenerator.core.CreateTableGenerator; import liquibase.statement.DatabaseFunction; import liquibase.statement.ForeignKeyConstraint; +import liquibase.statement.PrimaryKeyConstraint; import liquibase.statement.core.CreateTableStatement; import liquibase.structure.core.Schema; import liquibase.structure.core.Table; @@ -73,6 +74,24 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG } } buffer.append(","); + + PrimaryKeyConstraint primaryKeyConstraint = statement.getPrimaryKeyConstraint(); + if (primaryKeyConstraint != null) { + buffer.append(" PRIMARY KEY ("); + + for (int i = 0; i < primaryKeyConstraint.getColumns().size(); i++) { + String primaryKeyColumnName = primaryKeyConstraint.getColumns().get(i); + buffer.append(database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), primaryKeyColumnName)); + if (i < primaryKeyConstraint.getColumns().size() - 1) { + buffer.append(", "); + } + } + + buffer.append(")") + .append(" NOT ENFORCED") + .append(","); + } + for (ForeignKeyConstraint fkConstraint : statement.getForeignKeyConstraints()) { if(fkConstraint.getForeignKeyName()!=null) { buffer.append(" CONSTRAINT "); diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGenerator.java deleted file mode 100644 index ed1a1cec..00000000 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGenerator.java +++ /dev/null @@ -1,32 +0,0 @@ -package liquibase.ext.bigquery.sqlgenerator; - -import liquibase.database.Database; -import liquibase.ext.bigquery.database.BigqueryDatabase; -import liquibase.sql.Sql; -import liquibase.sql.UnparsedSql; -import liquibase.sqlgenerator.SqlGenerator; -import liquibase.sqlgenerator.SqlGeneratorChain; -import liquibase.sqlgenerator.core.DropPrimaryKeyGenerator; -import liquibase.statement.core.DropPrimaryKeyStatement; - -public class BigQueryDropPrimaryKeyConstraintGenerator extends DropPrimaryKeyGenerator { - - @Override - public int getPriority() { - return SqlGenerator.PRIORITY_DATABASE; - } - - @Override - public boolean supports(DropPrimaryKeyStatement statement, Database database) { - return database instanceof BigqueryDatabase; - } - - @Override - public Sql[] generateSql(DropPrimaryKeyStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { - String sql = "SELECT 1"; - - return new Sql[]{ - new UnparsedSql(sql, getAffectedPrimaryKey(statement)) - }; - } -} diff --git a/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator b/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator index 92eb16f6..dda641a1 100644 --- a/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator +++ b/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator @@ -3,4 +3,4 @@ liquibase.ext.bigquery.snapshot.jvm.BigQueryUniqueConstraintSnapshotGenerator liquibase.ext.bigquery.snapshot.jvm.BigQuerySequenceSnapshotGenerator liquibase.ext.bigquery.snapshot.jvm.BigQueryViewSnapshotGenerator liquibase.ext.bigquery.snapshot.jvm.BigQueryForeignKeySnapshotGenerator - +liquibase.ext.bigquery.snapshot.jvm.BigQueryPrimaryKeySnapshotGenerator diff --git a/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator b/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator index 7659212f..e302504b 100644 --- a/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator +++ b/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator @@ -1,7 +1,6 @@ liquibase.ext.bigquery.sqlgenerator.BigQueryAddColumnGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryAddForeignKeyConstraintGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryAddPrimaryKeyConstraintGenerator -liquibase.ext.bigquery.sqlgenerator.BigQueryDropPrimaryKeyConstraintGenerator liquibase.ext.bigquery.sqlgenerator.BigqueryCreateDatabaseChangeLogLockTableGenerator liquibase.ext.bigquery.sqlgenerator.BigqueryCreateDatabaseChangeLogTableGenerator liquibase.ext.bigquery.sqlgenerator.BigqueryDeleteGenerator diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java index 8b042f5b..0474b3dd 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java @@ -32,6 +32,6 @@ void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); - assertEquals("SELECT 1", sql[0].toSql()); + assertEquals("ALTER TABLE schemaName.tableName ADD PRIMARY KEY (`null`) NOT ENFORCED", sql[0].toSql()); } } \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGeneratorTest.java deleted file mode 100644 index 63963b8e..00000000 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDropPrimaryKeyConstraintGeneratorTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package liquibase.ext.bigquery.sqlgenerator; - -import liquibase.ext.bigquery.database.BigqueryDatabase; -import liquibase.sql.Sql; -import liquibase.statement.core.DropPrimaryKeyStatement; -import liquibase.statement.core.RenameTableStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class BigQueryDropPrimaryKeyConstraintGeneratorTest { - - private BigQueryDropPrimaryKeyConstraintGenerator generator; - private BigqueryDatabase database; - private DropPrimaryKeyStatement statement; - - @BeforeEach - void setUp() { - database = new BigqueryDatabase(); - generator = new BigQueryDropPrimaryKeyConstraintGenerator(); - statement = new DropPrimaryKeyStatement("catalogName", "schemaName", "tableName", "columnName"); - } - - @Test - void generateSql() { - Sql[] sql = generator.generateSql(statement, database, null); - assertEquals(1, sql.length); - assertEquals(";", sql[0].getEndDelimiter()); - assertEquals("SELECT 1", sql[0].toSql()); - } -} \ No newline at end of file From 7948b0a2adc579923e0ee4766831dbd04ec46d01 Mon Sep 17 00:00:00 2001 From: KushnirykOleh Date: Tue, 14 May 2024 18:22:22 +0300 Subject: [PATCH 14/32] resolved priorities for Datatypes and ModifyDatatype generator --- .../bigquery/datatype/core/BignumericDataTypeBigQuery.java | 2 +- .../ext/bigquery/datatype/core/BoolDataTypeBigQuery.java | 2 +- .../ext/bigquery/datatype/core/Float64DataTypeBigQuery.java | 2 +- .../bigquery/datatype/core/GeographyDataTypeBigQuery.java | 2 +- .../ext/bigquery/datatype/core/Int64DataTypeBigQuery.java | 2 +- ...erDataTypeBigQuery.java => NumericDataTypeBigQuery.java} | 6 +++--- .../ext/bigquery/datatype/core/StringDataTypeBigQuery.java | 4 ++-- .../sqlgenerator/BigQueryModifyDataTypeGenerator.java | 6 ++++++ .../META-INF/services/liquibase.datatype.LiquibaseDataType | 2 +- 9 files changed, 17 insertions(+), 11 deletions(-) rename src/main/java/liquibase/ext/bigquery/datatype/core/{NumberDataTypeBigQuery.java => NumericDataTypeBigQuery.java} (85%) diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java index 663fa690..31ae6c01 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java @@ -12,7 +12,7 @@ name = "bignumeric", minParameters = 0, maxParameters = 0, - priority = 1 + priority = LiquibaseDataType.PRIORITY_DATABASE ) public class BignumericDataTypeBigQuery extends LiquibaseDataType { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java index fcd188a6..93444618 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java @@ -14,7 +14,7 @@ name = "boolean", minParameters = 0, maxParameters = 0, - priority = BIGQUERY_PRIORITY_DATABASE + priority = LiquibaseDataType.PRIORITY_DATABASE ) public class BoolDataTypeBigQuery extends LiquibaseDataType { public BoolDataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java index 196e0960..3eb14edb 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java @@ -13,7 +13,7 @@ name = "float64", minParameters = 0, maxParameters = 0, - priority = BIGQUERY_PRIORITY_DATABASE + priority = LiquibaseDataType.PRIORITY_DATABASE ) public class Float64DataTypeBigQuery extends LiquibaseDataType { public Float64DataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java index 54e8aa8f..e41e1caa 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java @@ -14,7 +14,7 @@ name = "geography", minParameters = 0, maxParameters = 0, - priority = BIGQUERY_PRIORITY_DATABASE + priority = LiquibaseDataType.PRIORITY_DATABASE ) public class GeographyDataTypeBigQuery extends LiquibaseDataType { public GeographyDataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java index e5c561f0..b5803b63 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java @@ -14,7 +14,7 @@ name = "int64", minParameters = 0, maxParameters = 0, - priority = 1 + priority = LiquibaseDataType.PRIORITY_DATABASE ) public class Int64DataTypeBigQuery extends LiquibaseDataType { public Int64DataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java similarity index 85% rename from src/main/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQuery.java rename to src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java index aa3921b3..6fc3f5d8 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java @@ -12,10 +12,10 @@ name = "numeric", minParameters = 0, maxParameters = 0, - priority = 1 + priority = LiquibaseDataType.PRIORITY_DATABASE ) -public class NumberDataTypeBigQuery extends LiquibaseDataType { - public NumberDataTypeBigQuery() { +public class NumericDataTypeBigQuery extends LiquibaseDataType { + public NumericDataTypeBigQuery() { } public boolean supports(Database database) { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java index 212b2a0d..0499770d 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java @@ -7,14 +7,14 @@ import liquibase.datatype.core.VarcharType; import liquibase.ext.bigquery.database.BigqueryDatabase; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import liquibase.datatype.LiquibaseDataType; @DataTypeInfo( name = "string", minParameters = 0, maxParameters = 0, - priority = BIGQUERY_PRIORITY_DATABASE, + priority = LiquibaseDataType.PRIORITY_DATABASE, aliases = { "varchar", "clob", "java.lang.String" } ) public class StringDataTypeBigQuery extends VarcharType { diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGenerator.java index 36e80bc5..8c1bcf0a 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGenerator.java @@ -5,6 +5,7 @@ import liquibase.ext.bigquery.database.BigqueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; +import liquibase.sqlgenerator.SqlGenerator; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.ModifyDataTypeGenerator; import liquibase.statement.core.ModifyDataTypeStatement; @@ -16,6 +17,11 @@ public boolean supports(ModifyDataTypeStatement statement, Database database) { return database instanceof BigqueryDatabase; } + @Override + public int getPriority() { + return SqlGenerator.PRIORITY_DATABASE; + } + @Override public Sql[] generateSql(ModifyDataTypeStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String alterTable; diff --git a/src/main/resources/META-INF/services/liquibase.datatype.LiquibaseDataType b/src/main/resources/META-INF/services/liquibase.datatype.LiquibaseDataType index 4caddb94..dda1cedb 100644 --- a/src/main/resources/META-INF/services/liquibase.datatype.LiquibaseDataType +++ b/src/main/resources/META-INF/services/liquibase.datatype.LiquibaseDataType @@ -3,5 +3,5 @@ liquibase.ext.bigquery.datatype.core.GeographyDataTypeBigQuery liquibase.ext.bigquery.datatype.core.Float64DataTypeBigQuery liquibase.ext.bigquery.datatype.core.BoolDataTypeBigQuery liquibase.ext.bigquery.datatype.core.Int64DataTypeBigQuery -liquibase.ext.bigquery.datatype.core.NumberDataTypeBigQuery +liquibase.ext.bigquery.datatype.core.NumericDataTypeBigQuery liquibase.ext.bigquery.datatype.core.BignumericDataTypeBigQuery \ No newline at end of file From 736269e34b904d3fab2812dd83a36dd59a8973a2 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 30 May 2024 17:19:03 +0300 Subject: [PATCH 15/32] Fix merge conflicts --- .../ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java index 1e5db85b..eb3fb58a 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java @@ -2,7 +2,6 @@ import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigqueryDatabase; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -11,7 +10,7 @@ class NumberDataTypeBigQueryTest { @Test void toDatabaseDataType() { - NumberDataTypeBigQuery numberDataTypeBigQuery = new NumberDataTypeBigQuery(); + NumericDataTypeBigQuery numberDataTypeBigQuery = new NumericDataTypeBigQuery(); DatabaseDataType databaseDataType = numberDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); assertNotNull(databaseDataType); assertEquals("NUMERIC", databaseDataType.getType()); From 7274e83ebdeadf161888673da69689bf249ba890 Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 24 Apr 2024 13:43:16 -0300 Subject: [PATCH 16/32] fix: adding missed supports methods in BigQuery generators --- .../bigquery/sqlgenerator/BigQueryRenameTableGenerator.java | 4 ++++ .../ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGenerator.java index 91f30c80..2e48ac00 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGenerator.java @@ -20,6 +20,10 @@ public int getPriority() { return BIGQUERY_PRIORITY_DATABASE; } + @Override + public boolean supports(RenameTableStatement statement, Database database) { + return database instanceof BigqueryDatabase; + } @Override public Sql[] generateSql(RenameTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java index 2824fe53..54e4404f 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java @@ -1,5 +1,6 @@ package liquibase.ext.bigquery.sqlgenerator; +import liquibase.database.BigqueryDatabase; import liquibase.database.Database; import liquibase.datatype.DataTypeFactory; import liquibase.sql.Sql; @@ -23,6 +24,10 @@ public int getPriority() { return PRIORITY_DATABASE; } + @Override + public boolean supports(UpdateStatement statement, Database database) { + return database instanceof BigqueryDatabase; + } @Override public Sql[] generateSql(UpdateStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { From 0f982db32468362b111547febcd52d9e4aa2839f Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 24 Apr 2024 14:13:12 -0300 Subject: [PATCH 17/32] chore: codeql + sonar fixes --- .../ext/bigquery/database/BigqueryDatabase.java | 1 + .../datatype/core/BignumericDataTypeBigQuery.java | 12 +++++++++--- .../bigquery/datatype/core/BoolDataTypeBigQuery.java | 2 ++ .../datatype/core/Float64DataTypeBigQuery.java | 2 ++ .../datatype/core/GeographyDataTypeBigQuery.java | 2 ++ .../datatype/core/Int64DataTypeBigQuery.java | 2 ++ .../datatype/core/NumericDataTypeBigQuery.java | 2 ++ .../datatype/core/StringDataTypeBigQuery.java | 9 +++++++-- .../jvm/BigQueryDatasetSnapshotGenerator.java | 9 +++++---- .../BigQueryInsertOrUpdateGenerator.java | 4 +++- .../sqlgenerator/BigQueryRenameViewGenerator.java | 2 ++ 11 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java b/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java index e9678be9..71d76cd8 100644 --- a/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java +++ b/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java @@ -53,6 +53,7 @@ public int getPriority() { return BIGQUERY_PRIORITY_DATABASE; } + @Override public boolean supportsDatabaseChangeLogHistory() { return true; } diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java index 31ae6c01..c606514d 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java @@ -16,23 +16,29 @@ ) public class BignumericDataTypeBigQuery extends LiquibaseDataType { - private final static String BIGNUMERIC = "BIGNUMERIC"; + private static final String BIGNUMERIC = "BIGNUMERIC"; public BignumericDataTypeBigQuery() { } + @Override public boolean supports(Database database) { return database instanceof BigqueryDatabase; } + @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof BigqueryDatabase) { DatabaseDataType type = new DatabaseDataType(BIGNUMERIC, this.getParameters()); if (this.getParameters().length > 0) { String firstParameter = String.valueOf(this.getParameters()[0]); - int typePrecision = Integer.parseInt(firstParameter); - if (typePrecision == 77) { + try { + int typePrecision = Integer.parseInt(firstParameter); + if (typePrecision == 77) { + type.setType(BIGNUMERIC); + } + } catch (NumberFormatException e) { type.setType(BIGNUMERIC); } } diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java index 93444618..473c8997 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java @@ -20,10 +20,12 @@ public class BoolDataTypeBigQuery extends LiquibaseDataType { public BoolDataTypeBigQuery() { } + @Override public boolean supports(Database database) { return database instanceof BigqueryDatabase; } + @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof BigqueryDatabase) { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java index 3eb14edb..342cf2d2 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java @@ -19,10 +19,12 @@ public class Float64DataTypeBigQuery extends LiquibaseDataType { public Float64DataTypeBigQuery() { } + @Override public boolean supports(Database database) { return database instanceof BigqueryDatabase; } + @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof BigqueryDatabase) { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java index e41e1caa..ed9cf1ec 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java @@ -20,10 +20,12 @@ public class GeographyDataTypeBigQuery extends LiquibaseDataType { public GeographyDataTypeBigQuery() { } + @Override public boolean supports(Database database) { return database instanceof BigqueryDatabase; } + @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof BigqueryDatabase) { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java index b5803b63..f4d7982c 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java @@ -20,10 +20,12 @@ public class Int64DataTypeBigQuery extends LiquibaseDataType { public Int64DataTypeBigQuery() { } + @Override public boolean supports(Database database) { return database instanceof BigqueryDatabase; } + @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof BigqueryDatabase) { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java index 6fc3f5d8..ee7a5690 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java @@ -18,10 +18,12 @@ public class NumericDataTypeBigQuery extends LiquibaseDataType { public NumericDataTypeBigQuery() { } + @Override public boolean supports(Database database) { return database instanceof BigqueryDatabase; } + @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof BigqueryDatabase) { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java index 0499770d..eb9302fe 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java @@ -35,8 +35,12 @@ public DatabaseDataType toDatabaseDataType(Database database) { type.setType("STRING"); } else { String firstParameter = String.valueOf(this.getParameters()[0]); - int stringSize = Integer.parseInt(firstParameter); - if (stringSize == 65535) { + try { + int stringSize = Integer.parseInt(firstParameter); + if (stringSize == 65535) { + type.setType("STRING"); + } + } catch (NumberFormatException e) { type.setType("STRING"); } } @@ -57,6 +61,7 @@ public String objectToSql(Object value, Database database) { } } + @Override public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.STRING; } diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryDatasetSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryDatasetSnapshotGenerator.java index 7e86d12e..7b06e72f 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryDatasetSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryDatasetSnapshotGenerator.java @@ -13,6 +13,7 @@ import liquibase.structure.DatabaseObject; import liquibase.structure.core.Catalog; import liquibase.structure.core.Schema; +import liquibase.util.JdbcUtil; import liquibase.util.JdbcUtils; import java.sql.ResultSet; @@ -44,7 +45,7 @@ protected String[] getDatabaseSchemaNames(Database database) throws SQLException .getSchemas(database.getDefaultCatalogName(), null); while (schemas.next()) { - returnList.add(JdbcUtils.getValueForColumn(schemas, "TABLE_SCHEM", database)); + returnList.add(JdbcUtil.getValueForColumn(schemas, "TABLE_SCHEM", database)); } } finally { if (schemas != null) { @@ -62,7 +63,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot String catalogName = ((Schema) example).getCatalogName(); String schemaName = example.getName(); - if (database.supportsSchemas()) { + if (database.supports(Schema.class)) { if (catalogName == null) { catalogName = database.getDefaultCatalogName(); } @@ -70,7 +71,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot if (schemaName == null) { schemaName = database.getDefaultSchemaName(); } - } else if (database.supportsCatalogs()) { + } else if (database.supports(Catalog.class)) { if (catalogName == null && schemaName != null) { catalogName = schemaName; schemaName = null; @@ -85,7 +86,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot database.setObjectQuotingStrategy(ObjectQuotingStrategy.LEGACY); try { - if (database.supportsSchemas()) { + if (database.supports(Schema.class)) { String[] schemaNames = this.getDatabaseSchemaNames(database); for (String tableSchema : schemaNames) { diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java index 4f6ad20d..598c954d 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java @@ -7,11 +7,13 @@ import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.InsertOrUpdateGenerator; import liquibase.statement.core.InsertOrUpdateStatement; +import liquibase.util.StringUtil; public class BigQueryInsertOrUpdateGenerator extends InsertOrUpdateGenerator { public BigQueryInsertOrUpdateGenerator() { } + @Override public boolean supports(InsertOrUpdateStatement statement, Database database) { return database instanceof BigqueryDatabase; } @@ -54,7 +56,7 @@ protected String getUpdateStatement(InsertOrUpdateStatement insertOrUpdateStatem @Override protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { - if (whereClause == null || "".equals(whereClause)) { + if (StringUtil.isEmpty(whereClause)) { whereClause = "WHERE 1 = 1"; } return "MERGE INTO " + insertOrUpdateStatement.getTableName() + " USING (SELECT 1) ON " + whereClause + " WHEN NOT MATCHED THEN "; diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGenerator.java index 7f9be720..cb287082 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGenerator.java @@ -21,10 +21,12 @@ public int getPriority() { } + @Override public boolean supports(RenameViewStatement statement, Database database) { return database instanceof BigqueryDatabase; } + @Override public Sql[] generateSql(RenameViewStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { return new Sql[]{new UnparsedSql("ALTER VIEW " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getOldViewName()) + " RENAME TO " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getNewViewName()), new DatabaseObject[]{this.getAffectedOldView(statement), this.getAffectedNewView(statement)})}; } From 32834abb688a82db178987fd5d4f8c67e86a4b1e Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 24 Apr 2024 15:03:43 -0300 Subject: [PATCH 18/32] chore: codeql + sonar fixes --- ...ueryUniqueConstraintSnapshotGenerator.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java index 440cff41..c02ed01d 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java @@ -9,7 +9,7 @@ import liquibase.snapshot.DatabaseSnapshot; import liquibase.snapshot.SnapshotGenerator; import liquibase.snapshot.jvm.UniqueConstraintSnapshotGenerator; -import liquibase.statement.core.RawSqlStatement; +import liquibase.statement.core.RawParameterizedSqlStatement; import liquibase.structure.DatabaseObject; import liquibase.structure.core.*; @@ -52,20 +52,30 @@ protected List listConstraints(Table table, DatabaseSnapshot snapshot String constraintName = database.correctObjectName(name, UniqueConstraint.class); String tableName = database.correctObjectName(table.getName(), Table.class); - String sql = "select CONSTRAINT_NAME, CONSTRAINT_NAME as COLUMN_NAME FROM " + database.getSystemSchema() + ".TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE='UNIQUE'"; + List parameters = new ArrayList<>(); + + StringBuilder sqlBuilder = new StringBuilder(); + sqlBuilder.append("select CONSTRAINT_NAME, COLUMN_NAME FROM ") + .append(database.getSystemSchema()) + .append(".TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE='UNIQUE'"); + if (schemaName != null) { - sql = sql + "and CONSTRAINT_SCHEMA='" + schemaName + "' "; + sqlBuilder.append("and CONSTRAINT_SCHEMA=? "); + parameters.add(schemaName); } if (tableName != null) { - sql = sql + "AND TABLE_NAME='" + tableName + "' "; + sqlBuilder.append("and TABLE_NAME=? "); + parameters.add(tableName); } if (constraintName != null) { - sql = sql + "AND CONSTRAINT_NAME='" + constraintName + "'"; + sqlBuilder.append("and CONSTRAINT_NAME=? "); + parameters.add(constraintName); } - return Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database).queryForList(new RawSqlStatement(sql)); + return Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database) + .queryForList(new RawParameterizedSqlStatement(sqlBuilder.toString(), parameters.toArray())); } } From ad688a44e1455de6814b78b1c93c5fd94c96ab6b Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 24 Apr 2024 16:23:42 -0300 Subject: [PATCH 19/32] chore:fix sonar critical alerts --- .../ext/bigquery/change/BigQueryMergeColumnChange.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChange.java b/src/main/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChange.java index 6b7ff759..002f31b3 100644 --- a/src/main/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChange.java +++ b/src/main/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChange.java @@ -1,13 +1,13 @@ package liquibase.ext.bigquery.change; import liquibase.change.AddColumnConfig; -import liquibase.change.ChangeMetaData; import liquibase.change.DatabaseChange; import liquibase.change.core.AddColumnChange; import liquibase.change.core.DropColumnChange; import liquibase.change.core.MergeColumnChange; import liquibase.database.Database; import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import liquibase.statement.core.RawSqlStatement; import liquibase.structure.core.Column; @@ -18,7 +18,7 @@ @DatabaseChange(name="mergeColumns", description = "Concatenates the values in two columns, joins them by with string, and stores the resulting value in a new column.", - priority = ChangeMetaData.PRIORITY_DATABASE) + priority = PrioritizedService.PRIORITY_DATABASE) public class BigQueryMergeColumnChange extends MergeColumnChange { @Override From 5a96705a7e79d4d0ec10a5551c24c70ef10c826a Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 24 Apr 2024 17:08:00 -0300 Subject: [PATCH 20/32] chore: fix some sonar medium alerts --- .../ext/bigquery/database/BigqueryConnection.java | 13 +++++-------- .../sqlgenerator/BigQueryUpdateGenerator.java | 8 ++++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java b/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java index 682efd49..3fdfa2ec 100644 --- a/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java +++ b/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java @@ -20,6 +20,7 @@ */ public class BigqueryConnection extends JdbcConnection { + private static final String LOCATION = "Location"; private S42Connection con; public BigqueryConnection() { @@ -78,16 +79,11 @@ public String getUnderlyingBQConnectionLocation() { return bc == null ? "" : bc.getSettings().m_location; } - @Override - public Connection getUnderlyingConnection() { - return con; - } - @Override public void open(String url, Driver driverObject, Properties driverProperties) throws DatabaseException { - if (driverProperties.stringPropertyNames().contains("Location")) { - String locationValue = getUrlParamValue(url, "Location"); - driverProperties.setProperty("Location", locationValue); + if (!driverProperties.stringPropertyNames().contains(LOCATION)) { + String locationValue = getUrlParamValue(url, LOCATION, "US"); + driverProperties.setProperty(LOCATION, locationValue); } Scope.getCurrentScope().getLog(this.getClass()).fine(String.format("Opening connection to %s driverProperties=%s", url, driverProperties)); @@ -124,6 +120,7 @@ public boolean getAutoCommit() throws DatabaseException { @Override public void setAutoCommit(boolean autoCommit) throws DatabaseException { + // not supported by BigQuery } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java index 54e4404f..9763a552 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java @@ -5,10 +5,10 @@ import liquibase.datatype.DataTypeFactory; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; -import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.UpdateGenerator; import liquibase.statement.DatabaseFunction; import liquibase.statement.core.UpdateStatement; +import liquibase.util.BooleanUtil; import liquibase.util.SqlUtil; import java.util.Date; @@ -39,7 +39,7 @@ public Sql[] generateSql(UpdateStatement statement, Database database, SqlGenera sql.append(" ") .append(database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), column)) .append(" = ") - .append(this.convertToString(statement.getNewColumnValues().get(column), database)) + .append(this.convert(statement.getNewColumnValues().get(column), database)) .append(","); } @@ -59,7 +59,7 @@ public Sql[] generateSql(UpdateStatement statement, Database database, SqlGenera }; } - private String convertToString(Object newValue, Database database) { + private String convert(Object newValue, Database database) { String sqlString; if ((newValue == null) || "NULL".equalsIgnoreCase(newValue.toString())) { sqlString = "NULL"; @@ -74,7 +74,7 @@ private String convertToString(Object newValue, Database database) { sqlString = database.getDateLiteral(date); } else if (newValue instanceof Boolean) { - if (((Boolean) newValue)) { + if (BooleanUtil.isTrue((Boolean) newValue)) { sqlString = DataTypeFactory.getInstance().getTrueBooleanValue(database); } else { sqlString = DataTypeFactory.getInstance().getFalseBooleanValue(database); From 588c996c4206140598006116b1c9e201ba37179c Mon Sep 17 00:00:00 2001 From: filipe Date: Thu, 25 Apr 2024 14:46:21 -0300 Subject: [PATCH 21/32] fix: re-add required method --- .../liquibase/ext/bigquery/database/BigqueryConnection.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java b/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java index 3fdfa2ec..b2b7f3d4 100644 --- a/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java +++ b/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java @@ -79,6 +79,11 @@ public String getUnderlyingBQConnectionLocation() { return bc == null ? "" : bc.getSettings().m_location; } + @Override + public Connection getUnderlyingConnection() { + return con; + } + @Override public void open(String url, Driver driverObject, Properties driverProperties) throws DatabaseException { if (!driverProperties.stringPropertyNames().contains(LOCATION)) { From 5c3785e6330a0094ef3dfd7e56e89d4515d81080 Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 1 May 2024 11:46:13 -0300 Subject: [PATCH 22/32] fix: implement new Supports method --- .../ext/bigquery/database/BigqueryDatabase.java | 13 +++++++++++-- .../jvm/BigQuerySequenceSnapshotGenerator.java | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java b/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java index 71d76cd8..149545eb 100644 --- a/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java +++ b/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java @@ -13,6 +13,7 @@ import liquibase.structure.DatabaseObject; import liquibase.structure.core.Catalog; import liquibase.structure.core.Schema; +import liquibase.structure.core.Sequence; import liquibase.structure.core.Table; import java.util.HashSet; @@ -94,6 +95,14 @@ public int getDatabaseMinorVersion() { return BQDriver.DRIVER_MINOR_VERSION; } + @Override + public boolean supports(Class object) { + if (Sequence.class.isAssignableFrom(object)) { + return false; + } + return super.supports(object); + } + @Override public boolean supportsInitiallyDeferrableColumns() { return false; @@ -142,7 +151,7 @@ public String getDefaultDriver(String url) { @Override public boolean supportsSequences() { - return false; + return this.supports(Sequence.class); } @Override @@ -223,7 +232,7 @@ public String getJdbcCatalogName(final CatalogAndSchema schema) { @Override public String getViewDefinition(CatalogAndSchema schema, String viewName) throws DatabaseException { schema = schema.customize(this); - String definition = (String) ((ExecutorService) Scope.getCurrentScope().getSingleton(ExecutorService.class)) + String definition = (Scope.getCurrentScope().getSingleton(ExecutorService.class)) .getExecutor("jdbc", this) .queryForObject(new GetViewDefinitionStatement(schema.getCatalogName(), schema.getSchemaName(), viewName), String.class); Scope.getCurrentScope().getLog(this.getClass()).info("getViewDefinition "+definition); diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQuerySequenceSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQuerySequenceSnapshotGenerator.java index 0003351f..4fdfd6cd 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQuerySequenceSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQuerySequenceSnapshotGenerator.java @@ -51,7 +51,7 @@ protected SqlStatement getSelectSequenceStatement(Schema schema, Database databa return new RawSqlStatement( "SELECT NULL AS SEQUENCE_NAME, NULL AS START_VALUE, NULL AS AS MIN_VALUE, NULL AS MAX_VALUE, " + "NULL AS INCREMENT_BY, " + - "NULL AS WILL_CYCLE " + + "NULL AS WILL_CYCLE FROM " + jdbcSchemaName + "." + database.getSystemSchema().toUpperCase() + ".COLUMNS WHERE 1=0"); } return super.getSelectSequenceStatement(schema, database); From 0e02b37be5f37e2164447f1cb49e63731589a0b0 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 30 May 2024 15:46:16 +0300 Subject: [PATCH 23/32] chore: renamed all occurrences of Bigquery to BigQuery --- .../bigquery/change/BigQueryMergeColumnChange.java | 4 ++-- ...igqueryConnection.java => BigQueryConnection.java} | 8 ++++---- .../{BigqueryDatabase.java => BigQueryDatabase.java} | 6 +++--- .../datatype/core/BignumericDataTypeBigQuery.java | 6 +++--- .../bigquery/datatype/core/BoolDataTypeBigQuery.java | 8 ++++---- .../datatype/core/Float64DataTypeBigQuery.java | 8 ++++---- .../datatype/core/GeographyDataTypeBigQuery.java | 8 ++++---- .../bigquery/datatype/core/Int64DataTypeBigQuery.java | 8 +++----- .../datatype/core/NumericDataTypeBigQuery.java | 6 +++--- .../datatype/core/StringDataTypeBigQuery.java | 6 +++--- .../core/BigQueryChangedTableChangeGenerator.java | 4 ++-- .../{BigqueryExecutor.java => BigQueryExecutor.java} | 8 ++++---- .../jvm/BigQueryDatasetSnapshotGenerator.java | 7 +++---- .../jvm/BigQueryForeignKeySnapshotGenerator.java | 4 ++-- .../jvm/BigQueryPrimaryKeySnapshotGenerator.java | 4 ++-- .../jvm/BigQuerySequenceSnapshotGenerator.java | 8 ++++---- .../BigQueryUniqueConstraintSnapshotGenerator.java | 6 +++--- .../snapshot/jvm/BigQueryViewSnapshotGenerator.java | 6 +++--- .../sqlgenerator/BigQueryAddColumnGenerator.java | 6 +++--- .../BigQueryAddForeignKeyConstraintGenerator.java | 5 ++--- .../BigQueryAddPrimaryKeyConstraintGenerator.java | 4 ++-- ...eryCreateDatabaseChangeLogLockTableGenerator.java} | 8 ++++---- ...igQueryCreateDatabaseChangeLogTableGenerator.java} | 8 ++++---- .../sqlgenerator/BigQueryCreateTableGenerator.java | 6 +++--- ...eteGenerator.java => BigQueryDeleteGenerator.java} | 8 ++++---- .../sqlgenerator/BigQueryInsertOrUpdateGenerator.java | 4 ++-- .../sqlgenerator/BigQueryModifyDataTypeGenerator.java | 4 ++-- .../sqlgenerator/BigQueryRenameTableGenerator.java | 8 +++----- .../sqlgenerator/BigQueryRenameViewGenerator.java | 6 +++--- .../sqlgenerator/BigQuerySetNullableGenerator.java | 4 ++-- .../sqlgenerator/BigQueryUpdateGenerator.java | 5 +++-- .../META-INF/services/liquibase.database.Database | 2 +- .../services/liquibase.database.DatabaseConnection | 2 +- .../META-INF/services/liquibase.executor.Executor | 2 +- .../services/liquibase.sqlgenerator.SqlGenerator | 8 +++++--- ...atabaseTest.groovy => BigQueryDatabaseTest.groovy} | 4 ++-- .../change/BigQueryMergeColumnChangeTest.java | 6 +++--- .../bigquery/database/BigqueryDatabaseUnitTest.java | 4 ++-- .../datatype/core/BignumericDataTypeBigQueryTest.java | 4 ++-- .../datatype/core/BoolDataTypeBigQueryTest.java | 4 ++-- .../datatype/core/Float64DataTypeBigQueryTest.java | 5 ++--- .../datatype/core/GeographyDataTypeBigQueryTest.java | 5 ++--- .../datatype/core/Int64DataTypeBigQueryTest.java | 5 ++--- .../datatype/core/NumberDataTypeBigQueryTest.java | 4 ++-- .../datatype/core/StringDataTypeBigQueryTest.java | 9 ++++----- .../sqlgenerator/BigQueryAddColumnGeneratorTest.java | 8 +++----- .../BigQueryAddForeignKeyConstraintGeneratorTest.java | 6 +++--- .../BigQueryAddPrimaryKeyConstraintGeneratorTest.java | 6 +++--- .../BigQueryCreateTableGeneratorTest.java | 7 +++---- .../BigQueryInsertOrUpdateGeneratorTest.java | 7 +++---- .../BigQueryModifyDataTypeGeneratorTest.java | 7 +++---- .../BigQueryRenameTableGeneratorTest.java | 7 +++---- .../sqlgenerator/BigQueryRenameViewGeneratorTest.java | 7 +++---- .../BigQuerySetNullableGeneratorTest.java | 7 +++---- .../sqlgenerator/BigQueryUpdateGeneratorTest.java | 10 ++++------ ...CreateDatabaseChangeLogLockTableGeneratorTest.java | 11 +++++------ .../sqlgenerator/BigqueryDeleteGeneratorTest.java | 11 +++++------ 57 files changed, 165 insertions(+), 184 deletions(-) rename src/main/java/liquibase/ext/bigquery/database/{BigqueryConnection.java => BigQueryConnection.java} (98%) rename src/main/java/liquibase/ext/bigquery/database/{BigqueryDatabase.java => BigQueryDatabase.java} (98%) rename src/main/java/liquibase/ext/bigquery/executor/{BigqueryExecutor.java => BigQueryExecutor.java} (76%) rename src/main/java/liquibase/ext/bigquery/sqlgenerator/{BigqueryCreateDatabaseChangeLogLockTableGenerator.java => BigQueryCreateDatabaseChangeLogLockTableGenerator.java} (91%) rename src/main/java/liquibase/ext/bigquery/sqlgenerator/{BigqueryCreateDatabaseChangeLogTableGenerator.java => BigQueryCreateDatabaseChangeLogTableGenerator.java} (72%) rename src/main/java/liquibase/ext/bigquery/sqlgenerator/{BigqueryDeleteGenerator.java => BigQueryDeleteGenerator.java} (85%) rename src/test/groovy/liquibase/ext/bigquery/database/{BigqueryDatabaseTest.groovy => BigQueryDatabaseTest.groovy} (65%) diff --git a/src/main/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChange.java b/src/main/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChange.java index 002f31b3..7337abb1 100644 --- a/src/main/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChange.java +++ b/src/main/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChange.java @@ -6,7 +6,7 @@ import liquibase.change.core.DropColumnChange; import liquibase.change.core.MergeColumnChange; import liquibase.database.Database; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import liquibase.statement.core.RawSqlStatement; @@ -23,7 +23,7 @@ public class BigQueryMergeColumnChange extends MergeColumnChange { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java b/src/main/java/liquibase/ext/bigquery/database/BigQueryConnection.java similarity index 98% rename from src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java rename to src/main/java/liquibase/ext/bigquery/database/BigQueryConnection.java index b2b7f3d4..e989a2a8 100644 --- a/src/main/java/liquibase/ext/bigquery/database/BigqueryConnection.java +++ b/src/main/java/liquibase/ext/bigquery/database/BigQueryConnection.java @@ -13,20 +13,20 @@ import java.util.Optional; import java.util.Properties; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; /** * A Bigquery specific Delegate that removes the calls to autocommit */ -public class BigqueryConnection extends JdbcConnection { +public class BigQueryConnection extends JdbcConnection { private static final String LOCATION = "Location"; private S42Connection con; - public BigqueryConnection() { + public BigQueryConnection() { } - public BigqueryConnection(Connection conn) throws SQLException { + public BigQueryConnection(Connection conn) throws SQLException { this.con = (S42Connection) conn; String url = conn.getMetaData().getURL(); Scope.getCurrentScope().getLog(this.getClass()).fine(String.format("Setting connection to %s Location=%s", url, getUnderlyingBQConnectionLocation())); diff --git a/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java b/src/main/java/liquibase/ext/bigquery/database/BigQueryDatabase.java similarity index 98% rename from src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java rename to src/main/java/liquibase/ext/bigquery/database/BigQueryDatabase.java index 149545eb..685e9ac7 100644 --- a/src/main/java/liquibase/ext/bigquery/database/BigqueryDatabase.java +++ b/src/main/java/liquibase/ext/bigquery/database/BigQueryDatabase.java @@ -20,7 +20,7 @@ import java.util.Set; import java.util.regex.Pattern; -public class BigqueryDatabase extends AbstractJdbcDatabase { +public class BigQueryDatabase extends AbstractJdbcDatabase { public static final String PRODUCT_NAME = BQDriver.DATABASE_NAME; public static final int BIGQUERY_PRIORITY_DATABASE = 510; @@ -28,7 +28,7 @@ public class BigqueryDatabase extends AbstractJdbcDatabase { private static final Pattern CREATE_VIEW_AS_PATTERN = Pattern.compile("^CREATE\\s+.*?VIEW\\s+.*?AS\\s+", 34); - public BigqueryDatabase() { + public BigQueryDatabase() { this.setCurrentDateTimeFunction("CURRENT_DATETIME()"); this.unquotedObjectsAreUppercased = false; this.addReservedWords(getDefaultReservedWords()); @@ -174,7 +174,7 @@ private String getDefaultDataset() { if (connection == null) { return null; } - return BigqueryConnection.getUrlParamValue(connection.getURL(), "DefaultDataset"); + return BigQueryConnection.getUrlParamValue(connection.getURL(), "DefaultDataset"); } @Override diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java index c606514d..03ca918f 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java @@ -5,7 +5,7 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; @DataTypeInfo( @@ -23,12 +23,12 @@ public BignumericDataTypeBigQuery() { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { DatabaseDataType type = new DatabaseDataType(BIGNUMERIC, this.getParameters()); if (this.getParameters().length > 0) { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java index 473c8997..04fe4740 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java @@ -5,9 +5,9 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; @DataTypeInfo( @@ -22,12 +22,12 @@ public BoolDataTypeBigQuery() { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { DatabaseDataType type = new DatabaseDataType("BOOL", this.getParameters()); type.setType("BOOL"); diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java index 342cf2d2..c5824768 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java @@ -5,9 +5,9 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; @DataTypeInfo( name = "float64", @@ -21,12 +21,12 @@ public Float64DataTypeBigQuery() { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { DatabaseDataType type = new DatabaseDataType("FLOAT64", this.getParameters()); type.setType("FLOAT64"); diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java index ed9cf1ec..4bbdf9bd 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java @@ -5,9 +5,9 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; @DataTypeInfo( @@ -22,12 +22,12 @@ public GeographyDataTypeBigQuery() { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { DatabaseDataType type = new DatabaseDataType("GEOGRAPHY", this.getParameters()); type.setType("GEOGRAPHY"); diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java index f4d7982c..4afacc61 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java @@ -5,9 +5,7 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; - -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import liquibase.ext.bigquery.database.BigQueryDatabase; @DataTypeInfo( @@ -22,12 +20,12 @@ public Int64DataTypeBigQuery() { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { DatabaseDataType type = new DatabaseDataType("INT64", this.getParameters()); type.setType("INT64"); diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java index ee7a5690..1e0d5848 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java @@ -5,7 +5,7 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; @DataTypeInfo( @@ -20,12 +20,12 @@ public NumericDataTypeBigQuery() { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { return new DatabaseDataType("NUMERIC", this.getParameters()); } else { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java index eb9302fe..7824d5ed 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java @@ -5,7 +5,7 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.core.VarcharType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.datatype.LiquibaseDataType; @@ -23,12 +23,12 @@ public StringDataTypeBigQuery() { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { DatabaseDataType type = new DatabaseDataType("STRING", this.getParameters()); if (this.getParameters().length == 0) { diff --git a/src/main/java/liquibase/ext/bigquery/diff/output/changelog/core/BigQueryChangedTableChangeGenerator.java b/src/main/java/liquibase/ext/bigquery/diff/output/changelog/core/BigQueryChangedTableChangeGenerator.java index e7f1ff06..c41cf7f9 100644 --- a/src/main/java/liquibase/ext/bigquery/diff/output/changelog/core/BigQueryChangedTableChangeGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/diff/output/changelog/core/BigQueryChangedTableChangeGenerator.java @@ -9,7 +9,7 @@ import liquibase.diff.output.DiffOutputControl; import liquibase.diff.output.changelog.ChangeGeneratorChain; import liquibase.diff.output.changelog.core.ChangedTableChangeGenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.structure.DatabaseObject; import liquibase.structure.core.Table; @@ -21,7 +21,7 @@ public BigQueryChangedTableChangeGenerator() { @Override public int getPriority(Class objectType, Database database) { int priority = super.getPriority(objectType, database); - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { priority += PRIORITY_DATABASE; } return priority; diff --git a/src/main/java/liquibase/ext/bigquery/executor/BigqueryExecutor.java b/src/main/java/liquibase/ext/bigquery/executor/BigQueryExecutor.java similarity index 76% rename from src/main/java/liquibase/ext/bigquery/executor/BigqueryExecutor.java rename to src/main/java/liquibase/ext/bigquery/executor/BigQueryExecutor.java index 36e1f2ef..b4634a44 100644 --- a/src/main/java/liquibase/ext/bigquery/executor/BigqueryExecutor.java +++ b/src/main/java/liquibase/ext/bigquery/executor/BigQueryExecutor.java @@ -3,15 +3,15 @@ import liquibase.database.Database; import liquibase.exception.DatabaseException; import liquibase.executor.jvm.JdbcExecutor; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.visitor.SqlVisitor; import liquibase.statement.SqlStatement; import java.util.List; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; -public class BigqueryExecutor extends JdbcExecutor { +public class BigQueryExecutor extends JdbcExecutor { @Override public int getPriority() { @@ -20,7 +20,7 @@ public int getPriority() { @Override public boolean supports(Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryDatasetSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryDatasetSnapshotGenerator.java index 7b06e72f..208aa749 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryDatasetSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryDatasetSnapshotGenerator.java @@ -6,7 +6,7 @@ import liquibase.database.jvm.JdbcConnection; import liquibase.diff.compare.DatabaseObjectComparatorFactory; import liquibase.exception.DatabaseException; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.snapshot.DatabaseSnapshot; import liquibase.snapshot.InvalidExampleException; import liquibase.snapshot.jvm.SchemaSnapshotGenerator; @@ -14,7 +14,6 @@ import liquibase.structure.core.Catalog; import liquibase.structure.core.Schema; import liquibase.util.JdbcUtil; -import liquibase.util.JdbcUtils; import java.sql.ResultSet; import java.sql.SQLException; @@ -25,11 +24,11 @@ public class BigQueryDatasetSnapshotGenerator extends SchemaSnapshotGenerator { @Override public int getPriority(Class objectType, Database database) { - if (!(database instanceof BigqueryDatabase)) { + if (!(database instanceof BigQueryDatabase)) { return PRIORITY_NONE; } int priority = super.getPriority(objectType, database); - if (priority > PRIORITY_NONE && database instanceof BigqueryDatabase) { + if (priority > PRIORITY_NONE && database instanceof BigQueryDatabase) { priority += PRIORITY_DATABASE; } return priority; diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java index ec0c8159..706fa90f 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryForeignKeySnapshotGenerator.java @@ -6,7 +6,7 @@ import liquibase.database.Database; import liquibase.exception.DatabaseException; import liquibase.executor.ExecutorService; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.snapshot.DatabaseSnapshot; import liquibase.snapshot.SnapshotGenerator; import liquibase.snapshot.jvm.ForeignKeySnapshotGenerator; @@ -20,7 +20,7 @@ public class BigQueryForeignKeySnapshotGenerator extends ForeignKeySnapshotGener @Override public int getPriority(Class objectType, Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { return super.getPriority(objectType, database) + PRIORITY_DATABASE; } else { return PRIORITY_NONE; diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryPrimaryKeySnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryPrimaryKeySnapshotGenerator.java index 72c18728..360f78d5 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryPrimaryKeySnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryPrimaryKeySnapshotGenerator.java @@ -6,7 +6,7 @@ import liquibase.exception.DatabaseException; import liquibase.executor.Executor; import liquibase.executor.ExecutorService; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.snapshot.DatabaseSnapshot; import liquibase.snapshot.InvalidExampleException; import liquibase.snapshot.SnapshotGenerator; @@ -27,7 +27,7 @@ public class BigQueryPrimaryKeySnapshotGenerator extends PrimaryKeySnapshotGener @Override public int getPriority(Class objectType, Database database) { - if (!(database instanceof BigqueryDatabase)) { + if (!(database instanceof BigQueryDatabase)) { return PRIORITY_NONE; } int priority = super.getPriority(objectType, database); diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQuerySequenceSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQuerySequenceSnapshotGenerator.java index 4fdfd6cd..ea860b2e 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQuerySequenceSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQuerySequenceSnapshotGenerator.java @@ -5,7 +5,7 @@ import liquibase.database.AbstractJdbcDatabase; import liquibase.database.Database; import liquibase.exception.DatabaseException; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.snapshot.DatabaseSnapshot; import liquibase.snapshot.SnapshotGenerator; import liquibase.snapshot.jvm.SequenceSnapshotGenerator; @@ -18,11 +18,11 @@ public class BigQuerySequenceSnapshotGenerator extends SequenceSnapshotGenerator @Override public int getPriority(Class objectType, Database database) { - if (!(database instanceof BigqueryDatabase)) { + if (!(database instanceof BigQueryDatabase)) { return PRIORITY_NONE; } int priority = super.getPriority(objectType, database); - if (priority > PRIORITY_NONE && database instanceof BigqueryDatabase) { + if (priority > PRIORITY_NONE && database instanceof BigQueryDatabase) { priority += PRIORITY_DATABASE; } return priority; @@ -41,7 +41,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot @Override protected SqlStatement getSelectSequenceStatement(Schema schema, Database database) { - if (database instanceof BigqueryDatabase) { + if (database instanceof BigQueryDatabase) { // BigQuery does not support sequences //String catalog = database.getDefaultCatalogName(); CatalogAndSchema catalogAndSchema = (new CatalogAndSchema(schema.getCatalogName(), schema.getName())).customize(database); diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java index c02ed01d..066c4832 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryUniqueConstraintSnapshotGenerator.java @@ -4,7 +4,7 @@ import liquibase.database.Database; import liquibase.exception.DatabaseException; import liquibase.executor.ExecutorService; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.snapshot.CachedRow; import liquibase.snapshot.DatabaseSnapshot; import liquibase.snapshot.SnapshotGenerator; @@ -22,11 +22,11 @@ public class BigQueryUniqueConstraintSnapshotGenerator extends UniqueConstraintS @Override public int getPriority(Class objectType, Database database) { - if (!(database instanceof BigqueryDatabase)) { + if (!(database instanceof BigQueryDatabase)) { return PRIORITY_NONE; } int priority = super.getPriority(objectType, database); - if (priority > PRIORITY_NONE && database instanceof BigqueryDatabase) { + if (priority > PRIORITY_NONE && database instanceof BigQueryDatabase) { priority += PRIORITY_DATABASE; } return priority; diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java index 11d0252f..1b89dcd9 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java @@ -6,7 +6,7 @@ import liquibase.database.Database; import liquibase.exception.DatabaseException; import liquibase.executor.ExecutorService; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.snapshot.DatabaseSnapshot; import liquibase.snapshot.jvm.ViewSnapshotGenerator; import liquibase.statement.core.RawSqlStatement; @@ -23,11 +23,11 @@ public class BigQueryViewSnapshotGenerator extends ViewSnapshotGenerator { @Override public int getPriority(Class objectType, Database database) { - if (!(database instanceof BigqueryDatabase)) { + if (!(database instanceof BigQueryDatabase)) { return PRIORITY_NONE; } int priority = super.getPriority(objectType, database); - if (priority > PRIORITY_NONE && database instanceof BigqueryDatabase) { + if (priority > PRIORITY_NONE && database instanceof BigQueryDatabase) { priority += PRIORITY_DATABASE; } return priority; diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGenerator.java index 5dbfb030..c14fbd8c 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGenerator.java @@ -1,12 +1,12 @@ package liquibase.ext.bigquery.sqlgenerator; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; import liquibase.Scope; import liquibase.database.Database; import liquibase.datatype.DataTypeFactory; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sqlgenerator.core.AddColumnGenerator; import liquibase.statement.AutoIncrementConstraint; import liquibase.statement.core.AddColumnStatement; @@ -71,6 +71,6 @@ public int getPriority() { @Override public boolean supports(AddColumnStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } } diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGenerator.java index 23eea1d3..eb907500 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGenerator.java @@ -1,8 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.database.Database; -import liquibase.database.core.*; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGenerator; @@ -19,7 +18,7 @@ public int getPriority() { @Override public boolean supports(AddForeignKeyConstraintStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGenerator.java index cba13f40..44b0bcfe 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGenerator.java @@ -1,7 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.database.Database; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGenerator; @@ -18,7 +18,7 @@ public int getPriority() { @Override public boolean supports(AddPrimaryKeyStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateDatabaseChangeLogLockTableGenerator.java similarity index 91% rename from src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGenerator.java rename to src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateDatabaseChangeLogLockTableGenerator.java index bd9f54b1..4ec99d97 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateDatabaseChangeLogLockTableGenerator.java @@ -3,7 +3,7 @@ import liquibase.database.Database; import liquibase.database.ObjectQuotingStrategy; import liquibase.datatype.DataTypeFactory; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.SqlGeneratorFactory; @@ -12,9 +12,9 @@ import liquibase.statement.core.CreateDatabaseChangeLogLockTableStatement; import liquibase.statement.core.CreateTableStatement; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; -public class BigqueryCreateDatabaseChangeLogLockTableGenerator extends CreateDatabaseChangeLogLockTableGenerator { +public class BigQueryCreateDatabaseChangeLogLockTableGenerator extends CreateDatabaseChangeLogLockTableGenerator { @Override public int getPriority() { @@ -23,7 +23,7 @@ public int getPriority() { @Override public boolean supports(CreateDatabaseChangeLogLockTableStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogTableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateDatabaseChangeLogTableGenerator.java similarity index 72% rename from src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogTableGenerator.java rename to src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateDatabaseChangeLogTableGenerator.java index 32047f6a..c13da36e 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogTableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateDatabaseChangeLogTableGenerator.java @@ -1,13 +1,13 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.database.Database; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sqlgenerator.core.CreateDatabaseChangeLogTableGenerator; import liquibase.statement.core.CreateDatabaseChangeLogTableStatement; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; -public class BigqueryCreateDatabaseChangeLogTableGenerator extends CreateDatabaseChangeLogTableGenerator { +public class BigQueryCreateDatabaseChangeLogTableGenerator extends CreateDatabaseChangeLogTableGenerator { @Override public int getPriority() { @@ -16,7 +16,7 @@ public int getPriority() { @Override public boolean supports(CreateDatabaseChangeLogTableStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java index ff611e7e..af90e224 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java @@ -3,7 +3,7 @@ import liquibase.Scope; import liquibase.database.Database; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; @@ -19,7 +19,7 @@ import java.util.Iterator; import java.util.List; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; public class BigQueryCreateTableGenerator extends CreateTableGenerator { @@ -30,7 +30,7 @@ public int getPriority() { @Override public boolean supports(CreateTableStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDeleteGenerator.java similarity index 85% rename from src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGenerator.java rename to src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDeleteGenerator.java index 030abf15..1ce8ee0c 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryDeleteGenerator.java @@ -1,17 +1,17 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.database.Database; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.DeleteGenerator; import liquibase.statement.core.DeleteStatement; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; import static liquibase.util.SqlUtil.replacePredicatePlaceholders; -public class BigqueryDeleteGenerator extends DeleteGenerator { +public class BigQueryDeleteGenerator extends DeleteGenerator { @Override public int getPriority() { @@ -37,6 +37,6 @@ public Sql[] generateSql(DeleteStatement statement, Database database, SqlGenera @Override public boolean supports(DeleteStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } } diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java index 598c954d..21a435be 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java @@ -3,7 +3,7 @@ import java.util.Date; import liquibase.database.Database; import liquibase.datatype.DataTypeFactory; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.InsertOrUpdateGenerator; import liquibase.statement.core.InsertOrUpdateStatement; @@ -15,7 +15,7 @@ public BigQueryInsertOrUpdateGenerator() { @Override public boolean supports(InsertOrUpdateStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGenerator.java index 8c1bcf0a..d18e4efe 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGenerator.java @@ -2,7 +2,7 @@ import liquibase.database.Database; import liquibase.datatype.DataTypeFactory; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGenerator; @@ -14,7 +14,7 @@ public class BigQueryModifyDataTypeGenerator extends ModifyDataTypeGenerator { @Override public boolean supports(ModifyDataTypeStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGenerator.java index 2e48ac00..3754fd6e 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGenerator.java @@ -1,18 +1,16 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.database.Database; -import liquibase.database.core.*; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.RenameTableGenerator; -import liquibase.statement.core.DeleteStatement; import liquibase.statement.core.RenameTableStatement; import liquibase.structure.DatabaseObject; import liquibase.structure.core.Table; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; public class BigQueryRenameTableGenerator extends RenameTableGenerator { @Override @@ -22,7 +20,7 @@ public int getPriority() { @Override public boolean supports(RenameTableStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGenerator.java index cb287082..c2b1408b 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGenerator.java @@ -1,7 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.database.Database; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; @@ -9,7 +9,7 @@ import liquibase.statement.core.RenameViewStatement; import liquibase.structure.DatabaseObject; -import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; public class BigQueryRenameViewGenerator extends RenameViewGenerator { @@ -23,7 +23,7 @@ public int getPriority() { @Override public boolean supports(RenameViewStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGenerator.java index 18622f07..8626402d 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGenerator.java @@ -1,7 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.database.Database; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.SetNullableGenerator; @@ -16,7 +16,7 @@ public int getPriority() { @Override public boolean supports(SetNullableStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java index 9763a552..01c96bd7 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java @@ -1,10 +1,11 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.database.BigqueryDatabase; import liquibase.database.Database; import liquibase.datatype.DataTypeFactory; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; +import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.UpdateGenerator; import liquibase.statement.DatabaseFunction; import liquibase.statement.core.UpdateStatement; @@ -26,7 +27,7 @@ public int getPriority() { @Override public boolean supports(UpdateStatement statement, Database database) { - return database instanceof BigqueryDatabase; + return database instanceof BigQueryDatabase; } @Override diff --git a/src/main/resources/META-INF/services/liquibase.database.Database b/src/main/resources/META-INF/services/liquibase.database.Database index bca661d8..15d4c27c 100644 --- a/src/main/resources/META-INF/services/liquibase.database.Database +++ b/src/main/resources/META-INF/services/liquibase.database.Database @@ -1 +1 @@ -liquibase.ext.bigquery.database.BigqueryDatabase +liquibase.ext.bigquery.database.BigQueryDatabase diff --git a/src/main/resources/META-INF/services/liquibase.database.DatabaseConnection b/src/main/resources/META-INF/services/liquibase.database.DatabaseConnection index e72fd5c0..d6dec7eb 100644 --- a/src/main/resources/META-INF/services/liquibase.database.DatabaseConnection +++ b/src/main/resources/META-INF/services/liquibase.database.DatabaseConnection @@ -1 +1 @@ -liquibase.ext.bigquery.database.BigqueryConnection +liquibase.ext.bigquery.database.BigQueryConnection diff --git a/src/main/resources/META-INF/services/liquibase.executor.Executor b/src/main/resources/META-INF/services/liquibase.executor.Executor index bdd97705..2554c417 100644 --- a/src/main/resources/META-INF/services/liquibase.executor.Executor +++ b/src/main/resources/META-INF/services/liquibase.executor.Executor @@ -1 +1 @@ -liquibase.ext.bigquery.executor.BigqueryExecutor \ No newline at end of file +liquibase.ext.bigquery.executor.BigQueryExecutor \ No newline at end of file diff --git a/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator b/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator index e302504b..43654dd4 100644 --- a/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator +++ b/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator @@ -1,9 +1,11 @@ liquibase.ext.bigquery.sqlgenerator.BigQueryAddColumnGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryAddForeignKeyConstraintGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryAddPrimaryKeyConstraintGenerator -liquibase.ext.bigquery.sqlgenerator.BigqueryCreateDatabaseChangeLogLockTableGenerator -liquibase.ext.bigquery.sqlgenerator.BigqueryCreateDatabaseChangeLogTableGenerator -liquibase.ext.bigquery.sqlgenerator.BigqueryDeleteGenerator +liquibase.ext.bigquery.sqlgenerator.BigQueryDropForeignKeyConstraintGenerator +liquibase.ext.bigquery.sqlgenerator.BigQueryDropPrimaryKeyConstraintGenerator +liquibase.ext.bigquery.sqlgenerator.BigQueryCreateDatabaseChangeLogLockTableGenerator +liquibase.ext.bigquery.sqlgenerator.BigQueryCreateDatabaseChangeLogTableGenerator +liquibase.ext.bigquery.sqlgenerator.BigQueryDeleteGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryCreateTableGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryModifyDataTypeGenerator liquibase.ext.bigquery.sqlgenerator.BigQueryRenameTableGenerator diff --git a/src/test/groovy/liquibase/ext/bigquery/database/BigqueryDatabaseTest.groovy b/src/test/groovy/liquibase/ext/bigquery/database/BigQueryDatabaseTest.groovy similarity index 65% rename from src/test/groovy/liquibase/ext/bigquery/database/BigqueryDatabaseTest.groovy rename to src/test/groovy/liquibase/ext/bigquery/database/BigQueryDatabaseTest.groovy index 63ae0281..35ec8ae2 100644 --- a/src/test/groovy/liquibase/ext/bigquery/database/BigqueryDatabaseTest.groovy +++ b/src/test/groovy/liquibase/ext/bigquery/database/BigQueryDatabaseTest.groovy @@ -2,11 +2,11 @@ package liquibase.ext.bigquery.database import spock.lang.Specification -class BigqueryDatabaseTest extends Specification { +class BigQueryDatabaseTest extends Specification { def checkSetup() { when: - def db = new BigqueryDatabase() + def db = new BigQueryDatabase() then: db.getShortName() == "bigquery" diff --git a/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java b/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java index 94b6b00e..82b27621 100644 --- a/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java +++ b/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java @@ -1,6 +1,6 @@ package liquibase.ext.bigquery.change; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.statement.SqlStatement; import liquibase.statement.core.AddColumnStatement; import liquibase.statement.core.DropColumnStatement; @@ -13,11 +13,11 @@ class BigQueryMergeColumnChangeTest { - private BigqueryDatabase database; + private BigQueryDatabase database; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); } @Test diff --git a/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java b/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java index d0311907..8d904f93 100644 --- a/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java +++ b/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java @@ -8,11 +8,11 @@ class BigqueryDatabaseUnitTest { - private BigqueryDatabase database; + private BigQueryDatabase database; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); } @Test diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java index b6f8ed36..a38e0538 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java @@ -1,7 +1,7 @@ package liquibase.ext.bigquery.datatype.core; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -12,7 +12,7 @@ class BignumericDataTypeBigQueryTest { @Test void toDatabaseDataType() { BignumericDataTypeBigQuery bignumericDataTypeBigQuery = new BignumericDataTypeBigQuery(); - DatabaseDataType databaseDataType = bignumericDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + DatabaseDataType databaseDataType = bignumericDataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); assertEquals("BIGNUMERIC", databaseDataType.getType()); } diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java index b076bd7a..28bacf70 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java @@ -1,7 +1,7 @@ package liquibase.ext.bigquery.datatype.core; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -12,7 +12,7 @@ class BoolDataTypeBigQueryTest { @Test void toDatabaseDataType() { BoolDataTypeBigQuery boolDataTypeBigQuery = new BoolDataTypeBigQuery(); - DatabaseDataType databaseDataType = boolDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + DatabaseDataType databaseDataType = boolDataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); assertEquals("BOOL", databaseDataType.getType()); } diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java index 7d0ca204..15d979e9 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java @@ -1,8 +1,7 @@ package liquibase.ext.bigquery.datatype.core; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; -import org.junit.jupiter.api.BeforeEach; +import liquibase.ext.bigquery.database.BigQueryDatabase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -12,7 +11,7 @@ class Float64DataTypeBigQueryTest { @Test void toDatabaseDataType() { Float64DataTypeBigQuery float64DataTypeBigQuery = new Float64DataTypeBigQuery(); - DatabaseDataType databaseDataType = float64DataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + DatabaseDataType databaseDataType = float64DataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); assertEquals("FLOAT64", databaseDataType.getType()); } diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java index 31afa2f0..6a7fef8f 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java @@ -1,8 +1,7 @@ package liquibase.ext.bigquery.datatype.core; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; -import org.junit.jupiter.api.BeforeEach; +import liquibase.ext.bigquery.database.BigQueryDatabase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -12,7 +11,7 @@ class GeographyDataTypeBigQueryTest { @Test void toDatabaseDataType() { GeographyDataTypeBigQuery datatype = new GeographyDataTypeBigQuery(); - DatabaseDataType databaseDataType = datatype.toDatabaseDataType(new BigqueryDatabase()); + DatabaseDataType databaseDataType = datatype.toDatabaseDataType(new BigQueryDatabase()); assertEquals("GEOGRAPHY", databaseDataType.getType()); } } \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java index 7c46bb1e..bb666551 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java @@ -1,8 +1,7 @@ package liquibase.ext.bigquery.datatype.core; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; -import org.junit.jupiter.api.BeforeEach; +import liquibase.ext.bigquery.database.BigQueryDatabase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -12,7 +11,7 @@ class Int64DataTypeBigQueryTest { @Test void toDatabaseDataType() { Int64DataTypeBigQuery int64DataTypeBigQuery = new Int64DataTypeBigQuery(); - DatabaseDataType databaseDataType = int64DataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + DatabaseDataType databaseDataType = int64DataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); assertEquals("INT64", databaseDataType.getType()); } diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java index eb3fb58a..a053f4d3 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java @@ -1,7 +1,7 @@ package liquibase.ext.bigquery.datatype.core; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -11,7 +11,7 @@ class NumberDataTypeBigQueryTest { @Test void toDatabaseDataType() { NumericDataTypeBigQuery numberDataTypeBigQuery = new NumericDataTypeBigQuery(); - DatabaseDataType databaseDataType = numberDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + DatabaseDataType databaseDataType = numberDataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); assertEquals("NUMERIC", databaseDataType.getType()); } diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java index d2c8855e..d7c7d39f 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java @@ -1,8 +1,7 @@ package liquibase.ext.bigquery.datatype.core; import liquibase.datatype.DatabaseDataType; -import liquibase.ext.bigquery.database.BigqueryDatabase; -import org.junit.jupiter.api.BeforeEach; +import liquibase.ext.bigquery.database.BigQueryDatabase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -12,7 +11,7 @@ class StringDataTypeBigQueryTest { @Test void toDatabaseDataType() { StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); - DatabaseDataType databaseDataType = stringDataTypeBigQuery.toDatabaseDataType(new BigqueryDatabase()); + DatabaseDataType databaseDataType = stringDataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); assertEquals("STRING", databaseDataType.getType()); } @@ -20,14 +19,14 @@ void toDatabaseDataType() { @Test void objectToSql() { StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); - String sql = stringDataTypeBigQuery.objectToSql("TEST", new BigqueryDatabase()); + String sql = stringDataTypeBigQuery.objectToSql("TEST", new BigQueryDatabase()); assertEquals("'TEST'", sql); } @Test void objectToSqlNewLineCharacter() { StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); - String sql = stringDataTypeBigQuery.objectToSql("TEST\n NEW LINE", new BigqueryDatabase()); + String sql = stringDataTypeBigQuery.objectToSql("TEST\n NEW LINE", new BigQueryDatabase()); assertEquals("'''TEST\n NEW LINE'''", sql); } } \ No newline at end of file diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java index 3f44a557..0488b2aa 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java @@ -1,9 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; -import liquibase.sql.Sql; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.statement.core.AddColumnStatement; -import liquibase.statement.core.RenameTableStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,12 +10,12 @@ class BigQueryAddColumnGeneratorTest { private BigQueryAddColumnGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private AddColumnStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryAddColumnGenerator(); statement = new AddColumnStatement(); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java index 7a89736e..effd0b2c 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java @@ -1,7 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.change.ColumnConfig; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.AddForeignKeyConstraintStatement; import org.junit.jupiter.api.BeforeEach; @@ -12,12 +12,12 @@ class BigQueryAddForeignKeyConstraintGeneratorTest { private BigQueryAddForeignKeyConstraintGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private AddForeignKeyConstraintStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryAddForeignKeyConstraintGenerator(); statement = new AddForeignKeyConstraintStatement( "constraintName", diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java index 0474b3dd..47489263 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java @@ -1,7 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.change.ColumnConfig; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.AddPrimaryKeyStatement; import org.junit.jupiter.api.BeforeEach; @@ -12,12 +12,12 @@ class BigQueryAddPrimaryKeyConstraintGeneratorTest { private BigQueryAddPrimaryKeyConstraintGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private AddPrimaryKeyStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryAddPrimaryKeyConstraintGenerator(); statement = new AddPrimaryKeyStatement( "catalogName", diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java index 840e4008..5bd0fc3b 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java @@ -1,9 +1,8 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.CreateTableStatement; -import liquibase.statement.core.RenameTableStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,12 +11,12 @@ class BigQueryCreateTableGeneratorTest { private BigQueryCreateTableGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private CreateTableStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryCreateTableGenerator(); statement = new CreateTableStatement("catalog", "schema", "table"); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java index 07791396..1d1bb6dc 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java @@ -1,9 +1,8 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.change.ColumnConfig; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.statement.core.InsertOrUpdateStatement; -import liquibase.statement.core.InsertStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -13,12 +12,12 @@ class BigQueryInsertOrUpdateGeneratorTest { private BigQueryInsertOrUpdateGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private InsertOrUpdateStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryInsertOrUpdateGenerator(); statement = new InsertOrUpdateStatement("catalog", "schema", "table", "column", false); ColumnConfig columnConfig = new ColumnConfig(); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java index b791bc7f..0a26d9a7 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java @@ -1,9 +1,8 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.ModifyDataTypeStatement; -import liquibase.statement.core.RenameTableStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,12 +11,12 @@ class BigQueryModifyDataTypeGeneratorTest { private BigQueryModifyDataTypeGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private ModifyDataTypeStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryModifyDataTypeGenerator(); statement = new ModifyDataTypeStatement("catalogName", "schemaName", "tableName", "columnName", "newDataType"); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java index 24c7971b..7b208997 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java @@ -1,9 +1,8 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.RenameTableStatement; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,12 +11,12 @@ class BigQueryRenameTableGeneratorTest { private BigQueryRenameTableGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private RenameTableStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryRenameTableGenerator(); statement = new RenameTableStatement("catalogName", "schemaName", "oldTableName", "newTableName"); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java index e0c5ed1a..573af805 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java @@ -1,8 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; -import liquibase.statement.core.RenameTableStatement; import liquibase.statement.core.RenameViewStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,12 +11,12 @@ class BigQueryRenameViewGeneratorTest { private BigQueryRenameViewGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private RenameViewStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryRenameViewGenerator(); statement = new RenameViewStatement("catalogName", "schemaName", "oldTableName", "newTableName"); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java index 9419ed41..ce63e2dd 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java @@ -1,8 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; -import liquibase.statement.core.RenameTableStatement; import liquibase.statement.core.SetNullableStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,12 +11,12 @@ class BigQuerySetNullableGeneratorTest { private BigQuerySetNullableGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private SetNullableStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQuerySetNullableGenerator(); statement = new SetNullableStatement("catalogName", "schemaName", "tableName", "columnName", "columnDataType", false); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java index d96a2de5..2585e0e6 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java @@ -1,9 +1,7 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; -import liquibase.sql.Sql; -import liquibase.statement.core.RenameTableStatement; -import liquibase.statement.core.UpdateStatement; +import liquibase.ext.bigquery.database.BigQueryDatabase; +import liquibase.sql.Sql;import liquibase.statement.core.UpdateStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,12 +10,12 @@ class BigQueryUpdateGeneratorTest { private BigQueryUpdateGenerator generator; - private BigqueryDatabase database; + private BigQueryDatabase database; private UpdateStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); + database = new BigQueryDatabase(); generator = new BigQueryUpdateGenerator(); statement = new UpdateStatement("catalogName", "schemaName", "tableName"); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java index cb7aab83..48b09b44 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java @@ -1,9 +1,8 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.CreateDatabaseChangeLogLockTableStatement; -import liquibase.statement.core.RenameTableStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -11,14 +10,14 @@ class BigqueryCreateDatabaseChangeLogLockTableGeneratorTest { - private BigqueryCreateDatabaseChangeLogLockTableGenerator generator; - private BigqueryDatabase database; + private BigQueryCreateDatabaseChangeLogLockTableGenerator generator; + private BigQueryDatabase database; private CreateDatabaseChangeLogLockTableStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); - generator = new BigqueryCreateDatabaseChangeLogLockTableGenerator(); + database = new BigQueryDatabase(); + generator = new BigQueryCreateDatabaseChangeLogLockTableGenerator(); statement = new CreateDatabaseChangeLogLockTableStatement(); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java index 4023bc4d..c14872c2 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java @@ -1,9 +1,8 @@ package liquibase.ext.bigquery.sqlgenerator; -import liquibase.ext.bigquery.database.BigqueryDatabase; +import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.DeleteStatement; -import liquibase.statement.core.RenameTableStatement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -11,14 +10,14 @@ class BigqueryDeleteGeneratorTest { - private BigqueryDeleteGenerator generator; - private BigqueryDatabase database; + private BigQueryDeleteGenerator generator; + private BigQueryDatabase database; private DeleteStatement statement; @BeforeEach void setUp() { - database = new BigqueryDatabase(); - generator = new BigqueryDeleteGenerator(); + database = new BigQueryDatabase(); + generator = new BigQueryDeleteGenerator(); statement = new DeleteStatement("catalog", "schema", "table"); } From 6b8c29667fe423e962b08feb3572c508a1e13629 Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 1 May 2024 14:04:15 -0300 Subject: [PATCH 24/32] chore: codeql --- .../bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java | 4 ++-- .../sqlgenerator/BigQueryInsertOrUpdateGenerator.java | 5 +++-- .../ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java index 1b89dcd9..488b074a 100644 --- a/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/snapshot/jvm/BigQueryViewSnapshotGenerator.java @@ -13,7 +13,7 @@ import liquibase.structure.DatabaseObject; import liquibase.structure.core.Schema; import liquibase.structure.core.View; -import liquibase.util.StringUtil; +import org.apache.commons.lang3.StringUtils; import java.util.List; import java.util.Map; @@ -76,7 +76,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot definition = definition.substring(0, length - 1); } - definition = StringUtil.trimToNull(definition); + definition = StringUtils.trimToNull(definition); if (definition == null) { definition = "[CANNOT READ VIEW DEFINITION]"; } diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java index 21a435be..2d8e692e 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGenerator.java @@ -7,7 +7,8 @@ import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.InsertOrUpdateGenerator; import liquibase.statement.core.InsertOrUpdateStatement; -import liquibase.util.StringUtil; +import org.apache.commons.lang3.StringUtils; + public class BigQueryInsertOrUpdateGenerator extends InsertOrUpdateGenerator { public BigQueryInsertOrUpdateGenerator() { @@ -56,7 +57,7 @@ protected String getUpdateStatement(InsertOrUpdateStatement insertOrUpdateStatem @Override protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { - if (StringUtil.isEmpty(whereClause)) { + if (StringUtils.isEmpty(whereClause)) { whereClause = "WHERE 1 = 1"; } return "MERGE INTO " + insertOrUpdateStatement.getTableName() + " USING (SELECT 1) ON " + whereClause + " WHEN NOT MATCHED THEN "; diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java index 01c96bd7..7977a7d3 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGenerator.java @@ -9,8 +9,8 @@ import liquibase.sqlgenerator.core.UpdateGenerator; import liquibase.statement.DatabaseFunction; import liquibase.statement.core.UpdateStatement; -import liquibase.util.BooleanUtil; import liquibase.util.SqlUtil; +import org.apache.commons.lang3.BooleanUtils; import java.util.Date; @@ -75,7 +75,7 @@ private String convert(Object newValue, Database database) { sqlString = database.getDateLiteral(date); } else if (newValue instanceof Boolean) { - if (BooleanUtil.isTrue((Boolean) newValue)) { + if (BooleanUtils.isTrue((Boolean) newValue)) { sqlString = DataTypeFactory.getInstance().getTrueBooleanValue(database); } else { sqlString = DataTypeFactory.getInstance().getFalseBooleanValue(database); From 13183746a2b5c0a5238a65b02755edf8138234db Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 1 May 2024 18:09:52 -0300 Subject: [PATCH 25/32] fix: handle default location --- .../liquibase/ext/bigquery/database/BigQueryConnection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/database/BigQueryConnection.java b/src/main/java/liquibase/ext/bigquery/database/BigQueryConnection.java index e989a2a8..e95c57ca 100644 --- a/src/main/java/liquibase/ext/bigquery/database/BigQueryConnection.java +++ b/src/main/java/liquibase/ext/bigquery/database/BigQueryConnection.java @@ -86,8 +86,8 @@ public Connection getUnderlyingConnection() { @Override public void open(String url, Driver driverObject, Properties driverProperties) throws DatabaseException { - if (!driverProperties.stringPropertyNames().contains(LOCATION)) { - String locationValue = getUrlParamValue(url, LOCATION, "US"); + if (driverProperties.stringPropertyNames().contains(LOCATION)) { + String locationValue = getUrlParamValue(url, LOCATION); driverProperties.setProperty(LOCATION, locationValue); } From 06fa545179bf2c231fb7cef050e41a4e54c6904d Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 6 Jun 2024 15:40:54 +0300 Subject: [PATCH 26/32] Revert "Fix FOSSA build" This reverts commit d4083e0939a7edd660bdd8793e04d589074262de. --- .github/workflows/fossa_ai.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/fossa_ai.yml b/.github/workflows/fossa_ai.yml index a3318a0c..df1aa222 100644 --- a/.github/workflows/fossa_ai.yml +++ b/.github/workflows/fossa_ai.yml @@ -1,22 +1,14 @@ name: FOSSA License Compliance and Security Check on: - workflow_dispatch: - pull_request_target: + pull_request: types: - opened - reopened - synchronize jobs: - authorize: - environment: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }} - runs-on: ubuntu-latest - steps: - - run: true - fossa: - needs: authorize uses: liquibase/build-logic/.github/workflows/fossa_ai.yml@main secrets: inherit with: From c1eab34dfc4fb917e51ab33956f1e378564d6d62 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 6 Jun 2024 16:24:41 +0300 Subject: [PATCH 27/32] FIx tests --- pom.xml | 6 ++-- .../change/BigQueryMergeColumnChangeTest.java | 29 +++++++++++-------- .../database/BigqueryDatabaseUnitTest.java | 24 +++++++-------- .../core/BignumericDataTypeBigQueryTest.java | 10 +++---- .../core/BoolDataTypeBigQueryTest.java | 10 +++---- .../core/Float64DataTypeBigQueryTest.java | 9 +++--- .../core/GeographyDataTypeBigQueryTest.java | 8 ++--- .../core/Int64DataTypeBigQueryTest.java | 9 +++--- .../core/NumberDataTypeBigQueryTest.java | 9 +++--- .../core/StringDataTypeBigQueryTest.java | 13 +++++---- .../BigQueryAddColumnGeneratorTest.java | 14 ++++----- ...yAddForeignKeyConstraintGeneratorTest.java | 14 ++++----- ...yAddPrimaryKeyConstraintGeneratorTest.java | 14 ++++----- .../BigQueryCreateTableGeneratorTest.java | 14 ++++----- .../BigQueryInsertOrUpdateGeneratorTest.java | 22 +++++++------- .../BigQueryModifyDataTypeGeneratorTest.java | 14 ++++----- .../BigQueryRenameTableGeneratorTest.java | 14 ++++----- .../BigQueryRenameViewGeneratorTest.java | 14 ++++----- .../BigQuerySetNullableGeneratorTest.java | 14 ++++----- .../BigQueryUpdateGeneratorTest.java | 17 ++++++----- ...tabaseChangeLogLockTableGeneratorTest.java | 14 ++++----- .../BigqueryDeleteGeneratorTest.java | 14 ++++----- 22 files changed, 158 insertions(+), 148 deletions(-) diff --git a/pom.xml b/pom.xml index 9a555a0c..dac6dd02 100644 --- a/pom.xml +++ b/pom.xml @@ -52,10 +52,10 @@ - org.junit.jupiter - junit-jupiter - 5.10.2 + junit + junit test + 4.13.2 com.simba.googlebigquery.jdbc diff --git a/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java b/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java index 82b27621..0539d840 100644 --- a/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java +++ b/src/test/java/liquibase/ext/bigquery/change/BigQueryMergeColumnChangeTest.java @@ -5,23 +5,28 @@ import liquibase.statement.core.AddColumnStatement; import liquibase.statement.core.DropColumnStatement; import liquibase.statement.core.RawSqlStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +// +//import static org.junit.jupiter.api.Assertions.assertEquals; +//import static org.junit.jupiter.api.Assertions.assertInstanceOf; -class BigQueryMergeColumnChangeTest { +public class BigQueryMergeColumnChangeTest { private BigQueryDatabase database; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); } @Test - void generateStatements() { + public void generateStatements() { BigQueryMergeColumnChange change = new BigQueryMergeColumnChange(); change.setTableName("tableName"); change.setColumn1Name("column1Name"); @@ -34,10 +39,10 @@ void generateStatements() { SqlStatement[] sqlStatements = change.generateStatements(database); assertEquals(4, sqlStatements.length); - assertInstanceOf(AddColumnStatement.class, sqlStatements[0]); - assertInstanceOf(RawSqlStatement.class, sqlStatements[1]); - assertInstanceOf(DropColumnStatement.class, sqlStatements[2]); - assertInstanceOf(DropColumnStatement.class, sqlStatements[3]); + assertTrue(sqlStatements[0] instanceof AddColumnStatement); + assertTrue(sqlStatements[1] instanceof RawSqlStatement); + assertTrue(sqlStatements[2] instanceof DropColumnStatement); + assertTrue(sqlStatements[3] instanceof DropColumnStatement); AddColumnStatement addColumnStatement = (AddColumnStatement) sqlStatements[0]; assertEquals("finalColumnName", addColumnStatement.getColumnName()); diff --git a/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java b/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java index 8d904f93..8f5606dd 100644 --- a/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java +++ b/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java @@ -1,42 +1,42 @@ package liquibase.ext.bigquery.database; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -class BigqueryDatabaseUnitTest { +public class BigqueryDatabaseUnitTest { private BigQueryDatabase database; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); } @Test - void getShortName() { + public void getShortName() { assertEquals("bigquery", database.getShortName()); } @Test - void getDefaultDatabaseProductName() { + public void getDefaultDatabaseProductName() { assertEquals("Google BigQuery", database.getDefaultDatabaseProductName()); } @Test - void supportsDatabaseChangeLogHistory() { + public void supportsDatabaseChangeLogHistory() { assertTrue(database.supportsDatabaseChangeLogHistory()); } @Test - void getCurrentDateTimeFunction() { + public void getCurrentDateTimeFunction() { assertEquals("CURRENT_DATETIME()", database.getCurrentDateTimeFunction()); } @Test - void getQuotingStartCharacter() { + public void getQuotingStartCharacter() { assertEquals("`", database.getQuotingStartCharacter()); } diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java index a38e0538..e5671222 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQueryTest.java @@ -2,15 +2,15 @@ import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -class BignumericDataTypeBigQueryTest { +public class BignumericDataTypeBigQueryTest { @Test - void toDatabaseDataType() { + public void toDatabaseDataType() { BignumericDataTypeBigQuery bignumericDataTypeBigQuery = new BignumericDataTypeBigQuery(); DatabaseDataType databaseDataType = bignumericDataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java index 28bacf70..7677f8e5 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQueryTest.java @@ -2,15 +2,15 @@ import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -class BoolDataTypeBigQueryTest { +public class BoolDataTypeBigQueryTest { @Test - void toDatabaseDataType() { + public void toDatabaseDataType() { BoolDataTypeBigQuery boolDataTypeBigQuery = new BoolDataTypeBigQuery(); DatabaseDataType databaseDataType = boolDataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java index 15d979e9..babcb4d0 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQueryTest.java @@ -2,14 +2,15 @@ import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -class Float64DataTypeBigQueryTest { +public class Float64DataTypeBigQueryTest { @Test - void toDatabaseDataType() { + public void toDatabaseDataType() { Float64DataTypeBigQuery float64DataTypeBigQuery = new Float64DataTypeBigQuery(); DatabaseDataType databaseDataType = float64DataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java index 6a7fef8f..cda2eec0 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQueryTest.java @@ -2,14 +2,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class GeographyDataTypeBigQueryTest { +public class GeographyDataTypeBigQueryTest { @Test - void toDatabaseDataType() { + public void toDatabaseDataType() { GeographyDataTypeBigQuery datatype = new GeographyDataTypeBigQuery(); DatabaseDataType databaseDataType = datatype.toDatabaseDataType(new BigQueryDatabase()); assertEquals("GEOGRAPHY", databaseDataType.getType()); diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java index bb666551..9c9c91f9 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQueryTest.java @@ -2,14 +2,15 @@ import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -class Int64DataTypeBigQueryTest { +public class Int64DataTypeBigQueryTest { @Test - void toDatabaseDataType() { + public void toDatabaseDataType() { Int64DataTypeBigQuery int64DataTypeBigQuery = new Int64DataTypeBigQuery(); DatabaseDataType databaseDataType = int64DataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java index a053f4d3..9b44c119 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/NumberDataTypeBigQueryTest.java @@ -2,14 +2,15 @@ import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -class NumberDataTypeBigQueryTest { +public class NumberDataTypeBigQueryTest { @Test - void toDatabaseDataType() { + public void toDatabaseDataType() { NumericDataTypeBigQuery numberDataTypeBigQuery = new NumericDataTypeBigQuery(); DatabaseDataType databaseDataType = numberDataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); diff --git a/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java b/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java index d7c7d39f..ffa16640 100644 --- a/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java +++ b/src/test/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQueryTest.java @@ -2,14 +2,15 @@ import liquibase.datatype.DatabaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; -import org.junit.jupiter.api.Test; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -class StringDataTypeBigQueryTest { +public class StringDataTypeBigQueryTest { @Test - void toDatabaseDataType() { + public void toDatabaseDataType() { StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); DatabaseDataType databaseDataType = stringDataTypeBigQuery.toDatabaseDataType(new BigQueryDatabase()); assertNotNull(databaseDataType); @@ -17,14 +18,14 @@ void toDatabaseDataType() { } @Test - void objectToSql() { + public void objectToSql() { StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); String sql = stringDataTypeBigQuery.objectToSql("TEST", new BigQueryDatabase()); assertEquals("'TEST'", sql); } @Test - void objectToSqlNewLineCharacter() { + public void objectToSqlNewLineCharacter() { StringDataTypeBigQuery stringDataTypeBigQuery = new StringDataTypeBigQuery(); String sql = stringDataTypeBigQuery.objectToSql("TEST\n NEW LINE", new BigQueryDatabase()); assertEquals("'''TEST\n NEW LINE'''", sql); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java index 0488b2aa..8b627145 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddColumnGeneratorTest.java @@ -2,26 +2,26 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.statement.core.AddColumnStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigQueryAddColumnGeneratorTest { +public class BigQueryAddColumnGeneratorTest { private BigQueryAddColumnGenerator generator; private BigQueryDatabase database; private AddColumnStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryAddColumnGenerator(); statement = new AddColumnStatement(); } @Test - void generateSingleColumnSQL() { + public void generateSingleColumnSQL() { String sql = generator.generateSingleColumnSQL(statement, database); assertEquals(" ADD COLUMN null", sql); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java index effd0b2c..5c7b6526 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddForeignKeyConstraintGeneratorTest.java @@ -4,19 +4,19 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.AddForeignKeyConstraintStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.Assert.assertEquals; -class BigQueryAddForeignKeyConstraintGeneratorTest { +public class BigQueryAddForeignKeyConstraintGeneratorTest { private BigQueryAddForeignKeyConstraintGenerator generator; private BigQueryDatabase database; private AddForeignKeyConstraintStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryAddForeignKeyConstraintGenerator(); statement = new AddForeignKeyConstraintStatement( @@ -32,7 +32,7 @@ void setUp() { } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java index 47489263..ef054dee 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryAddPrimaryKeyConstraintGeneratorTest.java @@ -4,19 +4,19 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.AddPrimaryKeyStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.Assert.assertEquals; -class BigQueryAddPrimaryKeyConstraintGeneratorTest { +public class BigQueryAddPrimaryKeyConstraintGeneratorTest { private BigQueryAddPrimaryKeyConstraintGenerator generator; private BigQueryDatabase database; private AddPrimaryKeyStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryAddPrimaryKeyConstraintGenerator(); statement = new AddPrimaryKeyStatement( @@ -28,7 +28,7 @@ void setUp() { } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java index 5bd0fc3b..91ff7cbe 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java @@ -3,26 +3,26 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.CreateTableStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigQueryCreateTableGeneratorTest { +public class BigQueryCreateTableGeneratorTest { private BigQueryCreateTableGenerator generator; private BigQueryDatabase database; private CreateTableStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryCreateTableGenerator(); statement = new CreateTableStatement("catalog", "schema", "table"); } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java index 1d1bb6dc..d073a487 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryInsertOrUpdateGeneratorTest.java @@ -3,20 +3,20 @@ import liquibase.change.ColumnConfig; import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.statement.core.InsertOrUpdateStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -class BigQueryInsertOrUpdateGeneratorTest { +public class BigQueryInsertOrUpdateGeneratorTest { private BigQueryInsertOrUpdateGenerator generator; private BigQueryDatabase database; private InsertOrUpdateStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryInsertOrUpdateGenerator(); statement = new InsertOrUpdateStatement("catalog", "schema", "table", "column", false); @@ -28,28 +28,28 @@ void setUp() { } @Test - void getInsertStatement() { + public void getInsertStatement() { String insertStatement = generator.getInsertStatement(statement, database, null); assertNotNull(insertStatement); assertEquals("INSERT (columnName) VALUES (valueBoolean)", insertStatement); } @Test - void getUpdateStatement() { + public void getUpdateStatement() { String updateStatement = generator.getUpdateStatement(statement, database, "", null); assertNotNull(updateStatement); assertEquals("UPDATE SET columnName = valueBoolean", updateStatement); } @Test - void getRecordEmptyCheck() { + public void getRecordEmptyCheck() { String recordCheck = generator.getRecordCheck(statement, database, null); assertNotNull(recordCheck); assertEquals("MERGE INTO table USING (SELECT 1) ON WHERE 1 = 1 WHEN NOT MATCHED THEN ", recordCheck); } @Test - void getRecordWhereCheck() { + public void getRecordWhereCheck() { String recordCheck = generator.getRecordCheck(statement, database, "WHERE ID = 1"); assertNotNull(recordCheck); assertEquals("MERGE INTO table USING (SELECT 1) ON WHERE ID = 1 WHEN NOT MATCHED THEN ", recordCheck); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java index 0a26d9a7..39ff35b2 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryModifyDataTypeGeneratorTest.java @@ -3,26 +3,26 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.ModifyDataTypeStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigQueryModifyDataTypeGeneratorTest { +public class BigQueryModifyDataTypeGeneratorTest { private BigQueryModifyDataTypeGenerator generator; private BigQueryDatabase database; private ModifyDataTypeStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryModifyDataTypeGenerator(); statement = new ModifyDataTypeStatement("catalogName", "schemaName", "tableName", "columnName", "newDataType"); } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java index 7b208997..7d9a42c3 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameTableGeneratorTest.java @@ -3,26 +3,26 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.RenameTableStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigQueryRenameTableGeneratorTest { +public class BigQueryRenameTableGeneratorTest { private BigQueryRenameTableGenerator generator; private BigQueryDatabase database; private RenameTableStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryRenameTableGenerator(); statement = new RenameTableStatement("catalogName", "schemaName", "oldTableName", "newTableName"); } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java index 573af805..056cd21f 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryRenameViewGeneratorTest.java @@ -3,26 +3,26 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.RenameViewStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigQueryRenameViewGeneratorTest { +public class BigQueryRenameViewGeneratorTest { private BigQueryRenameViewGenerator generator; private BigQueryDatabase database; private RenameViewStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryRenameViewGenerator(); statement = new RenameViewStatement("catalogName", "schemaName", "oldTableName", "newTableName"); } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java index ce63e2dd..5a2ba83b 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQuerySetNullableGeneratorTest.java @@ -3,26 +3,26 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.SetNullableStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigQuerySetNullableGeneratorTest { +public class BigQuerySetNullableGeneratorTest { private BigQuerySetNullableGenerator generator; private BigQueryDatabase database; private SetNullableStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQuerySetNullableGenerator(); statement = new SetNullableStatement("catalogName", "schemaName", "tableName", "columnName", "columnDataType", false); } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(0, sql.length); } diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java index 2585e0e6..7fde31f4 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryUpdateGeneratorTest.java @@ -1,27 +1,28 @@ package liquibase.ext.bigquery.sqlgenerator; import liquibase.ext.bigquery.database.BigQueryDatabase; -import liquibase.sql.Sql;import liquibase.statement.core.UpdateStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import liquibase.sql.Sql; +import liquibase.statement.core.UpdateStatement; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigQueryUpdateGeneratorTest { +public class BigQueryUpdateGeneratorTest { private BigQueryUpdateGenerator generator; private BigQueryDatabase database; private UpdateStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryUpdateGenerator(); statement = new UpdateStatement("catalogName", "schemaName", "tableName"); } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java index 48b09b44..c0f5d30c 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryCreateDatabaseChangeLogLockTableGeneratorTest.java @@ -3,26 +3,26 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.CreateDatabaseChangeLogLockTableStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigqueryCreateDatabaseChangeLogLockTableGeneratorTest { +public class BigqueryCreateDatabaseChangeLogLockTableGeneratorTest { private BigQueryCreateDatabaseChangeLogLockTableGenerator generator; private BigQueryDatabase database; private CreateDatabaseChangeLogLockTableStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryCreateDatabaseChangeLogLockTableGenerator(); statement = new CreateDatabaseChangeLogLockTableStatement(); } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); diff --git a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java index c14872c2..f0bb398c 100644 --- a/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java +++ b/src/test/java/liquibase/ext/bigquery/sqlgenerator/BigqueryDeleteGeneratorTest.java @@ -3,26 +3,26 @@ import liquibase.ext.bigquery.database.BigQueryDatabase; import liquibase.sql.Sql; import liquibase.statement.core.DeleteStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.Assert.assertEquals; -class BigqueryDeleteGeneratorTest { +public class BigqueryDeleteGeneratorTest { private BigQueryDeleteGenerator generator; private BigQueryDatabase database; private DeleteStatement statement; - @BeforeEach - void setUp() { + @Before + public void setUp() { database = new BigQueryDatabase(); generator = new BigQueryDeleteGenerator(); statement = new DeleteStatement("catalog", "schema", "table"); } @Test - void generateSql() { + public void generateSql() { Sql[] sql = generator.generateSql(statement, database, null); assertEquals(1, sql.length); assertEquals(";", sql[0].getEndDelimiter()); From f0a380ee85e6be6a987a131b03ee2379417de9f6 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 6 Jun 2024 16:34:08 +0300 Subject: [PATCH 28/32] Fix test --- .../ext/bigquery/database/BigqueryDatabaseUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java b/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java index 8f5606dd..340de925 100644 --- a/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java +++ b/src/test/java/liquibase/ext/bigquery/database/BigqueryDatabaseUnitTest.java @@ -41,7 +41,7 @@ public void getQuotingStartCharacter() { } @Test - void getQuotingEndCharacter() { + public void getQuotingEndCharacter() { assertEquals("`", database.getQuotingEndCharacter()); } From 25874e88b3440ec699e80cd96564634ffc782560 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Fri, 7 Jun 2024 12:28:08 +0300 Subject: [PATCH 29/32] Fix tests --- .../changelogs/bigquery/addForeignKey.xml | 5 +++-- .../changelogs/bigquery/createTable.xml | 3 +++ .../changelogs/bigquery/dropForeignKey.xml | 5 +++-- .../expectedSql/bigquery/1initScript.sql | 22 +++++++++++++++++++ .../expectedSql/bigquery/addForeignKey.sql | 2 ++ .../expectedSql/bigquery/addLookupTable.sql | 4 ++-- .../expectedSql/bigquery/addPrimaryKey.sql | 1 + .../expectedSql/bigquery/createTable.sql | 3 ++- .../expectedSql/bigquery/dropPrimaryKey.sql | 2 ++ .../change/expectedSql/bigquery/modifySql.sql | 2 +- 10 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/liquibase/harness/change/expectedSql/bigquery/1initScript.sql create mode 100644 src/test/resources/liquibase/harness/change/expectedSql/bigquery/addForeignKey.sql create mode 100644 src/test/resources/liquibase/harness/change/expectedSql/bigquery/addPrimaryKey.sql create mode 100644 src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropPrimaryKey.sql diff --git a/src/test/resources/liquibase/harness/change/changelogs/bigquery/addForeignKey.xml b/src/test/resources/liquibase/harness/change/changelogs/bigquery/addForeignKey.xml index 0292745a..581d065c 100644 --- a/src/test/resources/liquibase/harness/change/changelogs/bigquery/addForeignKey.xml +++ b/src/test/resources/liquibase/harness/change/changelogs/bigquery/addForeignKey.xml @@ -4,9 +4,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> - + + + - + + + diff --git a/src/test/resources/liquibase/harness/change/changelogs/bigquery/dropForeignKey.xml b/src/test/resources/liquibase/harness/change/changelogs/bigquery/dropForeignKey.xml index 42e8d66f..b1308ae7 100644 --- a/src/test/resources/liquibase/harness/change/changelogs/bigquery/dropForeignKey.xml +++ b/src/test/resources/liquibase/harness/change/changelogs/bigquery/dropForeignKey.xml @@ -4,9 +4,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> - + + + - Date: Fri, 7 Jun 2024 13:05:29 +0300 Subject: [PATCH 30/32] Fix tests --- .../harness/change/expectedSql/bigquery/dropForeignKey.sql | 1 + .../liquibase/harness/change/expectedSql/bigquery/sqlFile.sql | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropForeignKey.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropForeignKey.sql index cdc2379c..8331e44f 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropForeignKey.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/dropForeignKey.sql @@ -1,2 +1,3 @@ +ALTER TABLE harness_test_ds.authors ADD PRIMARY KEY (id) NOT ENFORCED ALTER TABLE harness_test_ds.posts ADD CONSTRAINT fk_posts_authors_test FOREIGN KEY (author_id) REFERENCES harness_test_ds.authors (id) NOT ENFORCED ALTER TABLE harness_test_ds.posts DROP CONSTRAINT fk_posts_authors_test \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/sqlFile.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/sqlFile.sql index e4b3a0e6..adca383b 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/sqlFile.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/sqlFile.sql @@ -1,4 +1,3 @@ -CREATE TABLE harness_test_ds.sqltest (id INT) insert into sqltest (id) values (1) insert into sqltest (id) values (2) insert into sqltest (id) values (3) \ No newline at end of file From ea04aa7867b64e3064ade58368297aff95bbd419 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Fri, 7 Jun 2024 13:53:00 +0300 Subject: [PATCH 31/32] Fix tests --- .../liquibase/harness/change/expectedSql/bigquery/sqlFile.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/sqlFile.sql b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/sqlFile.sql index adca383b..e4b3a0e6 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/bigquery/sqlFile.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/bigquery/sqlFile.sql @@ -1,3 +1,4 @@ +CREATE TABLE harness_test_ds.sqltest (id INT) insert into sqltest (id) values (1) insert into sqltest (id) values (2) insert into sqltest (id) values (3) \ No newline at end of file From fa1dde3fe97569fb8b03424e2527cf7e202cacea Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Fri, 7 Jun 2024 14:42:46 +0300 Subject: [PATCH 32/32] Fix sonar and codeql issues --- .../bigquery/datatype/core/BignumericDataTypeBigQuery.java | 3 ++- .../ext/bigquery/datatype/core/BoolDataTypeBigQuery.java | 5 ++--- .../ext/bigquery/datatype/core/Float64DataTypeBigQuery.java | 4 ++-- .../bigquery/datatype/core/GeographyDataTypeBigQuery.java | 5 ++--- .../ext/bigquery/datatype/core/Int64DataTypeBigQuery.java | 3 ++- .../ext/bigquery/datatype/core/NumericDataTypeBigQuery.java | 3 ++- .../ext/bigquery/datatype/core/StringDataTypeBigQuery.java | 5 ++--- .../bigquery/sqlgenerator/BigQueryCreateTableGenerator.java | 3 ++- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java index 03ca918f..7411a749 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/BignumericDataTypeBigQuery.java @@ -6,13 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "bignumeric", minParameters = 0, maxParameters = 0, - priority = LiquibaseDataType.PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class BignumericDataTypeBigQuery extends LiquibaseDataType { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java index 04fe4740..179cd5b6 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/BoolDataTypeBigQuery.java @@ -6,15 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; - -import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "boolean", minParameters = 0, maxParameters = 0, - priority = LiquibaseDataType.PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class BoolDataTypeBigQuery extends LiquibaseDataType { public BoolDataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java index c5824768..fb16f402 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/Float64DataTypeBigQuery.java @@ -6,14 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; +import liquibase.servicelocator.PrioritizedService; -import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; @DataTypeInfo( name = "float64", minParameters = 0, maxParameters = 0, - priority = LiquibaseDataType.PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class Float64DataTypeBigQuery extends LiquibaseDataType { public Float64DataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java index 4bbdf9bd..ea50e6fe 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/GeographyDataTypeBigQuery.java @@ -6,15 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; - -import static liquibase.ext.bigquery.database.BigQueryDatabase.BIGQUERY_PRIORITY_DATABASE; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "geography", minParameters = 0, maxParameters = 0, - priority = LiquibaseDataType.PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class GeographyDataTypeBigQuery extends LiquibaseDataType { public GeographyDataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java index 4afacc61..31a2a2a7 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/Int64DataTypeBigQuery.java @@ -6,13 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "int64", minParameters = 0, maxParameters = 0, - priority = LiquibaseDataType.PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class Int64DataTypeBigQuery extends LiquibaseDataType { public Int64DataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java index 1e0d5848..27a4d94b 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/NumericDataTypeBigQuery.java @@ -6,13 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.bigquery.database.BigQueryDatabase; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "numeric", minParameters = 0, maxParameters = 0, - priority = LiquibaseDataType.PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class NumericDataTypeBigQuery extends LiquibaseDataType { public NumericDataTypeBigQuery() { diff --git a/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java b/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java index 7824d5ed..5755a099 100644 --- a/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java +++ b/src/main/java/liquibase/ext/bigquery/datatype/core/StringDataTypeBigQuery.java @@ -6,15 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.core.VarcharType; import liquibase.ext.bigquery.database.BigQueryDatabase; - -import liquibase.datatype.LiquibaseDataType; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "string", minParameters = 0, maxParameters = 0, - priority = LiquibaseDataType.PRIORITY_DATABASE, + priority = PrioritizedService.PRIORITY_DATABASE, aliases = { "varchar", "clob", "java.lang.String" } ) public class StringDataTypeBigQuery extends VarcharType { diff --git a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java index af90e224..7cda3c9f 100644 --- a/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java +++ b/src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java @@ -12,6 +12,7 @@ import liquibase.statement.ForeignKeyConstraint; import liquibase.statement.PrimaryKeyConstraint; import liquibase.statement.core.CreateTableStatement; +import liquibase.structure.core.Catalog; import liquibase.structure.core.Schema; import liquibase.structure.core.Table; @@ -103,7 +104,7 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG .append(") REFERENCES "); if (referencesString != null) { if (!referencesString.contains(".") && (database.getDefaultSchemaName() != null) && database - .getOutputDefaultSchema() && (database.supportsSchemas() || database.supportsCatalogs())) { + .getOutputDefaultSchema() && (database.supports(Schema.class) || database.supports(Catalog.class))) { referencesString = database.escapeObjectName(database.getDefaultSchemaName(), Schema.class) + "." + referencesString; } buffer.append(referencesString);