lonnyj / liquibase-spatial Goto Github PK
View Code? Open in Web Editor NEWLiquibase Spatial is an extension to Liquibase to handle spatial indexing and geometry types
License: Apache License 2.0
Liquibase Spatial is an extension to Liquibase to handle spatial indexing and geometry types
License: Apache License 2.0
There were API changes in Liquibase 3.3.0. Update the library to work with these changes.
Hi,
I am new to geospatial datatypes, i am using postgresSql database and PostGIS. I added all the required jars like liquibase-core 3.2, liquibase-spatial 1.0.0, postgresql 9.2, postgis-jdbc 2.1.3.
This is my liquibase script,
when i run mvn liquibase:update from cygwin, i am getting the error,
liquibase.exception.DatabaseException: Error executing SQL CREATE TABLE geo.CIRCLE (GEOFENCEID INT NOT NULL, RADIUS INT NOT NULL, CENTERPOINT GEOMETRY(point, 4326) NOT NULL, CONSTRAINT PK_CIRCLE PRIMARY KEY (GEOFENCEID)): ERROR: type "geometry" does not exist
Please help me on this issue
<preConditions>
<spatial:spatialSupported/>
</preConditions>
<createTable tableName="CIRCLE">
<column name="GEOFENCEID" type="int">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_CIRCLE" />
</column>
<column name="RADIUS" type="int">
<constraints nullable="false" />
</column>
<column name="CENTERPOINT" type="GEOMETRY(point,4326)">
<constraints nullable="false" />
</column>
</createTable>
I'm using Liquibase to update my database from two sides:
Running via included file from the db-changelog-master.xml like the following code snippet works for now. (By setting validCheckSum to ANY. But without it database updates only succeed when run from one of the two sides described above. F.i. when it has run via SpringLiquibase, and is run again via SpringLiquibase, all is fine. Checksum is ok. But when I then update the database via Maven a checksum error occurs. The checksum is different when run from Maven then when run from SpringLiquibase.
The checksum error only occurs at the changeSet that creates the spatial index (createSpatialIndex). All others are ok (create spatial table, insert spatial data).
Using: Java 7, Postgresql 9.4 with postgis, Spring 4.1.6, Liquibase 3.3.3, Liquibase-spacial 1.2.1, liquibase-postgresql 3.0
Note: Same checksum error occurs when using another extension, liquibase-postgresql. See liquibase/liquibase-postgresql#1
File db-changelog-master.xml:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"
logicalFilePath="db-changelog-master.xml">
<include file="db-changelog-spacial-example.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Spring config:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="dataSource" />
<property name="changeLog" value="classpath:db/changelog/db-changelog-master.xml" />
<property name="defaultSchema" value="${jdbc.defaultSchema}" />
</bean>
</beans>
db-changelog-spacial-example.xml:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spatial="http://www.liquibase.org/xml/ns/dbchangelog-ext/liquibase-spatial"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext/liquibase-spatial
http://lonnyj.github.com/liquibase-spatial/liquibase-spatial.xsd"
logicalFilePath="db-changelog-spacial-example.xml">
<changeSet id="create spatial table" author="bvlangen">
<preConditions>
<spatial:spatialSupported />
</preConditions>
<comment>Create a spatial table</comment>
<createTable tableName="EXAMPLE">
<column name="ID" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="EXAMPLE_PK" />
</column>
<column name="GEOM" type="GEOMETRY(Point, 4326)">
<constraints nullable="false" />
</column>
</createTable>
</changeSet>
<changeSet id="Create spatial index" author="bvlangen">
<!-- Checksum differs when run from Maven or Spring, therefore set to valid ANY and added precondition -->
<validCheckSum>ANY</validCheckSum>
<preConditions>
<not>
<spatial:spatialIndexExists tableName="EXAMPLE" columnNames="GEOM" />
</not>
</preConditions>
<comment>Create spatial index</comment>
<spatial:createSpatialIndex tableName="EXAMPLE" indexName="EXAMPLE_GEOM_IDX" geometryType="Point" srid="4326">
<column name="GEOM" />
</spatial:createSpatialIndex>
</changeSet>
<changeSet id="insert spatial data" author="bvlangen">
<comment>Insert spatial data</comment>
<insert tableName="EXAMPLE">
<column name="ID" valueNumeric="1" />
<column name="GEOM" value="SRID=4326;POINT(-5 -5)" />
</insert>
<insert tableName="EXAMPLE">
<column name="ID" valueNumeric="2" />
<column name="GEOM" value="SRID=4326;POINT(0 0)" />
</insert>
<insert tableName="EXAMPLE">
<column name="ID" valueNumeric="3" />
<column name="GEOM" value="SRID=4326;POINT(5 5)" />
</insert>
</changeSet>
</databaseChangeLog>
On http://lonnyj.github.io/liquibase-spatial/liquibase-spatial.xsd the createSpatialIndex srid attribute is declared as integer:
<xsd:attributeGroup name="createSpatialIndex">
<xsd:annotation>
<!-- .... -->
<!-- .... -->
<xsd:attribute name="srid" type="xsd:integer"/>
So, I get a parse exception when I try something like this:
<spatial:createSpatialIndex tableName="kp"
indexName="ix_kp_geometry"
geometryType="Point" srid="${pom.base-crs}">
<column name="geometry" />
</spatial:createSpatialIndex>
Here's a patch for supporting SAP Hana I wrote for a previous job. Seemed to work, but didn't do any full testing of it.
Author: Matthew Peveler <[email protected]>
Date: Fri Aug 21 13:42:17 2015 -0400
Add SAP Hana Support
diff --git a/.gitignore b/.gitignore
index 6d7d4fd..ce596f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@
/test-output
/derby.log
/pom.xml.bak
+.idea
+*.iml
\ No newline at end of file
diff --git a/README.md b/README.md
index 98410dc..2bb2185 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,13 @@ Liquibase Spatial
Liquibase Spatial is an extension to Liquibase to handle spatial indexing and geometry types. It
requires Liquibase 3.1.1 or newer.
+This is a special build that includes SAP Hana support using [liquibase-hana](https://github.com/lbitonti/liquibase-hana) extension.
+To build, you need to:
+```
+mvn install:install-file -Dfile=liquibase-hana-3.1-SNAPSHOT.jar
+mvn package
+```
+
<table>
<tr>
<th>Liquibase Version</th>
@@ -20,6 +27,10 @@ requires Liquibase 3.1.1 or newer.
<td>Liquibase 3.3.x</td>
<td>Liquibase Spatial 1.2.x</td>
</tr>
+ <tr>
+ <td>Liquibase 3.4.x</td>
+ <td>Liquibase Spatial 1.2.x</td>
+ </tr>
</table>
In order to use this extension, you must have the [<code>liquibase-spatial</code>](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.lonnyj%22%20AND%20a%3A%22liquibase-spatial%22)
diff --git a/liquibase-hana-3.1-SNAPSHOT.jar b/liquibase-hana-3.1-SNAPSHOT.jar
new file mode 100644
index 0000000..cc5b556
Binary files /dev/null and b/liquibase-hana-3.1-SNAPSHOT.jar differ
diff --git a/pom.xml b/pom.xml
index b85775b..a112342 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,7 +78,7 @@
<hatbox.version>1.0.b9</hatbox.version>
<h2.version>1.4.177</h2.version>
<jts.version>1.13</jts.version>
- <liquibase.version>3.3.0</liquibase.version>
+ <liquibase.version>3.4.1</liquibase.version>
</properties>
<dependencies>
@@ -122,6 +122,11 @@
<version>6.8.17</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.liquibase.ext</groupId>
+ <artifactId>liquibase-hana</artifactId>
+ <version>3.1-SNAPSHOT</version>
+ </dependency>
</dependencies>
<build>
diff --git a/src/main/java/liquibase/ext/spatial/datatype/GeometryType.java b/src/main/java/liquibase/ext/spatial/datatype/GeometryType.java
index b098a30..fd64d69 100644
--- a/src/main/java/liquibase/ext/spatial/datatype/GeometryType.java
+++ b/src/main/java/liquibase/ext/spatial/datatype/GeometryType.java
@@ -3,6 +3,7 @@ package liquibase.ext.spatial.datatype;
import liquibase.database.Database;
import liquibase.database.core.DerbyDatabase;
import liquibase.database.core.H2Database;
+import liquibase.database.ext.HanaDBDatabase;
import liquibase.database.core.OracleDatabase;
import liquibase.database.core.PostgresDatabase;
import liquibase.datatype.DataTypeInfo;
@@ -62,6 +63,8 @@ public class GeometryType extends LiquibaseDataType {
databaseDataType = new DatabaseDataType("SDO_GEOMETRY");
} else if (database instanceof PostgresDatabase) {
databaseDataType = new DatabaseDataType(getName(), getParameters());
+ } else if (database instanceof HanaDBDatabase) {
+ databaseDataType = new DatabaseDataType("ST_GEOMETRY", getParameters());
} else {
databaseDataType = new DatabaseDataType("GEOMETRY");
}
diff --git a/src/main/java/liquibase/ext/spatial/preconditions/SpatialSupportedPrecondition.java b/src/main/java/liquibase/ext/spatial/preconditions/SpatialSupportedPrecondition.java
index 4c313e7..65f79c1 100644
--- a/src/main/java/liquibase/ext/spatial/preconditions/SpatialSupportedPrecondition.java
+++ b/src/main/java/liquibase/ext/spatial/preconditions/SpatialSupportedPrecondition.java
@@ -11,6 +11,7 @@ import liquibase.database.core.H2Database;
import liquibase.database.core.MySQLDatabase;
import liquibase.database.core.OracleDatabase;
import liquibase.database.core.PostgresDatabase;
+import liquibase.database.ext.HanaDBDatabase;
import liquibase.exception.DatabaseException;
import liquibase.exception.LiquibaseException;
import liquibase.exception.PreconditionErrorException;
@@ -45,7 +46,8 @@ public class SpatialSupportedPrecondition extends AbstractPrecondition {
public Warnings warn(final Database database) {
final Warnings warnings = new Warnings();
if (!(database instanceof DerbyDatabase || database instanceof H2Database
- || database instanceof MySQLDatabase || database instanceof OracleDatabase || database instanceof PostgresDatabase)) {
+ || database instanceof MySQLDatabase || database instanceof OracleDatabase
+ || database instanceof PostgresDatabase || database instanceof HanaDBDatabase)) {
warnings.addWarning(database.getDatabaseProductName()
+ " is not supported by this extension");
}
@@ -56,7 +58,8 @@ public class SpatialSupportedPrecondition extends AbstractPrecondition {
public ValidationErrors validate(final Database database) {
final ValidationErrors errors = new ValidationErrors();
if (!(database instanceof DerbyDatabase || database instanceof H2Database
- || database instanceof MySQLDatabase || database instanceof OracleDatabase || database instanceof PostgresDatabase)) {
+ || database instanceof MySQLDatabase || database instanceof OracleDatabase
+ || database instanceof PostgresDatabase || database instanceof HanaDBDatabase)) {
errors.addError(database.getDatabaseProductName() + " is not supported by this extension");
}
return errors;
@@ -89,6 +92,11 @@ public class SpatialSupportedPrecondition extends AbstractPrecondition {
} catch (final DatabaseException e) {
throw new PreconditionErrorException(e, changeLog, this);
}
+ } else if (database instanceof HanaDBDatabase) {
+ final ViewExistsPrecondition precondition = new ViewExistsPrecondition();
+ precondition.setSchemaName("SYS");
+ precondition.setViewName("ST_SPATIAL_REFERENCE_SYSTEMS_");
+ precondition.check(database, changeLog, changeSet);
} else if (!(database instanceof MySQLDatabase)) {
final Throwable exception = new LiquibaseException(database.getDatabaseProductName()
+ " is not supported by this extension");
diff --git a/src/main/java/liquibase/ext/spatial/sqlgenerator/SpatialInsertGeneratorHanaDB.java b/src/main/java/liquibase/ext/spatial/sqlgenerator/SpatialInsertGeneratorHanaDB.java
new file mode 100644
index 0000000..a840319
--- /dev/null
+++ b/src/main/java/liquibase/ext/spatial/sqlgenerator/SpatialInsertGeneratorHanaDB.java
@@ -0,0 +1,23 @@
+package liquibase.ext.spatial.sqlgenerator;
+
+import liquibase.database.Database;
+import liquibase.database.ext.HanaDBDatabase;
+import liquibase.statement.core.InsertStatement;
+
+public class SpatialInsertGeneratorHanaDB extends AbstractSpatialInsertGenerator {
+
+ @Override
+ public boolean supports(final InsertStatement statement, final Database database) {
+ return database instanceof HanaDBDatabase;
+ }
+
+ @Override
+ public String getGeomFromWktFunction() {
+ return "ST_GeomFromText";
+ }
+
+ @Override
+ public String convertToFunction(final String wkt, final String srid, final Database database) {
+ return super.convertToFunction(wkt, srid, database);
+ }
+}
diff --git a/src/main/java/liquibase/ext/spatial/sqlgenerator/SpatialUpdateGeneratorHanaDB.java b/src/main/java/liquibase/ext/spatial/sqlgenerator/SpatialUpdateGeneratorHanaDB.java
new file mode 100644
index 0000000..f33931a
--- /dev/null
+++ b/src/main/java/liquibase/ext/spatial/sqlgenerator/SpatialUpdateGeneratorHanaDB.java
@@ -0,0 +1,22 @@
+package liquibase.ext.spatial.sqlgenerator;
+
+import liquibase.database.Database;
+import liquibase.database.ext.HanaDBDatabase;
+import liquibase.statement.core.UpdateStatement;
+
+public class SpatialUpdateGeneratorHanaDB extends AbstractSpatialUpdateGenerator{
+ @Override
+ public boolean supports(final UpdateStatement statement, final Database database) {
+ return database instanceof HanaDBDatabase;
+ }
+
+ @Override
+ public String getGeomFromWktFunction() {
+ return "ST_GeomFromText";
+ }
+
+ @Override
+ public String convertToFunction(final String wkt, final String srid, final Database database) {
+ return super.convertToFunction(wkt, srid, database);
+ }
+}
I am working to setup liquibase and when I attempt use the spatial extension with the current version(3.2.2) or any version of liquibase newer than 3.1.1 I get a NoSuchMethodError exception.
Unexpected error running Liquibase: liquibase.exception.UnexpectedLiquibaseException: java.lang.NoSuchMethodError: liquibase.datatype.DataTypeFactory.fromDescription(Ljava/lang/String;)Lliquibase/datatype/LiquibaseDataType;
Upgraded from liquibase-core-3.1 to liquibase-core 4.16.1 (also tried 4.10 and 4.17.2). Used liquibase-spatial 1.1.1 and 1.2.1. Using on Postgresql 11.6.
Everything working but getting error noted above in title. I cannot send a stack trace due to company policy so please don't ask.
Caused by: liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: liquibase.exception.SetupException: liquibase.parser.core.ParsedNodeException: Unknown precodition 'spatialIndexExists'. Check for spelling or capitalization errors and missing extensions such as liquibase-commercial.
Caused by: liquibase.exception.SetupException: liquibase.exception.SetupException: liquibase.parser.core.ParsedNodeException: Unknown precodition 'spatialIndexExists'. Check for spelling or capitalization errors and missing extensions such as liquibase-commercial.
Pseudo code: (had to remove beginning "<" to get text to appear)
// preConditions>
// tableExists tableName="TEST" />
// not>
// spatial:spatialIndexExists tableName="TEST" columnNames="GEOM" />
// /not>
// /preConditions>
PostGIS supports geography datatype that enables easy maintenance and querying of geo spatial data. I hope we get support for the same in liquibase
I have recently created a Spring Boot application where I am using the liquibase spatial index property. My install.xml liquibase file looks something like this:
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:spatial="http://www.liquibase.org/xml/ns/dbchangelog-ext/liquibase-spatial"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext/liquibase-spatial
**http://lonnyj.github.com/liquibase-spatial/liquibase-spatial.xsd**">
After some days, my application suddenly stopped working and I started getting the following error:
2021-04-16 07:21:15,637 [main] WARN l.p.core.xml.XMLChangeLogSAXParser$1 - schema_reference.4: Failed to read schema document 'http://lonnyj.github.com/liquibase-spatial/liquibase-spatial.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema.
It seems that the path got changed all of a sudden. Could you please check and let me know what is the issue?
I have geometry columns and indices with SRID=4326. I'm trying to support Oracle 10gR2+ and Postgres 9+ with as few differences as possible.
The entries in USER_SDO_GEOM_METADATA for my geometry columns should have SRID=4326.
The entries in USER_SDO_GEOM_METADATA for my geometry columns have SRID=8307.
This is happening because the Oracle SQL generator is wrapping the SRID in MAP_EPSG_SRID_TO_ORACLE which in this case is converting EPSG:4326 to the legacy code SDO:8307.
I suspect this may have been done to support older versions of Oracle (pre 10gR2).
Add an option to disable mapping EPSG codes to Oracle codes. I'm thinking a system property like -Dliquibase.ext.spatial.map-epsg-srid-to-oracle=false
would cause the SRIDs to be passed through verbatim.
Hi,
I am attempting to use the liquibase-spatial plugin with my H2 unit tests. The first thing my unit tests always do is to drop all tables in the database, using the dropAll Liquibase method which works just fine until I try to get things working to support spatial data. When I enable this I get the error: Failed to determine is the table has a geometry column.
My pom is copied below and I can provide any additional information.
I'd like to get this working so we can continue to use H2 in our test environments.
Thank you very, very much,
Tim
4.0.0
com.digitalglobe.databaseMigration
databaseMigration
1.0-SNAPSHOT
jar
databaseMigration
http://maven.apache.org
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.