Each time we upload smart contract, no matter what version string we specified, Thought Machine will generate an inner product version id. Every account will be bounded to this product version id.

Currently the deploy script will execute account migration automatically, but unfortunately, it’s not always success. This document will guide you to verify if migration executed successfully and migrate account manually using core api of TM, check the result and failure reason.

(blue star) Account migration while deployment

Current deployment implementation

In the scription file tm-contract/deploy/deploy.sh, after uploaded smart contract to TM by CLU, the last script is

python3 -m update_plans --action=update --prefix="${PRODUCT_PREFIX}"

This command will execute account migration automatically.

Verify account update status

Because of the account migration will not always be successful, we need to manually check the result. The best way is to query account list by older product version id, if we still have accounts using that version id, that means the account migration has been failed.

Query product version ids

We can simply query our product versions from thought machine. Visit https://ops.tm5.sandbox.safibank.online/products/product-management for tm5, choose the product and switch Product versions tab, all the uploaded versions will be list here.

Retrieve accounts by product version id

After we uploaded a new version of test_main_account_product, latest version id now is 246. We need to query accounts by product version id 246 to check if accounts has been updated successfully.

curl --location --request \
GET 'https://core-api.tm5.sandbox.safibank.online/v1/accounts?page_size=10&product_version_ids=246' \
--header 'X-Auth-Token: <AUTH-TOKEN>'

If the result of accounts is not an empty list, that means accounts with older version has been migrated to the latest version, otherwise we need to do some manual migration and check the failure reason.

(blue star) Manually execute account migration

execute account migration by core api

we need to find out the latest version id and older version id by last chapter of Query product version ids.

After we have collected those two ids, we can migrate accounts by invoking core api of TM.

curl --location --request POST 'https://core-api.tm5.sandbox.safibank.online/v1/account-migrations' \
--header 'X-Auth-Token: <AUTH-TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "request_id": "<any unique string Max length: 512 characters.>",
    "account_migration": {
        "id": "Mig-Test-3",
        "product_version_migration": {
            "from_product_version_ids": [
                "<older version id>"
            ],
            "to_product_version_id": "<the latest version id>",
            "schedule_migration_type": "SCHEDULE_MIGRATION_TYPE_RECREATE_ALL_SCHEDULES_AND_GROUPS"
        }
    }
}'

migration status check

As this migration is executed asynchronized, we need to wait until the progress completed. TM already have an api to query the status of this process using the account migration id which we provided last step.

curl --location --request GET 'https://core-api.tm5.sandbox.safibank.online/v1/account-migrations:batchGet?ids=Neil-Mig-Test-3' \
--header 'X-Auth-Token: <AUTH-TOKEN>'

The status should be ACCOUNT_MIGRATION_STATUS_PENDING_EXECUTION if the progress is in execution. Wait and check again till status changed to ACCOUNT_MIGRATION_STATUS_COMPLETED.

The status of ACCOUNT_MIGRATION_STATUS_COMPLETED does not means completed successfully, but only represents it’s execution has finished, we still need to retrieve the accounts if they have been migrated successfully.

Verify migration result

The same as previous chapter of Retrieve accounts by product version id, query accounts using older version id. If the accounts is not empty, that means migration processed failed.

Retrieve account update history and failure_reason

Each time after migration processed, TM will create an account update record. We can query this list to find out the reason caused migration failure.

Pick any account id returned last step from accounts list, invoke core api using that id.

curl --location --request GET 'https://core-api.tm5.sandbox.safibank.online/v1/account-updates?account_id=5fd7db31-6cfc-459d-bc22-f4ccbf92cca3&page_size=100&page_token=' \
--header 'X-Auth-Token: <AUTH-TOKEN>'

Find the record which create_timestamp is the timestamp you started account migration process. The account update history’s amount maybe more that the limitation of page_size defined by TM, we need to continue query using next_page_token.

Check the failure_reason, for this example it’s New smart contract version 246 not in supported versions of the associated plan: 10, 9 which means we need to migrate plan also, see https://docs.thoughtmachine.net/vault-core/4-5/EN/reference/plans/#plan_migrations-migrating_accounts_associated_with_plans.