From 485e4d3df8fe5595fd2c72c445a7fd9788aa4a81 Mon Sep 17 00:00:00 2001 From: Nana-EC Date: Thu, 10 Jun 2021 04:56:40 -0500 Subject: [PATCH] Add migration to v2 Signed-off-by: Nana-EC --- .../migration/v2/V2.0.0__time_scale_init.sql | 2 +- .../migration/v2/V2.0.5__upsert_support.sql | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 hedera-mirror-importer/src/main/resources/db/migration/v2/V2.0.5__upsert_support.sql diff --git a/hedera-mirror-importer/src/main/resources/db/migration/v2/V2.0.0__time_scale_init.sql b/hedera-mirror-importer/src/main/resources/db/migration/v2/V2.0.0__time_scale_init.sql index 9695082ffad..43af7f9f6f2 100644 --- a/hedera-mirror-importer/src/main/resources/db/migration/v2/V2.0.0__time_scale_init.sql +++ b/hedera-mirror-importer/src/main/resources/db/migration/v2/V2.0.0__time_scale_init.sql @@ -86,7 +86,7 @@ create table if not exists entity auto_renew_account_id bigint, auto_renew_period bigint, created_timestamp bigint, - deleted boolean default false not null, + deleted boolean, expiration_timestamp bigint, id bigint not null, key bytea, diff --git a/hedera-mirror-importer/src/main/resources/db/migration/v2/V2.0.5__upsert_support.sql b/hedera-mirror-importer/src/main/resources/db/migration/v2/V2.0.5__upsert_support.sql new file mode 100644 index 00000000000..06ab02fd547 --- /dev/null +++ b/hedera-mirror-importer/src/main/resources/db/migration/v2/V2.0.5__upsert_support.sql @@ -0,0 +1,47 @@ +------------------- +-- Support upsert (insert and update from temp table) capabilities for updatable domains +------------------- + +-- create getNewAccountFreezeStatus function +-- if no freeze_key return NOT_APPLICABLE (0), else return FROZEN (1) or UNFROZEN (2) based on if freeze_default is true +create or replace function getNewAccountFreezeStatus(tokenId bigint) returns smallint as +$$ +declare + key bytea; + freezeDefault boolean; + status smallint; +begin + select into freezeDefault, key freeze_default, freeze_key from token where token_id = tokenId; + if key is null then + status := 0; + else + if freezeDefault then + status := 1; + else + status := 2; + end if; + end if; + + return status; +end +$$ language plpgsql; + + +-- create getNewAccountKycStatus function - takes tokenId and gives KycStatus default +-- if no key_key return NOT_APPLICABLE (0), else return REVOKED (2) +create or replace function getNewAccountKycStatus(tokenId bigint) returns smallint as +$$ +declare + key bytea; + status smallint; +begin + select into key kyc_key from token where token_id = tokenId; + if key is null then + status := 0; + else + status := 2; + end if; + + return status; +end +$$ language plpgsql;