Skip to content

Commit

Permalink
Merge pull request #70 from liquibase/update_liquibase_version_and_sn…
Browse files Browse the repository at this point in the history
…apshot

Upgrade to Liquibase 4.25.0
  • Loading branch information
jandroav authored Nov 28, 2023
2 parents 9cb11cb + 3f05b50 commit 9e1ddf6
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 35 deletions.
Binary file added lib/liquibase-extension-testing-4.25.0.jar
Binary file not shown.
60 changes: 32 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-parent-pom</artifactId>
<version>0.2.4</version> <!-- Replace with the desired version -->
<version>0.3.2</version> <!-- Replace with the desired version -->
</parent>

<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-databricks</artifactId>
<version>1.1.0</version>
<version>1.1.1-SNAPSHOT</version>

<name>Liquibase Extension Databricks support</name>
<name>Liquibase Extension Databricks</name>
<description>Liquibase Extension for Databricks.</description>
<url>https://github.com/liquibase/liquibase-databricks</url>

Expand All @@ -26,13 +26,10 @@
</developers>

<properties>
<groovy-all.version>2.4.21</groovy-all.version>
<liquibase.version>4.23.2</liquibase.version>
<gmavenplus-plugin.version>2.1.0</gmavenplus-plugin.version>
<liquibase.version>4.25.0</liquibase.version>
<sonar.tests>src/test/groovy</sonar.tests>
<spock-core.version>1.3-groovy-2.4</spock-core.version>
<spock-reports.version>1.8.0</spock-reports.version>
<junit-platform.version>1.10.0</junit-platform.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<scm>
Expand All @@ -56,29 +53,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>3.1.2</version>
</dependency>
</dependencies>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reportFormat>plain</reportFormat>
</configuration>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
Expand Down Expand Up @@ -123,7 +105,29 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<source>1.8</source>
<author>false</author>
<doctitle>Liquibase ${project.name} ${project.version} API</doctitle>
<quiet>true</quiet>
<doclint>none</doclint>
<encoding>UTF-8</encoding>
<jarOutputDirectory>${project.build.directory}</jarOutputDirectory>
</configuration>
<executions>
<execution>
<id>jar-javadoc</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import liquibase.snapshot.jvm.SequenceSnapshotGenerator;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Schema;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.RawSqlStatement;

public class SequenceSnapshotGeneratorDatabricks extends SequenceSnapshotGenerator {

Expand All @@ -35,7 +37,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot
}

@Override
protected String getSelectSequenceSql(Schema schema, Database database) {
protected SqlStatement getSelectSequenceStatement(Schema schema, Database database) {
if (database instanceof DatabricksDatabase) {
// Databricks does not support sequences

Expand All @@ -50,8 +52,9 @@ protected String getSelectSequenceSql(Schema schema, Database database) {
"AND table_schema = '" + schema.getName() +"' " +
"AND 1=0";

return databricksSequenceSql;
}
return super.getSelectSequenceSql(schema, database);
return new RawSqlStatement(databricksSequenceSql);
}

return super.getSelectSequenceStatement(schema, database);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package liquibase.ext.databricks.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.snapshot.DatabaseSnapshot;
import liquibase.snapshot.jvm.ViewSnapshotGenerator;
import liquibase.statement.core.RawSqlStatement;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Schema;
import liquibase.structure.core.View;
import liquibase.util.StringUtil;

import java.util.List;
import java.util.Map;

import liquibase.ext.databricks.database.DatabricksDatabase;
public class ViewSnapshotGeneratorDatabricks extends ViewSnapshotGenerator {


@Override
public int getPriority(Class<? extends DatabaseObject> objectType, Database database) {
int priority = super.getPriority(objectType, database);
if (priority > PRIORITY_NONE && database instanceof DatabricksDatabase) {
priority += DatabricksDatabase.PRIORITY_DATABASE;
}
return priority;
}

@Override
protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException {
if (((View) example).getDefinition() != null) {
return example;
} else {
Database database = snapshot.getDatabase();
Schema schema = example.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 view_definition FROM %s.%s.VIEWS WHERE table_name='%s' AND table_schema='%s' AND table_catalog='%s';",
schema.getCatalogName(), database.getSystemSchema(), example.getName(), schema.getName(), schema.getCatalogName());

List<Map<String, ?>> viewsMetadataRs = Scope.getCurrentScope().getSingleton(ExecutorService.class)
.getExecutor("jdbc", database).queryForList(new RawSqlStatement(query));

if (viewsMetadataRs.isEmpty()) {
return null;
} else {
Map<String, ?> row = viewsMetadataRs.get(0);
String rawViewName = example.getName();
String rawSchemaName = schema.getName();
String rawCatalogName = schema.getCatalogName();

View view = (new View()).setName(this.cleanNameFromDatabase(rawViewName, database));
CatalogAndSchema schemaFromJdbcInfo = ((AbstractJdbcDatabase) database).getSchemaFromJdbcInfo(rawCatalogName, rawSchemaName);
view.setSchema(new Schema(schemaFromJdbcInfo.getCatalogName(), schemaFromJdbcInfo.getSchemaName()));

String definition = (String) row.get("VIEW_DEFINITION");
if (definition.startsWith("FULL_DEFINITION: ")) {
definition = definition.replaceFirst("^FULL_DEFINITION: ", "");
view.setContainsFullDefinition(true);
}

int length = definition.length();
if (length > 0 && definition.charAt(length - 1) == 0) {
definition = definition.substring(0, length - 1);
}

definition = StringUtil.trimToNull(definition);
if (definition == null) {
definition = "[CANNOT READ VIEW DEFINITION]";
}

view.setDefinition(definition);

return view;
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import liquibase.statement.core.CreateTableStatement;
import liquibase.structure.DatabaseObject;
import liquibase.util.StringUtil;
import org.yaml.snakeyaml.util.ArrayUtils;

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ liquibase.ext.databricks.snapshot.jvm.SequenceSnapshotGeneratorDatabricks
liquibase.ext.databricks.snapshot.jvm.ForeignKeySnapshotGeneratorDatabricks
liquibase.ext.databricks.snapshot.jvm.UniqueConstraintSnapshotGeneratorDatabricks
liquibase.ext.databricks.snapshot.jvm.IndexSnapshotGeneratorDatabricks
liquibase.ext.databricks.snapshot.jvm.ViewSnapshotGeneratorDatabricks
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
-- liquibase formatted sql

CREATE TABLE test_table_xml (test_column INT);

0 comments on commit 9e1ddf6

Please sign in to comment.