在 Corda 中,我们为可查询状态创建状态模式;例如:
值得注意的是,
liquibase能否自动生成这些脚本呢?
object MyStateSchema {
object MyStateSchemaV1 : MappedSchema(
schemaFamily = MyStateSchema.javaClass,
version = 1,
mappedTypes = listOf(MyStateEntity::class.java)
)
@Entity
@Table(name = "my_states")
class MyStateEntity(
@Column(name = "linear_id", nullable = false)
val linearId: UUID = UUID.randomUUID(),
@Column(name = "external_id", nullable = true)
val externalId: String? = null,
@Column(name = "identity", nullable = false)
val identity: AbstractParty = NULL_PARTY,
@Column(name = "value", nullable = false)
val value: String = ""
) : PersistentState()
}
值得注意的是,
MyStateEntity
被注解为JPA注解。因此我们需要生成与数据库无关的脚本来创建和更新数据库模式,例如:<?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.5.xsd">
<changeSet author="Me" id="create-my_states">
<createTable tableName="my_states">
<column name="output_index" type="INT">
<constraints nullable="false"/>
</column>
<column name="transaction_id" type="NVARCHAR(64)">
<constraints nullable="false"/>
</column>
<column name="linear_id" type="uuid">
<constraints nullable="false"/>
</column>
<column name="external_id" type="NVARCHAR(255)" />
<column name="identity" type="NVARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="value" type="NVARCHAR(255)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey columnNames="output_index, transaction_id"
constraintName="PK_my_states"
tableName="my_states"/>
</changeSet>
</databaseChangeLog>
目前我正在手动编写更改日志,这非常繁琐。我相信一定有更好的方法。我尝试向gradle添加了一些依赖项,以便运行以下命令(可惜没有成功):
./gradlew generateChangeLog