我正在尝试设置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格式的主changelog,指向一个带有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这到底有没有可能?
发布于 2021-11-18 19:50:13
MySQL数据库中没有schema。但是,如果您打算将控制表放在不同的数据库中,那么您可以使用liquibase.liquibaseCatalogName: <db_name>来保存所有的控制表,使用liquibase.command.defaultCatalogName: <db_name>来保存所有其他的更改。
https://stackoverflow.com/questions/69919919
复制相似问题