【发布时间】:2020-11-20 00:36:31
【问题描述】:
我正在构建一个小型 spring-boot 应用程序。我正在使用 spring-data-jpa 创建数据库架构,并使用 liquibase 来填充测试数据。
application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/book-db
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=admin
spring.datasource.password=lTIDDYz3n3jD3BeYaAJz
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
根据文档,如果我在默认路径下有 gradle 依赖项和 master changeLog,则不需要配置 liquibase。
db.changelog-master.yaml:
databaseChangeLog:
- changeSet:
id: 1
author: jb
changes:
- sqlFile:
path: db/migration/insert-books.sql
插入-books.sql:
--liquibase formatted sql
--changeset admin:1
delete from book;
insert into book (id, title)
values (nextval('seq'), 'Functional Programming for Mortals');
commit;
我已经尝试过使用和不使用commit。表 databasechangelog 和 databasechangelog 已成功创建并包含迁移(插入书籍)。
迁移完成,因为如果我添加无效插入(到某些不存在的表),我会得到异常:
ERROR: relation "xxx" does not exist
如何使用 liquibase 在 insert-books.sql 脚本中填充数据?
【问题讨论】:
标签: java spring-boot hibernate spring-data-jpa liquibase