In Corda we create state schemas for queryable states; for example:
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()
}
Notably, MyStateEntity
is annotated with JPA annotations. From this we need to generate database agnostic scripts to create and update the database schema; for example:
<?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>
Currently I'm writing the change logs by hand, and it's rather tiresome. I'm sure there must be a better way. I tried adding some dependencies to gradle so that I could run the following command (sadly it didn't work):
./gradlew generateChangeLog
Can liquibase generate these scripts automatically?