diff --git a/ppr-api/src/database/patch/21975-ppr-drafts-used.sql b/ppr-api/src/database/patch/21975-ppr-drafts-used.sql new file mode 100644 index 000000000..6be83d969 --- /dev/null +++ b/ppr-api/src/database/patch/21975-ppr-drafts-used.sql @@ -0,0 +1,63 @@ +-- 21975 begin PPR API build 1.2.5 + +-- 3635874 PROD 2024-06-24 +select max(id) + from drafts +; + +-- 1886177 +select max(id) + from drafts + where account_id = '0' +; + +-- 1746001 +select count(d.id) + from drafts d, registrations r + where d.account_id != '0' + and d.account_id not like '%_USED' + and d.id = r.draft_id + and d.id between 1886177 and 2300000 -- 412787 +-- and d.id between 2300001 and 2800000 -- 498879 +-- and d.id between 2800001 and 3300000 -- 499138 +-- and d.id > 3300000 -- 335219 +; +update drafts + set account_id = account_id || '_USED' + where id in (select d.id + from drafts d, registrations r + where d.account_id != '0' + and d.account_id not like '%_USED' + and d.id = r.draft_id + and d.id between 1886177 and 2300000) +; + +update drafts + set account_id = account_id || '_USED' + where id in (select d.id + from drafts d, registrations r + where d.account_id != '0' + and d.account_id not like '%_USED' + and d.id = r.draft_id + and d.id between 2300001 and 2800000) +; +update drafts + set account_id = account_id || '_USED' + where id in (select d.id + from drafts d, registrations r + where d.account_id != '0' + and d.account_id not like '%_USED' + and d.id = r.draft_id + and d.id between 2800001 and 3300000) +; +update drafts + set account_id = account_id || '_USED' + where id in (select d.id + from drafts d, registrations r + where d.account_id != '0' + and d.account_id not like '%_USED' + and d.id = r.draft_id + and d.id > 3300000) +; + +-- 21975 end PPR API build 1.2.5 diff --git a/ppr-api/src/ppr_api/models/registration.py b/ppr-api/src/ppr_api/models/registration.py index e820d9f40..940e8ce6e 100644 --- a/ppr-api/src/ppr_api/models/registration.py +++ b/ppr-api/src/ppr_api/models/registration.py @@ -41,6 +41,7 @@ FINANCING_PATH = '/ppr/api/v1/financing-statements/' +ACCOUNT_DRAFT_USED_SUFFIX = '_USED' class CrownChargeTypes(BaseEnum): @@ -597,6 +598,7 @@ def create_from_json(json_data, draft = Draft.create_from_registration(registration, json_data) else: draft.draft = json_data + draft.account_id = draft.account_id + ACCOUNT_DRAFT_USED_SUFFIX registration.draft = draft registration.registration_type_cl = registration_type_cl if registration_type_cl in (model_utils.REG_CLASS_AMEND, @@ -734,6 +736,7 @@ def create_financing_from_json(json_data, account_id: str = None, user_id: str = draft = Draft.create_from_registration(registration, json_data, user_id) else: draft.draft = json_data + draft.account_id = draft.account_id + ACCOUNT_DRAFT_USED_SUFFIX registration.draft = draft if reg_type == MiscellaneousTypes.SECURITIES_NOTICE and json_data.get('securitiesActNotices'): registration = registration_utils.create_securities_act_notices(registration, json_data)