postgresql - Liquibase 通过 Docker - 变更日志未写入磁盘

标签 postgresql docker liquibase

我想为本地运行(不在容器中)的 PostgreSQL 数据库设置 Liquibase(使用 Docker)。我学习了多个教程,包括 Docker Hub 上的教程.
按照建议,我创建了一个 liquibase.docker.properties文件在我的 <PATH TO CHANGELOG DIR>

classpath: /liquibase/changelog
url: jdbc:postgresql://localhost:5432/mydb?currentSchema=public
changeLogFile: changelog.xml
username: myuser
password: mypass
能够运行 docker run --rm --net="host" -v <PATH TO CHANGELOG DIR>:/liquibase/changelog liquibase/liquibase --defaultsFile=/liquibase/changelog/liquibase.docker.properties <COMMAND> .
当我跑 [...] generateChangeLog我得到以下输出(带有选项 --logLevel info ):
[2021-04-27 06:08:20] INFO [liquibase.integration] No Liquibase Pro license key supplied. Please set liquibaseProLicenseKey on command line or in liquibase.properties to use Liquibase Pro features.
Liquibase Community 4.3.3 by Datical
####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ## 
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ## 
##  Free schema change activity reports at        ##
##      https://hub.liquibase.com                 ##
##                                                ##
####################################################
Starting Liquibase at 06:08:20 (version 4.3.3 #52 built at 2021-04-12 17:08+0000)
BEST PRACTICE: The changelog generated by diffChangeLog/generateChangeLog should be inspected for correctness and completeness before being deployed.
[2021-04-27 06:08:22] INFO [liquibase.diff] changeSets count: 1
[2021-04-27 06:08:22] INFO [liquibase.diff] changelog.xml does not exist, creating and adding 1 changesets.
Liquibase command 'generateChangeLog' was executed successfully.
看起来命令运行“成功”但 我找不到文件 changelog.xml在我的本地目录 我安装的,即 <PATH TO CHANGELOG DIR> .然而,安装必须工作,因为它成功连接到数据库,即容器能够访问和读取 liquibase.docker.properties .
首先,我想我可能不得不对 Docker“说”它允许在我的磁盘上写入,但似乎应该支持这 [来自 Docker Hub 的描述]:

The /liquibase/changelog volume can also be used for commands that write output, such as generateChangeLog


我错过了什么?在此先感谢您的帮助!

附加信息 docker inspect 的输出:
"Mounts": [
    {
        "Type": "bind",
        "Source": "<PATH TO CHANGELOG DIR>",
        "Destination": "/liquibase/changelog",
        "Mode": "",
        "RW": true,
        "Propagation": "rprivate"
    },
    ...
],

最佳答案

当您运行时 generateChangeLog , 文件路径应指定为 /liquibase/changelog/changelog.xml即使对于 update它需要是 changelog.xml例子:

docker run --rm --net="host" -v <PATH TO CHANGELOG DIR>:/liquibase/changelog liquibase/liquibase --defaultsFile=/liquibase/changelog/liquibase.docker.properties --changeLogFile=/liquibase/changelog/changelog.xml generateChangeLog
对于 generateChangeLog ,changeLogFile 参数是要输出的文件的特定路径与相对于 classpath 的路径设置更新和其他命令使用。
当您包含命令行参数以及上面的 defaultsFile 时,命令行参数将获胜。当特定命令需要更多/不同的命令时,这使您可以在替换特定设置的同时利用相同的默认设置。
详情
创建文件的操作和读取现有文件的操作是有区别的。
使用 Liquibase,您几乎总是希望使用与类路径中的目录相关的文件路径,就像示例中那样。指定的变更日志文件存储在跟踪系统中,因此如果您曾经运行相同的变更日志但以不同的方式引用(因为您移动了根目录或从不同的机器运行),那么 Liquibase 会将其视为一个新文件并尝试重新运行已经运行的变更集。
这就是为什么文档有 classpath: /liquibase/changelogchangeLogFile: com/example/changelog.xml . update操作在/liquibase/changelog 目录中查找名为 com/example/changelog.xml 的文件并找到它并将路径存储为 com/example/changelog.xml .
GenerateChangeLog 是“并不总是相对于类路径”的情况之一,因为它需要知道在哪里存储文件。如果您只是将输出 changeLogFile 指定为 changelog.xml它创建的只是相对于您的进程的工作目录创建该文件,这不是您需要/期望的。

关于postgresql - Liquibase 通过 Docker - 变更日志未写入磁盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67277878/

相关文章:

docker - 查看 Portainer 运行的命令

liquibase - 如何生成.sql格式的changlog文件?

Postgresql 四舍五入数值

postgresql - PostGIS 安装 "could not open extension control file"

Docker compose - 构建顺序,数据库在应用程序之前

找不到 Gradle Liquibase 更改日志文件

java - 液体碱 : Load data with dates depending on today (plus one day)

ruby-on-rails - 如何向生成的脚手架添加额外的 View 并向其添加操作

postgresql - Heroku 共享 PostgreSQL 和 pgcrypto

docker - 使用预先安装了需求的预构建docker容器镜像