Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KushnirykOleh committed Aug 30, 2024
1 parent 7c1e317 commit 4ec7676
Show file tree
Hide file tree
Showing 39 changed files with 115 additions and 1,154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import lombok.Getter;
import lombok.Setter;

import java.text.MessageFormat;

Expand All @@ -14,56 +16,27 @@
priority = PrioritizedService.PRIORITY_DATABASE,
appliesTo = {"column"}
)
@Setter
@Getter
public class AddCheckConstraintChangeDatabricks extends AbstractChange {

private String catalogName;
private String schemaName;
private String tableName;

private String constraintName;

private String constraintBody;


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

public String getCatalogName() {
return catalogName;
}

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

public String getTableName() {
return tableName;
}

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

public String getSchemaName() {
return schemaName;
}

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

// Name of Delta Table Constraint
@DatabaseChangeProperty(description = "Name of the check constraint")
public String getConstraintName() {
return this.constraintName;
}

public void setConstraintName(String name) {
this.constraintName = name;
}

// This is the SQL expression involving the constraint
@DatabaseChangeProperty(
serializationType = SerializationType.DIRECT_VALUE
Expand All @@ -72,24 +45,20 @@ public String getConstraintBody() {
return this.constraintBody;
}

public void setConstraintBody(String body) {
this.constraintBody = body;
}

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

protected Change[] createInverses() {
DropCheckConstraintChangeDatabricks var1 = new DropCheckConstraintChangeDatabricks();
var1.setTableName(getTableName());
var1.setSchemaName(getSchemaName());
var1.setCatalogName(getCatalogName());
var1.setConstraintName(getConstraintName());
DropCheckConstraintChangeDatabricks inverse = new DropCheckConstraintChangeDatabricks();
inverse.setTableName(getTableName());
inverse.setSchemaName(getSchemaName());
inverse.setCatalogName(getCatalogName());
inverse.setConstraintName(getConstraintName());

return new Change[]{var1};
return new Change[]{inverse};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package liquibase.ext.databricks.change.addCheckConstraint;


import liquibase.database.Database;
import liquibase.exception.ValidationErrors;
import liquibase.ext.databricks.change.addCheckConstraint.AddCheckConstraintStatementDatabricks;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.database.Database;
import liquibase.exception.ValidationErrors;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.core.AbstractSqlGenerator;

public class AddCheckConstraintGeneratorDatabricks extends AbstractSqlGenerator<AddCheckConstraintStatementDatabricks> {
Expand Down Expand Up @@ -44,10 +38,7 @@ public Sql[] generateSql(AddCheckConstraintStatementDatabricks statement, Databa
// Constrinat Name
sql.append(statement.getConstraintName());

sql.append(" CHECK (");

sql.append(statement.getConstraintBody().toString() + ")");

sql.append(" CHECK (").append(statement.getConstraintBody()).append(")");

return new Sql[] { new UnparsedSql(sql.toString()) };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
package liquibase.ext.databricks.change.addCheckConstraint;

import liquibase.statement.AbstractSqlStatement;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class AddCheckConstraintStatementDatabricks extends AbstractSqlStatement {
private String catalogName;
private String schemaName;
private String tableName;
private String constraintName;
private String constraintBody;


public String getCatalogName() {
return this.catalogName;
}

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


public String getSchemaName() {
return this.schemaName;
}

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

public String getTableName() {
return this.tableName;
}

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

public String getConstraintName() {
return this.constraintName;
}

public void setConstraintName(String constraintName) {this.constraintName = constraintName;}

public String getConstraintBody() {
return this.constraintBody;
}

public void setConstraintBody(String constraintBody) {
this.constraintBody = constraintBody;
}
}
Loading

0 comments on commit 4ec7676

Please sign in to comment.