File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11class UpdateFixTermItemRelation < ActiveRecord ::Migration [ 7.0 ]
22 def up
33 after_1999_id = select_value ( "SELECT id FROM terms WHERE value = 'After 1999'" )
4- after_2000_id = select_value ( "SELECT id FROM terms WHERE value = 'After 2020'" )
5- return unless after_1999_id && after_2000_id
4+ after_2020_id = select_value ( "SELECT id FROM terms WHERE value = 'After 2020'" )
5+ return unless after_1999_id && after_2020_id
66
77 execute <<~SQL . squish
88 WITH target AS (
1414 AND i.date = '[2020]'
1515 )
1616 UPDATE items_terms it
17- SET term_id = #{ after_2000_id }
17+ SET term_id = #{ after_2020_id }
1818 FROM target
1919 WHERE it.item_id = target.item_id
2020 AND it.term_id = target.term_id;
@@ -23,16 +23,16 @@ def up
2323
2424 def down
2525 after_1999_id = select_value ( "SELECT id FROM terms WHERE value = 'After 1999'" )
26- after_2000_id = select_value ( "SELECT id FROM terms WHERE value = 'After 2020'" )
27- return unless after_1999_id && after_2000_id
26+ after_2020_id = select_value ( "SELECT id FROM terms WHERE value = 'After 2020'" )
27+ return unless after_1999_id && after_2020_id
2828
2929 execute <<~SQL . squish
3030 WITH target AS (
3131 SELECT it.term_id, it.item_id
3232 FROM items i
3333 JOIN items_terms it ON i.id = it.item_id
3434 JOIN terms t ON it.term_id = t.id
35- WHERE t.id = #{ after_2000_id }
35+ WHERE t.id = #{ after_2020_id }
3636 AND i.date = '[2020]'
3737 )
3838 UPDATE items_terms it
You can’t perform that action at this time.
0 commit comments