Skip to content

Instantly share code, notes, and snippets.

@zarazan
Created December 28, 2020 23:41
Show Gist options
  • Save zarazan/4cd8b9301d363b3d9ffe827ae4683f0b to your computer and use it in GitHub Desktop.
Save zarazan/4cd8b9301d363b3d9ffe827ae4683f0b to your computer and use it in GitHub Desktop.
-- Delete all unit facts in Kepler for store 400
with one_facility_dim as (
select facility_dim_id
from facility_dim
where facility_dim.store_number = '400'
),
kepler_units as (
select provider_id, unit_dim_id
from unit_dim
inner join unit_lookup_fact USING(unit_dim_id)
inner join one_facility_dim USING(facility_dim_id)
),
fms_units (provider_id) as (
VALUES ('uuid1'),('uuid2')
),
units_to_delete as (
select string_agg(unit_dim_id::text, ',') as unit_dim_id_csv
from kepler_units
left join fms_units on kepler_units.provider_id = fms_units.provider_id::uuid
where fms_units.provider_id is null
)
select * from delete_units_from_facts((select unit_dim_id_csv::text from units_to_delete), '400');
@zarazan
Copy link
Author

zarazan commented Dec 28, 2020

To get the output from FMS for the fms_units section:

Facility.find_by_store_number('400').units.each { |u| print "('#{u.uuid}')," };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment