liquibase创建postgis“geometry”类型的表

htzpubme  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(503)

我正在编写一个liquibase脚本来创建一个表 Geometry 列(来自postgresql db的postgis扩展)
然而,我没能使它工作。我的剧本:

- changeSet:
      id: 5-change-set-places
      comment: Create places table
      author: LongLe
      validCheckSum: 1:any
      changes:
        - sql:
            dbms: postgresql
            endDelimiter: ;
            splitStatements: true
            sql: |
              CREATE TABLE IF NOT EXISTS "${schema}"."places" (
                "id" bigint NOT NULL,
                "geom" GEOMETRY(Geometry, 4326) NOT NULL
              );
              GRANT SELECT, INSERT, UPDATE, DELETE ON "${schema}"."places" TO "${rolename}";
              ALTER TABLE "${schema}"."places"
                DROP CONSTRAINT IF EXISTS "places_pkey",
                ADD CONSTRAINT "places_pkey" PRIMARY KEY ("id");

但是,它失败了,错误如下:

ERROR: type "geometry" does not exist

我还提到了液化空间扩展https://github.com/lonnyj/liquibase-spatial 并组成等效配置:

- changeSet:
      id: 5-change-set-places
      comment: Create places table
      author: LongLe
      validCheckSum: 1:any
      changes:
        - createTable:
            columns:
              - column:
                  constraints:
                    nullable: false
                    primaryKey: true
                    primaryKeyName: places_pkey
                  name: id
                  type: bigint
              - column:
                  constraints:
                    nullable: false
                  name: geom
                  type: GEOMETRY(Geometry,4326)
            tableName: test

但还是失败了,错误是:
31-03-2021 21:07:31.587[main]警告c.m.ms.block…applyliquibase-应用liquibase尝试5时出错:更改集的迁移失败classpath:db/changelog/db.changelog-master.yaml::5-change-set-places::longle:原因:liquibase.exception.databaseexception:错误:类型“geometry”不存在位置:67[失败的sql:创建表]testschema.places(id bigint not null,geom geometry(geometry,4326)not null,constraint places\u pkey primary key(id))]
但是当我从日志中取出sql来运行时:

CREATE TABLE testschema.places (id BIGINT NOT NULL, geom geometry(Geometry, 4326) NOT NULL, CONSTRAINT places_pkey PRIMARY KEY (id))

那就行了。
我一定错过了一些很简单的事情,但我毫无头绪地检查了一下。有人有更好的主意吗?

tkqqtvp1

tkqqtvp11#

确保你已经跑了

CREATE EXTENSION postgis;

然后使用schema限定数据类型。如果扩展是在中创建的 public ,使用

CREATE TABLE places (geom public.geometry, ...);

相关问题