我可以跳过 Liquibase LoadUpdateData XML 标签中的主键子句吗
Can I skip primary key clause from Liquibase LoadUpdateData XML tag
我的Table结构如下
CREATE TABLE domain_stat (
domain_stat bpchar(2) NOT NULL,
des_domain_stat varchar(40) NULL,
cde_domain_stat_catg bpchar(1) NOT NULL,
date_crea timestamp NOT NULL,
id_crea_user bpchar(8) NOT NULL,
date_updt timestamp NOT NULL,
id_updt_user bpchar(8) NOT NULL
);
因此本例中不涉及主键,甚至我的实际数据也确实包含重复行。
问题是通过使用 liquibase 语法将数据加载到 table 我必须强制添加 primarykey
子句。
有什么办法可以跳过主键。或添加复合键的任何替代方法,以便可以将完整的行标识为唯一行。
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet author="liquibase-docs"
id="loadUpdateData-example" context="!prod">
<loadUpdateData encoding="UTF-8"
file="config/liquibase/data/domain_stat.csv" onlyUpdate="false" primaryKey="id"
quotchar="'" separator="," tableName="domain_stat">
</loadUpdateData>
</changeSet>
</databaseChangeLog>
我已找到解决此问题的方法。
因为我的 table 上没有主键。
我创建了一个 executable bat
文件,并在其中使用 Postgres \COPY
指令将 CSV 文件数据加载到相应的 table.
Bat 文件为
set PGPASSWORD=root
set DB_HOST_NAME="localhost"
set DB_PORT="5434"
set DB_USER="postgres"
set DB_NAME="db_dev"
echo "Importing accessory Data"
psql -h %DB_HOST_NAME% -p %DB_PORT% -U %DB_USER% -d %DB_NAME% -c "\COPY "dev".p_table FROM ../data/p_data.csv delimiter ',' csv HEADER NULL AS 'null';"
我的 liquibase XML 文件看起来像
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet author="liquibase-docs" context="!prod"
id="executeCommand-example">
<executeCommand executable="import-data.bat" />
</changeSet>
</databaseChangeLog>
然后将此文件导入主变更日志,这对我有用!!
我的Table结构如下
CREATE TABLE domain_stat (
domain_stat bpchar(2) NOT NULL,
des_domain_stat varchar(40) NULL,
cde_domain_stat_catg bpchar(1) NOT NULL,
date_crea timestamp NOT NULL,
id_crea_user bpchar(8) NOT NULL,
date_updt timestamp NOT NULL,
id_updt_user bpchar(8) NOT NULL
);
因此本例中不涉及主键,甚至我的实际数据也确实包含重复行。
问题是通过使用 liquibase 语法将数据加载到 table 我必须强制添加 primarykey
子句。
有什么办法可以跳过主键。或添加复合键的任何替代方法,以便可以将完整的行标识为唯一行。
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet author="liquibase-docs"
id="loadUpdateData-example" context="!prod">
<loadUpdateData encoding="UTF-8"
file="config/liquibase/data/domain_stat.csv" onlyUpdate="false" primaryKey="id"
quotchar="'" separator="," tableName="domain_stat">
</loadUpdateData>
</changeSet>
</databaseChangeLog>
我已找到解决此问题的方法。
因为我的 table 上没有主键。
我创建了一个 executable bat
文件,并在其中使用 Postgres \COPY
指令将 CSV 文件数据加载到相应的 table.
Bat 文件为
set PGPASSWORD=root
set DB_HOST_NAME="localhost"
set DB_PORT="5434"
set DB_USER="postgres"
set DB_NAME="db_dev"
echo "Importing accessory Data"
psql -h %DB_HOST_NAME% -p %DB_PORT% -U %DB_USER% -d %DB_NAME% -c "\COPY "dev".p_table FROM ../data/p_data.csv delimiter ',' csv HEADER NULL AS 'null';"
我的 liquibase XML 文件看起来像
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet author="liquibase-docs" context="!prod"
id="executeCommand-example">
<executeCommand executable="import-data.bat" />
</changeSet>
</databaseChangeLog>
然后将此文件导入主变更日志,这对我有用!!