Skip to content

Commit

Permalink
[DAT-18258] refactoring (#170)
Browse files Browse the repository at this point in the history
* refactoring

* updated pom, added 1 test

* put liquibase-core back

* checking liquibase-core dependency

* added surefire

* added jsonAssert, removed IT test from default execution

* chore: convert groovy tests to java + add slf4j api

* fix: correct test file name

* ignored new version of advanced test for now

---------

Co-authored-by: filipe <[email protected]>
  • Loading branch information
KushnirykOleh and filipelautert authored Sep 10, 2024
1 parent 0c6e3a5 commit 7b9923c
Show file tree
Hide file tree
Showing 57 changed files with 302 additions and 1,259 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
liquibase-support-level: [Foundational, Contributed, Advanced] # Define the different test levels to run
liquibase-support-level: [Foundational, Contributed] # Define the different test levels to run
fail-fast: false # Set fail-fast to false to run all test levels even if some of them fail

steps:
Expand Down
124 changes: 42 additions & 82 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-parent-pom</artifactId>
<version>0.4.5</version> <!-- Replace with the desired version -->
</parent>

<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-databricks</artifactId>
<version>1.4.0-SNAPSHOT</version>
Expand Down Expand Up @@ -56,11 +62,10 @@
<sonar.scm.provider>git</sonar.scm.provider>
<sonar.qualitygate.wait>true</sonar.qualitygate.wait>
<sonar.sources>src/main/java</sonar.sources>
<sonar.tests>src/test/groovy</sonar.tests>

<groovy.version>2.4.21</groovy.version>
<dependency.spock.version>1.3-groovy-2.4</dependency.spock.version>

<sonar.tests>src/test</sonar.tests>
<liquibase-test-harness.version>1.0.10</liquibase-test-harness.version>
<junit.version>5.11.0</junit.version>
<junit-platform.version>1.11.0</junit-platform.version>
<jacoco.fileset.directory>target</jacoco.fileset.directory>
</properties>

Expand All @@ -71,60 +76,53 @@
<version>${liquibase.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.13.2</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-test-harness</artifactId>
<version>1.0.9</version>
<scope>test</scope>
<groupId>com.databricks</groupId>
<artifactId>databricks-jdbc</artifactId>
<version>2.6.40</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.3</version>
<scope>test</scope>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.databricks</groupId>
<artifactId>databricks-jdbc</artifactId>
<version>2.6.40</version>
<scope>test</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
<scope>test</scope>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-testng</artifactId>
</exclusion>
</exclusions>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>${junit-platform.version}</version>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>${dependency.spock.version}</version>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.databricks</groupId>
<artifactId>databricks-jdbc</artifactId>
<version>2.6.40</version>
<scope>compile</scope>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>${jsonassert.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down Expand Up @@ -153,15 +151,6 @@
</configuration>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reportFormat>plain</reportFormat>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down Expand Up @@ -193,35 +182,6 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
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 7b9923c

Please sign in to comment.