avniproject / JSSCP

0 stars 0 forks source link

[JSSCP][Support] remove ind from HH where HH address id different from individual address #234

Closed garimadosar5 closed 2 years ago

garimadosar5 commented 3 years ago

https://avni.freshdesk.com/a/tickets/1420

vindeolal commented 3 years ago

Fixed. Script used

with audits as (
    update group_subject set is_voided = true where id in (
        select distinct gs.id
        from group_subject gs
                 join group_role gr on gs.group_role_id = gr.id
                 join organisation o on o.id = gs.organisation_id
                 join individual g on gs.group_subject_id = g.id
                 join individual m on gs.member_subject_id = m.id
                 join address_level gal on g.address_id = gal.id
                 join address_level mal on m.address_id = mal.id
                 join virtual_catchment_address_mapping_table vc on vc.addresslevel_id = gal.id
                 join catchment c on c.id = vc.catchment_id
        where mal.id not in
              (select addresslevel_id from virtual_catchment_address_mapping_table v where v.catchment_id = c.id)
        and not gs.is_voided
    )
        returning audit_id
)
update audit
set last_modified_date_time=current_timestamp
where id in (
    select audit_id
    from audits
)