首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grails 3数据库迁移

grails 3数据库迁移
EN

Stack Overflow用户
提问于 2016-08-31 13:44:59
回答 1查看 1.3K关注 0票数 0

我将应用程序更新为grails3.1.9,数据库迁移插件也有问题。

我的产品application.yml如下所示:

代码语言:javascript
复制
   production:
        dataSource:
                driverClassName: org.postgresql.Driver
                dialect: org.hibernate.dialect.PostgreSQLDialect
                dbCreate: none
                url: jdbc:postgresql://localhost:5432/something
                username: postgres
                password: postgres
                properties:

我的build.gradle看起来是这样的:

代码语言:javascript
复制
buildscript {
 dependencies {
        classpath 'org.grails.plugins:database-migration:2.0.0.RC4'
    }
}

    dependencies {
        compile 'org.liquibase:liquibase-core:3.4.1'
        compile 'org.grails.plugins:database-migration:2.0.0.RC4'
    }

这是变革的开始g:

代码语言:javascript
复制
databaseChangeLog = {

    changeSet(author: "michal (generated)", id: "1472650791344-1") {
        createTable(tableName: "appointment") {
            column(autoIncrement: "true", name: "id", type: "BIGINT") {
                constraints(primaryKey: "true", primaryKeyName: "appointmentPK")
            }

            column(name: "version", type: "BIGINT")

            column(name: "customer_id", type: "BIGINT")

            column(name: "duration", type: "BLOB(255)")

            column(name: "note", type: "CLOB")

            column(defaultValueComputed: "0", name: "personal_available", type: "BOOLEAN")

            column(defaultValueComputed: "0", name: "personal_booked", type: "BOOLEAN")

            column(name: "provider_id", type: "BIGINT")

            column(name: "start_time", type: "BLOB(255)")

            column(name: "url", type: "VARCHAR(255)")
        }
    }

当我在生产模式下运行我的应用程序时,我会得到这个错误。

代码语言:javascript
复制
SEVERE 8/31/16 3:41 PM: liquibase: changelog.groovy: changelog.groovy::1472650791344-1::michal (generated): Change Set changelog.groovy::1472650791344-1::michal (generated) failed.  Error: ERROR: relation "appointment" already exists [Failed SQL: CREATE TABLE public.appointment (id BIGSERIAL NOT NULL, version BIGINT, customer_id BIGINT, duration BYTEA, note TEXT, personal_available BOOLEAN DEFAULT 0, personal_booked BOOLEAN DEFAULT 0, provider_id BIGINT, start_time BYTEA, url VARCHAR(255), CONSTRAINT "appointmentPK" PRIMARY KEY (id))]
liquibase.exception.DatabaseException: ERROR: relation "appointment" already exists [Failed SQL: CREATE TABLE public.appointment (id BIGSERIAL NOT NULL, version BIGINT, customer_id BIGINT, duration BYTEA, note TEXT, personal_available BOOLEAN DEFAULT 0, personal_booked BOOLEAN DEFAULT 0, provider_id BIGINT, start_time BYTEA, url VARCHAR(255), CONSTRAINT "appointmentPK" PRIMARY KEY (id))]
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:316)

..。

代码语言:javascript
复制
Caused by: org.postgresql.util.PSQLException: ERROR: relation "appointment" already exists

我会感激任何想法,为什么它不起作用。

谢谢格雷戈·佩金。设置dbcreate来验证确实帮助我修复了这个错误。

EN

回答 1

Stack Overflow用户

发布于 2016-08-31 17:19:44

表已经存在似乎很奇怪,但我昨晚在dev环境中遇到了这样的情况,所以我知道这是可能发生的。例如,即使您有dbCreate: none,可能hbm2ddl迁移工具是由于一个bug而执行的。查查日志。

或者您的databasechangelog表由于某种原因被意外清除。检查数据库表中是否存在对应的特定更改集行。

对于这个特定的变更集,您可以做的一件事是向变更集添加一个tableExists预条件,如果表已经存在,则使用onFail="MARK_RAN"将变更集标记为EXECUTED。Liquibase的作者曾经写道,由于性能问题,应该谨慎地使用预条件。因此,如果你发现自己为每一个变化都创造了一个前提条件,你可能需要重新考虑。

注意,如果收到更多更改集的此错误,则可能需要使用dbm-changelog-sync (http://grails-plugins.github.io/grails-database-migration/1.4.0/ref/Maintenance%20Scripts/dbm-changelog-sync.html)将所有更改集标记为“已执行”,实质上告诉Liquibase在服务器随后重新启动时忽略这些更改集。

如果您确实希望执行一些更改集(而不是忽略) --例如,您最近做了一些更改--那么您可以使用上下文标记“要被忽略的”更改集,然后使用这些值作为context参数运行context命令。

有关更多信息,请参见以下链接。* http://grails-plugins.github.io/grails-database-migration/1.4.0/ref/Maintenance%20Scripts/dbm-changelog-sync.html * http://www.liquibase.org/2014/11/contexts-vs-labels.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39251406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档