我尝试更新21-points.com应用以使用latest code中的JHipster Mini-Book。这是我到目前为止所做的:
使用Heroku的pg:pull
命令将我的生产数据库复制到本地数据库:
heroku pg:pull HEROKU_POSTGRESQL_GRAY_URL health --app health-by-points
安装Liquibase并将PostgreSQL数据库驱动程序复制到$ LIQUIBASE_HOME / lib。
[mraible:/opt/tools/liquibase-3.5.3-bin] % cp ~/.m2/repository/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar lib/.
Ran liquibase的“diffChangeLog”生成一个更改日志,以便从旧数据库迁移到新模式。
./liquibase \
--driver=org.postgresql.Driver --url=jdbc:postgresql://localhost:5432/health --username=postgres \
diffChangeLog \
--referenceUrl=jdbc:postgresql://localhost:5432/twentyonepoints \
--referenceUsername=twentyonepoints --referencePassword=21points
将输出复制到src/main/resources/config/liquibase/changelog/20171024115100_migrate_from_v2.xml
并添加到config/liquibase/master.xml
。
在我最新的JHipster应用程序中更改了application-prod.xml
,指向我从Heroku下载的旧数据库。
跑./gradlew -Pprod
。启动时出错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/jhipster/health/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ValidationFailedException: Validation Failed:
2 change sets check sum
config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000000::jhipster was: 7:eda8cd7fd15284e6128be97bd8edea82 but is now: 7:a6235f40597a13436aa36c6d61db2269
config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster was: 7:e87abbb935c561251405aea5c91bc3a4 but is now: 7:29cf7a7467c2961e7a2366c4347704d7
使用以下命令更新数据库中的md5sum。
update databasechangelog set md5sum = '7:a6235f40597a13436aa36c6d61db2269' where md5sum = '7:eda8cd7fd15284e6128be97bd8edea82';
update databasechangelog set md5sum = '7:29cf7a7467c2961e7a2366c4347704d7' where md5sum = '7:e87abbb935c561251405aea5c91bc3a4’;
试图再次跑。
2017-10-24 12:12:02.670 ERROR 22960 --- [ main] liquibase : classpath:config/liquibase/master.xml: config/liquibase/changelog/20160831020048_added_entity_Points.xml::20160831020048-1::jhipster: Change Set config/liquibase/changelog/20160831020048_added_entity_Points.xml::20160831020048-1::jhipster failed. Error: ERROR: relation "points" already exists [Failed SQL: CREATE TABLE public.points (id BIGINT NOT NULL, jhi_date date NOT NULL, exercise INT, meals INT, alcohol INT, notes VARCHAR(140), user_id BIGINT, CONSTRAINT PK_POINTS PRIMARY KEY (id))]
2017-10-24 12:12:02.672 WARN 22960 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/jhipster/health/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20160831020048_added_entity_Points.xml::20160831020048-1::jhipster:
Reason: liquibase.exception.DatabaseException: ERROR: relation "points" already exists [Failed SQL: CREATE TABLE public.points (id BIGINT NOT NULL, jhi_date date NOT NULL, exercise INT, meals INT, alcohol INT, notes VARCHAR(140), user_id BIGINT, CONSTRAINT PK_POINTS PRIMARY KEY (id))]
知道它为什么要再次创建我的数据库表吗?是因为我改变了md5sum吗?
这些看起来像是从旧的JHipster生成的架构迁移到全新架构时要采取的正确步骤吗?旧架构和新架构之间的唯一区别是旧架构在preferences_id
表中有user
列,而新架构在user_id
表中有preferences
列
答案 0 :(得分:1)
我会做的几乎一样:在第7步,我会继续使用liquibase方法来处理校验和,即我会从命令行使用clearCheckSums,然后在下一次运行时,所有校验和都将被重新计算并且如果在步骤8中仍然存在关于想要再次运行的脚本的错误,那么您可以从命令行使用changelogSync,如:
./liquibase --driver=org.postgresql.Driver --url=jdbc:postgresql://localhost:5432/health
--username=postgres clearCheckSums
./liquibase --driver=org.postgresql.Driver --url=jdbc:postgresql://localhost:5432/health
--username=postgres changelogSync