在Corda中,迁移到Enterprise时错误解析master.changelog.json

时间:2018-07-17 14:25:28

标签: corda

我正在从Corda开源迁移到Corda Enterprise,并创建了迁移脚本。但是,出现以下错误:

  

liquibase.exception.ChangeLogParseException:解析错误   master.changelog.json位于   liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:98)   〜[liquibase-core-3.5.3.jar :?]在   liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:229)   〜[liquibase-core-3.5.3.jar :?]在   liquibase.Liquibase.listUnrunChangeSets(Liquibase.java:1183)   〜[liquibase-core-3.5.3.jar :?]在   liquibase.Liquibase.listUnrunChangeSets(Liquibase.java:1176)   〜[liquibase-core-3.5.3.jar :?]在   net.corda.nodeapi.internal.persistence.SchemaMigration.doRunMigration(SchemaMigration.kt:133)   〜[corda-node-api-3.1.jar :?]在   net.corda.nodeapi.internal.persistence.SchemaMigration.doRunMigration $ default(SchemaMigration.kt:77)   〜[corda-node-api-3.1.jar :?]在   net.corda.nodeapi.internal.persistence.SchemaMigration.checkState(SchemaMigration.kt:66)   〜[corda-node-api-3.1.jar :?]在   net.corda.nodeapi.internal.persistence.SchemaMigration.nodeStartup(SchemaMigration.kt:49)   〜[corda-node-api-3.1.jar :?]在   net.corda.node.internal.AbstractNodeKt.configureDatabase(AbstractNode.kt:1140)   〜[corda-node-3.1.jar :?]在   net.corda.node.internal.AbstractNode.initialiseDatabasePersistence(AbstractNode.kt:852)   〜[corda-node-3.1.jar :?]在   net.corda.node.internal.Node.initialiseDatabasePersistence(Node.kt:373)   〜[corda-node-3.1.jar :?]在   net.corda.node.internal.AbstractNode.start(AbstractNode.kt:296)   〜[corda-node-3.1.jar :?]在   net.corda.node.internal.Node.start(Node.kt:387)   〜[corda-node-3.1.jar :?]在   net.corda.node.internal.EnterpriseNode.start(EnterpriseNode.kt:181)   〜[corda-node-3.1.jar :?]在   net.corda.node.internal.NodeStartup.startNode(NodeStartup.kt:270)   〜[corda-node-3.1.jar :?]在   net.corda.node.internal.NodeStartup.run(NodeStartup.kt:160)   位于net.corda.node.Corda.main的[corda-node-3.1.jar :?](Corda.kt:25)   [corda-node-3.1.jar :?]原因:liquibase.exception.SetupException:   错误解析第1行的第62列   migration / account-application.changelog-master.xml:cvc-elt.1:无法   找到元素“ changeSet”的声明。在   liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:322)   〜[liquibase-core-3.5.3.jar :?]在   liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:282)   〜[liquibase-core-3.5.3.jar :?]在   liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:91)   〜[liquibase-core-3.5.3.jar :?] ...还有16个

以下是account-application.changelog-master.xml文件的内容:

<changeSet author="R3.Corda" id="account_application_schema">
    <addColumn tableName="account_application_states">
        <column name="member_id" type="uuid"/>
    </addColumn>
    <addColumn tableName="account_application_states">
        <column name="fund_product_id" type="uuid"/>
    </addColumn>
    <addColumn tableName="account_application_states">
        <column name="type" type="varchar(255)"/>
    </addColumn>
    <addColumn tableName="account_application_states">
        <column name="fund_name" type="varchar(255)"/>
    </addColumn>
    <addColumn tableName="account_application_states">
        <column name="linear_id" type="uuid"/>
    </addColumn>
</changeSet> 

我尝试将内容包装在<databaseChangeLog>标记中,但是仍然遇到类似的错误。我是否需要在文件中添加任何额外的标题或内容?

2 个答案:

答案 0 :(得分:2)

为Corda Enterprise设置空数据库时,需要按照说明here设置角色和架构。之后,需要创建变更日志文件并将其添加到资源/迁移文件夹中。需要在变更日志中创建表并添加索引,例如下面的示例(account-application.changelog-master.xml)。请注意需要额外的(未在MappedSchema中定义的)output_index和transaction_id列,否则将抛出缺少列的错误。这些用于将自定义架构与Corda vault_schema结合在一起。

<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet author="R3.Corda" id="account_application_schema">
    <createTable tableName="account_application_states">
        <column name="member_id" type="uuid"/>
        <column name="type" type="varchar(255)"/>
        <column name="linear_id" type="uuid"/>
        <column name="output_index" type="int"/>
        <column name="transaction_id" type="varchar(255)"/>
    </createTable>
    <createIndex indexName="account_application_index_member_id" tableName="account_application_states" unique="false">
        <column name="member_id" type="uuid"/>
    </createIndex>
    <createIndex indexName="linear_id_account_application_index" tableName="account_application_states" unique="false">
        <column name="linear_id" type="uuid"/>
    </createIndex>
    <createIndex indexName="output_index_account_application_index" tableName="account_application_states" unique="false">
        <column name="output_index" type="int"/>
    </createIndex>
    <createIndex indexName="transaction_id_account_application_index" tableName="account_application_states" unique="false">
        <column name="transaction_id" type="varchar(255)"/>
    </createIndex>
</changeSet>

此变更日志随后需要由MappedSchema引用,例如下面的示例:

override val migrationResource = "account-application.changelog-master"

@Entity
@Table(name = "account_application_states",
        indexes = arrayOf(Index(name = "member_id_account_application_index", columnList = "member_id"), Index(name = "linear_id_account_application_index", columnList = "linear_id")))
class PersistentAccountApplication(
    @Column(name = "member_id")
    val memberId: UUID,

    @Column(name = "type")
    val type: String,

    @Column(name = "linear_id")
    val linearId: UUID
) : PersistentState() {
    // Default constructor required by hibernate.
    constructor(): this(UUID.randomUUID(), "", UUID.randomUUID())
}

设置完成后,将需要Corda数据库迁移工具来迁移表和列(外部数据库也需要在node.conf文件中进行配置,并且也说明了here)。 here说明了数据库迁移工具的用法。下面是用于迁移的命令示例:

java -jar corda-tools-database-manager-3.1.jar --base-directory /path/to/node --execute-migration

如果每个节点的过程均成功完成,则您应该能够启动该节点并正常运行所有内容。

答案 1 :(得分:1)

您的变更日志需要包含标准的XML模式定义:

<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
    http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

有关更多详细信息,请参见here