<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

    <!--this is needed because pre-v3 states are no longer supported-->
    <changeSet author="R3.Corda" id="nullability">
        <addNotNullConstraint tableName="vault_fungible_states" columnName="quantity" columnDataType="BIGINT"/>

        <addNotNullConstraint tableName="vault_states" columnName="contract_state_class_name" columnDataType="NVARCHAR(255)"/>
        <addNotNullConstraint tableName="vault_states" columnName="notary_name" columnDataType="NVARCHAR(255)"/>
        <addNotNullConstraint tableName="vault_states" columnName="recorded_timestamp" columnDataType="timestamp"/>
        <!-- drop indexes before adding not null constraints to the underlying table, recreating index immediately after -->
        <dropIndex indexName="state_status_idx" tableName="vault_states"/>
        <dropIndex indexName="lock_id_idx" tableName="vault_states"/>
        <addNotNullConstraint tableName="vault_states" columnName="state_status" columnDataType="INT"/>
        <createIndex indexName="state_status_idx" tableName="vault_states">
            <column name="state_status"/>
        </createIndex>
        <createIndex indexName="lock_id_idx" tableName="vault_states">
            <column name="lock_id"/>
            <column name="state_status"/>
        </createIndex>

        <dropIndex indexName="transaction_id_index" tableName="vault_transaction_notes"/>
        <addNotNullConstraint tableName="vault_transaction_notes" columnName="note" columnDataType="NVARCHAR(255)"/>
        <addNotNullConstraint tableName="vault_transaction_notes" columnName="transaction_id" columnDataType="NVARCHAR(64)"/>
        <createIndex indexName="transaction_id_index" tableName="vault_transaction_notes">
            <column name="transaction_id"/>
        </createIndex>
    </changeSet>
</databaseChangeLog>