【发布时间】:2021-12-23 10:39:55
【问题描述】:
我正在尝试设置 liquibase 来管理现有的 mysql 数据库。
理想情况下,我想在控制架构中创建控制表并将迁移应用到默认架构。
liquibase 的配置如下:
liquibase.classpath:/liquibase/changelog
liquibase.command.changelogFile: master.xml
liquibase.command.url: jdbc:mysql://host.docker.internal:3306/<default_schema>
liquibase.command.username: <root_user>
liquibase.command.password: <super_safe_password>
我在 xml 中也有一个主更改日志,指向一个带有 sql 迁移的子目录:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
<includeAll path="migrations/" relativeToChangelogFile="true"/>
</databaseChangeLog>
最后我使用 liquibase 的 docker 容器来避免在多台机器上安装它的命令行工具,因为我想在 CI/CD 管道上运行命令。
我有一个脚本来编排这一切:
#!/bin/bash
set -e
if [ "$#" -lt 3 ]; then
echo "usage: liquibase <schema> <zone> <command>"
echo "available zones: local"
echo "available schemas: ..."
exit 1
fi
SCHEMA=$1
ZONE=$2
COMMANDS=${@:3}
if [ ! -d "$PWD/schemas/$SCHEMA" ]; then
echo "Schema not supported: $SCHEMA"
exit 0
fi
CONF_DIR="$PWD/schemas/$SCHEMA/conf"
if [ ! -f "$CONF_DIR/liquibase.$ZONE.properties" ]; then
echo "Zone not supported: $ZONE"
exit 0
fi
MIGRATIONS_DIR="$PWD/schemas/$SCHEMA/changelog/migrations"
MASTER_CHANGELOG_DIR="$PWD/schemas/$SCHEMA/changelog"
docker run --rm \
-e INSTALL_MYSQL=true \
-v "$MASTER_CHANGELOG_DIR":/liquibase/changelog \
-v "$CONF_DIR":/conf \
-v "$MIGRATIONS_DIR":/liquibase/changelog/migrations \
liquibase/liquibase \
--defaultsFile=/conf/liquibase."$ZONE".properties \
"$COMMANDS"
我尝试过使用两种 liquibase 配置,有人认为它们可以解决问题,但没有运气:
liquibase.liquibaseSchemaName:<control_schema>
liquibase.command.defaultSchemaName:<default_schema>
似乎 defaultSchemaName 中定义的架构覆盖了以前的配置,强制将所有内容保持在同一架构中。
我当时使用的是最新的 liquibase 版本:
Liquibase Version: 4.5.0
Liquibase Community 4.5.0 by Datical
这可能吗?
【问题讨论】: