datamade / chi-councilmatic

:eyes: keep tabs on Chicago city council
https://chicago.councilmatic.org/
MIT License
21 stars 16 forks source link

use alternate identifiers to redirect to canonical bill slug #353

Closed fgregg closed 1 year ago

fgregg commented 1 year ago

with the new LIS the identifier of many bills has been renamed. we should use the alternate identifier attribute to set up redirects

derekeder commented 1 year ago

We updated the database to change the slug to use the new system's identifiers on 622 bills. Here's the SQL commands for posterity:

find the bills that were using the old identifiers but had new ones:

select slug, opencivicdata_bill.identifier as name_identifier, opencivicdata_billidentifier.identifier as alternate_identifier 
from councilmatic_core_bill 
inner join opencivicdata_bill on opencivicdata_bill.id= councilmatic_core_bill.bill_id 
inner join opencivicdata_billidentifier using (bill_id) 
where opencivicdata_bill.identifier != substr(opencivicdata_billidentifier.identifier, 2, length(opencivicdata_billidentifier.identifier)) 
and opencivicdata_billidentifier.identifier != substr(opencivicdata_bill.identifier, 2, length(opencivicdata_bill.identifier)) 
limit 100;

update those bills to use the new identifiers in their slugs:

update councilmatic_core_bill set slug=lower(opencivicdata_bill.identifier)
 from opencivicdata_bill
inner join opencivicdata_billidentifier on opencivicdata_bill.id=opencivicdata_billidentifier.bill_id
where councilmatic_core_bill.bill_id = opencivicdata_bill.id and
opencivicdata_bill.identifier != substr(opencivicdata_billidentifier.identifier, 2, length(opencivicdata_billidentifier.identifier))
and opencivicdata_billidentifier.identifier != substr(opencivicdata_bill.identifier, 2, length(opencivicdata_bill.identifier));
fgregg commented 1 year ago

done