77 t2020_plus = Term . find_by! ( facet : facet , value : 'After 2020' )
88
99 # Items with nil date
10- insert_and_delete ( t_after_1999 . id , t2000_2009 . id , "i.date is null AND i.title in ('Loading a Cannon', 'Dense Populations')" )
10+ update_item_term ( t_after_1999 . id , t2000_2009 . id , "i.date is null AND i.title in ('Loading a Cannon', 'Dense Populations')" )
1111 # Items with date = '[2020]'
12- insert_and_delete ( t_after_1999 . id , t2020_plus . id , "date = '[2020]'" )
12+ update_item_term ( t_after_1999 . id , t2020_plus . id , "date = '[2020]'" )
1313 end
1414
1515 def down
@@ -19,18 +19,18 @@ def down
1919 t2020_plus = Term . find_by! ( facet : facet , value : 'After 2020' )
2020
2121 # revert items with nil date
22- insert_and_delete ( t2000_2009 . id , t_after_1999 . id , "i.date is null AND i.title in ('Loading a Cannon', 'Dense Populations')" )
22+ update_item_term ( t2000_2009 . id , t_after_1999 . id , "i.date is null AND i.title in ('Loading a Cannon', 'Dense Populations')" )
2323 # revert items with date = '[2020]'
24- insert_and_delete ( t2020_plus . id , t_after_1999 . id , "date = '[2020]'" )
24+ update_item_term ( t2020_plus . id , t_after_1999 . id , "date = '[2020]'" )
2525 end
2626
2727 private
2828
29- def insert_and_delete ( old_term_id , new_term_id , condition_sql )
29+ def update_item_term ( old_term_id , new_term_id , condition_sql )
3030
3131 execute <<~SQL . squish
3232 WITH target AS (
33- SELECT it.term_id, it.item_id, i.title
33+ SELECT it.term_id, it.item_id
3434 FROM items i
3535 JOIN items_terms it ON i.id = it.item_id
3636 JOIN terms t ON it.term_id = t.id
0 commit comments