Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAT-17773] Epic branch for moving functionality from liquibase core #325

Merged
merged 38 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e5e652c
Update junit version to 5
vitaliimak Apr 25, 2024
057d603
Add sqlgenerator unit tests
vitaliimak Apr 25, 2024
b1c9e66
Add change unit test
vitaliimak Apr 25, 2024
ed01eec
Add lombok dependency
vitaliimak Apr 25, 2024
f9890be
Add database unit tests
vitaliimak Apr 25, 2024
8b84b84
Add data type unit tests
vitaliimak Apr 26, 2024
34db2bc
Merge branch 'main' into DAT-17450
vitaliimak May 29, 2024
d4083e0
Fix FOSSA build
vitaliimak May 29, 2024
534a0c6
Merge pull request #295 from liquibase/DAT-17450
vitaliimak May 30, 2024
3cdcc21
fixed FK
KushnirykOleh May 13, 2024
c5da23c
fixed FK name
KushnirykOleh May 16, 2024
687e2b1
updated query generation
KushnirykOleh May 16, 2024
ce7e5ea
replaced null by undefined, fixed creating constraints when creating …
KushnirykOleh May 17, 2024
3191d08
Fix merge conflicts
vitaliimak May 30, 2024
467434a
Merge pull request #313 from liquibase/DAT-17502
vitaliimak May 30, 2024
02d5cec
Add PrimaryKey support
vitaliimak May 29, 2024
db96d6f
Merge pull request #321 from liquibase/DAT-17773
vitaliimak May 30, 2024
7948b0a
resolved priorities for Datatypes and ModifyDatatype generator
KushnirykOleh May 14, 2024
736269e
Fix merge conflicts
vitaliimak May 30, 2024
05c5d06
Merge pull request #320 from liquibase/DAT-17403
vitaliimak May 30, 2024
7274e83
fix: adding missed supports methods in BigQuery generators
Apr 24, 2024
0f982db
chore: codeql + sonar fixes
Apr 24, 2024
32834ab
chore: codeql + sonar fixes
Apr 24, 2024
ad688a4
chore:fix sonar critical alerts
Apr 24, 2024
5a96705
chore: fix some sonar medium alerts
Apr 24, 2024
588c996
fix: re-add required method
filipelautert Apr 25, 2024
5c3785e
fix: implement new Supports method
filipelautert May 1, 2024
0e02b37
chore: renamed all occurrences of Bigquery to BigQuery
vitaliimak May 30, 2024
6b8c296
chore: codeql
filipelautert May 1, 2024
1318374
fix: handle default location
filipelautert May 1, 2024
d07b990
Merge pull request #324 from liquibase/DAT-17482
vitaliimak May 30, 2024
06fa545
Revert "Fix FOSSA build"
vitaliimak Jun 6, 2024
c1eab34
FIx tests
vitaliimak Jun 6, 2024
f0a380e
Fix test
vitaliimak Jun 6, 2024
25874e8
Fix tests
vitaliimak Jun 7, 2024
06cc9a6
Fix tests
vitaliimak Jun 7, 2024
ea04aa7
Fix tests
vitaliimak Jun 7, 2024
fa1dde3
Fix sonar and codeql issues
vitaliimak Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.ext.bigquery.database.BigQueryDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.RawSqlStatement;
import liquibase.structure.core.Column;
Expand All @@ -18,12 +18,12 @@

@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
public boolean supports(Database database) {
return database instanceof BigqueryDatabase;
return database instanceof BigQueryDatabase;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +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()));
Expand Down Expand Up @@ -85,9 +86,9 @@ 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");
driverProperties.setProperty("Location", locationValue);
if (driverProperties.stringPropertyNames().contains(LOCATION)) {
String locationValue = getUrlParamValue(url, LOCATION);
driverProperties.setProperty(LOCATION, locationValue);
}

Scope.getCurrentScope().getLog(this.getClass()).fine(String.format("Opening connection to %s driverProperties=%s", url, driverProperties));
Expand Down Expand Up @@ -124,6 +125,7 @@ public boolean getAutoCommit() throws DatabaseException {

@Override
public void setAutoCommit(boolean autoCommit) throws DatabaseException {
// not supported by BigQuery
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
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;
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;
private String liquibaseSchemaName;

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());
Expand All @@ -53,6 +54,7 @@ public int getPriority() {
return BIGQUERY_PRIORITY_DATABASE;
}

@Override
public boolean supportsDatabaseChangeLogHistory() {
return true;
}
Expand Down Expand Up @@ -93,6 +95,14 @@ public int getDatabaseMinorVersion() {
return BQDriver.DRIVER_MINOR_VERSION;
}

@Override
public boolean supports(Class<? extends DatabaseObject> object) {
if (Sequence.class.isAssignableFrom(object)) {
return false;
}
return super.supports(object);
}

@Override
public boolean supportsInitiallyDeferrableColumns() {
return false;
Expand Down Expand Up @@ -141,7 +151,7 @@ public String getDefaultDriver(String url) {

@Override
public boolean supportsSequences() {
return false;
return this.supports(Sequence.class);
}

@Override
Expand All @@ -164,7 +174,7 @@ private String getDefaultDataset() {
if (connection == null) {
return null;
}
return BigqueryConnection.getUrlParamValue(connection.getURL(), "DefaultDataset");
return BigQueryConnection.getUrlParamValue(connection.getURL(), "DefaultDataset");
}

@Override
Expand Down Expand Up @@ -222,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,41 @@
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 liquibase.servicelocator.PrioritizedService;


@DataTypeInfo(
name = "bignumeric",
minParameters = 0,
maxParameters = 0,
priority = 1
priority = PrioritizedService.PRIORITY_DATABASE
)
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;
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) {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
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;
import liquibase.servicelocator.PrioritizedService;


@DataTypeInfo(
name = "boolean",
minParameters = 0,
maxParameters = 0,
priority = BIGQUERY_PRIORITY_DATABASE
priority = PrioritizedService.PRIORITY_DATABASE
)
public class BoolDataTypeBigQuery extends LiquibaseDataType {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@
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 liquibase.servicelocator.PrioritizedService;

import static liquibase.ext.bigquery.database.BigqueryDatabase.BIGQUERY_PRIORITY_DATABASE;

@DataTypeInfo(
name = "float64",
minParameters = 0,
maxParameters = 0,
priority = BIGQUERY_PRIORITY_DATABASE
priority = PrioritizedService.PRIORITY_DATABASE
)
public class Float64DataTypeBigQuery extends LiquibaseDataType {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
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;
import liquibase.servicelocator.PrioritizedService;


@DataTypeInfo(
name = "geography",
minParameters = 0,
maxParameters = 0,
priority = BIGQUERY_PRIORITY_DATABASE
priority = PrioritizedService.PRIORITY_DATABASE
)
public class GeographyDataTypeBigQuery extends LiquibaseDataType {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
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;
import liquibase.servicelocator.PrioritizedService;


@DataTypeInfo(
name = "int64",
minParameters = 0,
maxParameters = 0,
priority = 1
priority = PrioritizedService.PRIORITY_DATABASE
)
public class Int64DataTypeBigQuery extends LiquibaseDataType {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
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 liquibase.servicelocator.PrioritizedService;


@DataTypeInfo(
name = "numeric",
minParameters = 0,
maxParameters = 0,
priority = 1
priority = PrioritizedService.PRIORITY_DATABASE
)
public class NumberDataTypeBigQuery extends LiquibaseDataType {
public NumberDataTypeBigQuery() {
public class NumericDataTypeBigQuery extends LiquibaseDataType {
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 {
Expand Down
Loading
Loading