Database 我可以从Liquibase LoadUpdateData XML标记中跳过主键子句吗
我的表格结构如下Database 我可以从Liquibase LoadUpdateData XML标记中跳过主键子句吗,database,primary-key,liquibase,Database,Primary Key,Liquibase,我的表格结构如下 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
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语法将数据加载到表中,我必须强制添加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>
我找到了解决此问题的方法。 因为我的桌子上没有主键。 我创建了一个可执行的
bat
文件,并使用Postgres\COPY
指令将CSV文件数据加载到相应的表中
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>
然后将这个文件导入到主变更日志中,这对我有用