在CashSchemaV1中添加了一个额外的列xyz。我可以使用H2 db启动节点,但是使用PostgreSQL时会出现以下错误:
[ERROR] 14:52:11+0530 [main] internal.NodeStartupLogging.invoke - Exception during node startup: Incompatible schema change detected. Please run the node with database.initialiseSchema=true. Reason: Schema-validation: missing column [xyz] in table [contract_cash_states]
关注https://docs.corda.r3.com/database-management.html#database-management-scripts
<column name="pennies" type="BIGINT"/>
<column name="xyz" type="NVARCHAR(130)"/>
然后将数据库迁移脚本追溯地添加到现有的CorDapp。 在此之后,尝试启动节点,但出现以下错误:
[ERROR] 14:52:11+0530 [main] internal.NodeStartupLogging.invoke - Exception during node startup: Incompatible schema change detected. Please run the node with database.initialiseSchema=true. Reason: Schema-validation: missing column [xyz] in table [contract_cash_states]
CashSchemaV1.kt https://github.com/corda/corda/blob/master/finance/contracts/src/main/kotlin/net/corda/finance/schemas/CashSchemaV1.kt
@Type(type = "corda-wrapper-binary")
var issuerRef: ByteArray,
@Column (name = "xyz")
var xyz: String
) : PersistentState()
}
迁移脚本生成cash-schema-v1.changelog-master.sql
--liquibase formatted sql
--changeset R3.Corda.Generated:initial_schema_for_CashSchemaV1
create table contract_cash_states (
output_index int4 not null,
transaction_id varchar(64) not null,
ccy_code varchar(3) not null,
issuer_key_hash varchar(130) not null,
issuer_ref bytea not null,
owner_name varchar(255),
pennies int8 not null,
xyz varchar(255),
primary key (output_index, transaction_id)
);
create index ccy_code_idx on contract_cash_states (ccy_code);
create index pennies_idx on contract_cash_states (pennies);
应使用CashSchemaV1中指定的所有列创建架构
答案 0 :(得分:0)
执行添加额外列的步骤:
1)在cash.changelog-init.xml中添加了<column name="xyz" type="NVARCHAR(130)"/>
2)在<addNotNullConstraint tableName="abc_states" columnName="xyz" columnDataType="NVARCHAR(130)"/>
中添加了cash.changelog-v1.xml
构建cordapp,然后使用this运行节点,节点成功启动。