Skip to content

Commit

Permalink
fixed supports and priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
KushnirykOleh committed Aug 1, 2024
1 parent e4b37ba commit ccb630e
Show file tree
Hide file tree
Showing 44 changed files with 135 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import liquibase.database.Database;
import liquibase.ext.databricks.change.dropCheckConstraint.DropCheckConstraintChangeDatabricks;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;

import java.text.MessageFormat;
import liquibase.ext.databricks.database.DatabricksDatabase;

@DatabaseChange(name = "addCheckConstraint",
description = "Adds check constraint to Delta Table",
priority = DatabricksDatabase.PRIORITY_DEFAULT + 200,
priority = PrioritizedService.PRIORITY_DATABASE,
appliesTo = {"column"}
)
public class AddCheckConstraintChangeDatabricks extends AbstractChange {
Expand All @@ -23,35 +24,38 @@ public class AddCheckConstraintChangeDatabricks extends AbstractChange {

private String constraintBody;


@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

public String getCatalogName() {
return catalogName;
}

public void setCatalogName (String catalogName) {
public void setCatalogName(String catalogName) {
this.catalogName = catalogName;
}

public String getTableName() {
return tableName;
}

public void setTableName (String tableName) {
public void setTableName(String tableName) {
this.tableName = tableName;
}

public String getSchemaName() {
return schemaName;
}

public void setSchemaName (String schemaName) {
public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
}


// Name of Delta Table Constraint
@DatabaseChangeProperty(
description = "Name of the check constraint"
)
@DatabaseChangeProperty(description = "Name of the check constraint")
public String getConstraintName() {
return this.constraintName;
}
Expand All @@ -60,9 +64,7 @@ public void setConstraintName(String name) {
this.constraintName = name;
}


// The is the SQL expression involving the contraint

// This is the SQL expression involving the constraint
@DatabaseChangeProperty(
serializationType = SerializationType.DIRECT_VALUE
)
Expand All @@ -76,7 +78,8 @@ public void setConstraintBody(String body) {

@Override
public String getConfirmationMessage() {
return MessageFormat.format("{0}.{1}.{2} successfully Added check constraint {3}.", getCatalogName(), getSchemaName(), getTableName(), getConstraintName());
return MessageFormat.format("{0}.{1}.{2} successfully Added check constraint {3}.", getCatalogName(), getSchemaName(), getTableName(),
getConstraintName());
}

protected Change[] createInverses() {
Expand All @@ -100,6 +103,6 @@ public SqlStatement[] generateStatements(Database database) {
statement.setConstraintName(getConstraintName());
statement.setConstraintBody(getConstraintBody());

return new SqlStatement[] {statement};
return new SqlStatement[]{statement};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class AddCheckConstraintStatementDatabricks extends AbstractSqlStatement
private String tableName;
private String constraintName;
private String constraintBody;
private boolean validate = true;
private boolean disabled;


public String getCatalogName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package liquibase.ext.databricks.change.addForeignKeyConstraint;

import liquibase.ext.databricks.database.DatabricksDatabase;

import liquibase.change.*;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.snapshot.SnapshotGeneratorFactory;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.AddForeignKeyConstraintStatement;
Expand All @@ -23,8 +23,9 @@
*/
@DatabaseChange(name = "addForeignKeyConstraint",
description = "Adds a foreign key constraint to an existing column",
priority = DatabricksDatabase.PRIORITY_DATABASE,
priority = PrioritizedService.PRIORITY_DATABASE,
appliesTo = "column")
//TODO this class need refactoring as it copies parent class instead of properly inheriting it.
public class AddForeignKeyConstraintChangeDatabricks extends AddForeignKeyConstraintChange {

private String baseTableCatalogName;
Expand All @@ -46,6 +47,10 @@ public class AddForeignKeyConstraintChangeDatabricks extends AddForeignKeyConstr
private String onUpdate;
private String onDelete;

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
protected String[] createSupportedDatabasesMetaData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,27 @@

import liquibase.change.core.*;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.ext.databricks.change.createTable.CreateTableStatementDatabricks;
import liquibase.ext.databricks.change.createTable.CreateTableChangeDatabricks;
import liquibase.Scope;
import liquibase.change.*;
import liquibase.database.Database;
import liquibase.database.core.DB2Database;
import liquibase.database.core.Db2zDatabase;
import liquibase.database.core.HsqlDatabase;
import liquibase.database.core.InformixDatabase;
import liquibase.database.core.MSSQLDatabase;
import liquibase.database.core.OracleDatabase;
import liquibase.database.core.SybaseASADatabase;
import liquibase.datatype.DataTypeFactory;
import liquibase.exception.ValidationErrors;
import liquibase.servicelocator.PrioritizedService;
import liquibase.snapshot.SnapshotGeneratorFactory;
import liquibase.statement.NotNullConstraint;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.CreateTableStatement;
import liquibase.statement.core.RawSqlStatement;
import liquibase.statement.core.ReorganizeTableStatement;
import liquibase.structure.core.Column;
import liquibase.structure.core.ForeignKey;
import liquibase.structure.core.Table;
import liquibase.change.core.AddLookupTableChange;
import static liquibase.statement.SqlStatement.EMPTY_SQL_STATEMENT;

/**
* Extracts data from an existing column to create a lookup table.
* A foreign key is created between the old column and the new lookup table.
*/
@DatabaseChange(name = "addLookupTable", priority = DatabricksDatabase.PRIORITY_DATABASE + 500, appliesTo = "column",
//TODO this class need refactoring as it copies parent class instead of properly inheriting it.
@DatabaseChange(name = "addLookupTable", priority = PrioritizedService.PRIORITY_DATABASE, appliesTo = "column",
description = "Creates a lookup table containing values stored in a column and creates a foreign key to the new table.")
public class AddLookupTableChangeDatabricks extends AddLookupTableChange {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

import liquibase.change.AbstractChange;
import liquibase.change.Change;
import liquibase.change.ChangeMetaData;
import liquibase.change.DatabaseChange;
import liquibase.database.Database;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import java.util.Collections;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Map;

@DatabaseChange(name = "analyzeTable", description = "Analyze Table Stats", priority = ChangeMetaData.PRIORITY_DEFAULT)
@DatabaseChange(name = "analyzeTable", description = "Analyze Table Stats", priority = PrioritizedService.PRIORITY_DATABASE)
public class AnalyzeTableChange extends AbstractChange {

private String catalogName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import liquibase.change.core.CreateTableChange;
import liquibase.database.Database;
import liquibase.exception.ValidationErrors;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.core.CreateTableStatement;


@DatabaseChange(name = "createTable", description = "Create Table", priority = PrioritizedService.PRIORITY_DATABASE +500)
@DatabaseChange(name = "createTable", description = "Create Table", priority = PrioritizedService.PRIORITY_DATABASE)
public class CreateTableChangeDatabricks extends CreateTableChange {

private String tableFormat;
Expand All @@ -18,6 +19,10 @@ public class CreateTableChangeDatabricks extends CreateTableChange {
private String partitionColumns;
private ExtendedTableProperties extendedTableProperties;

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
public ValidationErrors validate(Database database) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import liquibase.change.DatabaseChangeProperty;
import liquibase.database.Database;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;

import java.text.MessageFormat;

@DatabaseChange(name = "dropCheckConstraint", description = "Drops check constraint to Delta Table", priority = DatabricksDatabase.PRIORITY_DEFAULT + 200)
@DatabaseChange(name = "dropCheckConstraint", description = "Drops check constraint to Delta Table", priority = PrioritizedService.PRIORITY_DATABASE)
public class DropCheckConstraintChangeDatabricks extends AbstractChange {

private String catalogName;
Expand Down Expand Up @@ -43,6 +44,10 @@ public void setSchemaName (String schemaName) {
this.schemaName = schemaName;
}

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

// Name of Delta Table Constraint
@DatabaseChangeProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import liquibase.change.ChangeMetaData;
import liquibase.change.DatabaseChange;
import liquibase.database.Database;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import liquibase.change.Change;

import java.text.MessageFormat;
import java.util.ArrayList;

@DatabaseChange(name = "optimizeTable", description = "Optimize and ZOrder Table", priority = ChangeMetaData.PRIORITY_DEFAULT)
@DatabaseChange(name = "optimizeTable", description = "Optimize and ZOrder Table", priority = PrioritizedService.PRIORITY_DATABASE)
public class OptimizeTableChange extends AbstractChange {

private String catalogName;
Expand Down Expand Up @@ -56,6 +58,11 @@ public String getConfirmationMessage() {
return MessageFormat.format("{0}.{1}.{2} successfully optimized.", getCatalogName(), getSchemaName(), getTableName());
}

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
protected Change[] createInverses() {
// No Op for Databricks optimize statement. there is no rolling this back.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import liquibase.change.ChangeMetaData;
import liquibase.change.DatabaseChange;
import liquibase.database.Database;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;

import java.text.MessageFormat;

@DatabaseChange(name = "vacuumTable", description = "Vacuum Old Files from Table", priority = ChangeMetaData.PRIORITY_DEFAULT + 200)
@DatabaseChange(name = "vacuumTable", description = "Vacuum Old Files from Table", priority = PrioritizedService.PRIORITY_DATABASE)
public class VacuumTableChange extends AbstractChange {

private String catalogName;
Expand Down Expand Up @@ -55,6 +57,11 @@ public String getConfirmationMessage() {
return MessageFormat.format("{0}.{1}.{2} successfully vacuumed.", getCatalogName(), getSchemaName(), getTableName());
}

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
protected Change[] createInverses() {
// No Op for Databricks optimize statement. there is no rolling this back.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean supports(String url) {

@Override
public int getPriority() {
return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE;
return PRIORITY_DATABASE;
}

@Override
Expand Down
Loading

0 comments on commit ccb630e

Please sign in to comment.