From 6b139309ed76e88989568a0b45048c0683364dfe Mon Sep 17 00:00:00 2001 From: filipe Date: Fri, 4 Oct 2024 14:44:57 -0300 Subject: [PATCH] feat: Generated Snapshots should reference Databricks XSD --- .../parser/NamespaceDetailsDatabricks.java | 55 +++++++++++++++++++ .../liquibase.parser.NamespaceDetails | 1 + 2 files changed, 56 insertions(+) create mode 100644 src/main/java/liquibase/ext/databricks/parser/NamespaceDetailsDatabricks.java create mode 100644 src/main/resources/META-INF/services/liquibase.parser.NamespaceDetails diff --git a/src/main/java/liquibase/ext/databricks/parser/NamespaceDetailsDatabricks.java b/src/main/java/liquibase/ext/databricks/parser/NamespaceDetailsDatabricks.java new file mode 100644 index 00000000..33994df2 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/parser/NamespaceDetailsDatabricks.java @@ -0,0 +1,55 @@ +package liquibase.ext.databricks.parser; + +import liquibase.parser.LiquibaseParser; +import liquibase.parser.NamespaceDetails; +import liquibase.parser.core.xml.XMLChangeLogSAXParser; +import liquibase.serializer.LiquibaseSerializer; +import liquibase.serializer.core.xml.XMLChangeLogSerializer; + +/** + * Namespace details for Databricks extension. + * It is used by Liquibase when generating changelogs - ie during a snapshot. + */ +public class NamespaceDetailsDatabricks implements NamespaceDetails { + + public static final String DATABRICKS_NAMESPACE = "http://www.liquibase.org/xml/ns/databricks"; + + public static final String DATABRICKS_XSD = "http://www.liquibase.org/xml/ns/databricks/liquibase-databricks-latest.xsd"; + + @Override + public int getPriority() { + return PRIORITY_EXTENSION; + } + + @Override + public boolean supports(LiquibaseSerializer serializer, String namespace) { + return namespaceCorrect(namespace) && serializer instanceof XMLChangeLogSerializer; + } + + @Override + public boolean supports(LiquibaseParser parser, String namespace) { + return namespaceCorrect(namespace) && parser instanceof XMLChangeLogSAXParser; + } + + @Override + public String getShortName(String namespace) { + return "databricks"; + } + + @Override + public String getSchemaUrl(String namespace) { + return DATABRICKS_XSD; + } + + @Override + public String[] getNamespaces() { + return new String[]{ + DATABRICKS_NAMESPACE + }; + } + + private boolean namespaceCorrect(String namespace) { + return namespace.equals(DATABRICKS_NAMESPACE) || namespace.equals(DATABRICKS_XSD); + } + +} diff --git a/src/main/resources/META-INF/services/liquibase.parser.NamespaceDetails b/src/main/resources/META-INF/services/liquibase.parser.NamespaceDetails new file mode 100644 index 00000000..351dd668 --- /dev/null +++ b/src/main/resources/META-INF/services/liquibase.parser.NamespaceDetails @@ -0,0 +1 @@ +liquibase.ext.databricks.parser.NamespaceDetailsDatabricks