Skip to content

Commit a0ca4ac

Browse files
committed
Change variable names
1 parent 3179f28 commit a0ca4ac

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

db/migrate/20250930230620_update_fix_term_item_relation.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
class UpdateFixTermItemRelation < ActiveRecord::Migration[7.0]
22
def up
3+
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
6+
37
execute <<~SQL.squish
4-
old_id = select_value("SELECT id FROM terms WHERE value = 'After 1999'")
5-
new_id = select_value("SELECT id FROM terms WHERE value = 'After 2020'")
6-
return unless old_id && new_id
7-
88
WITH target AS (
99
SELECT it.term_id, it.item_id
1010
FROM items i
1111
JOIN items_terms it ON i.id = it.item_id
1212
JOIN terms t ON it.term_id = t.id
13-
WHERE t.id = #{old_id}
13+
WHERE t.id = #{after_1999_id}
1414
AND i.date = '[2020]'
1515
)
1616
UPDATE items_terms it
17-
SET term_id = #{new_id}
17+
SET term_id = #{after_2000_id}
1818
FROM target
1919
WHERE it.item_id = target.item_id
2020
AND it.term_id = target.term_id;
2121
SQL
2222
end
2323

24-
def up
25-
new_id = select_value("SELECT id FROM terms WHERE value = 'After 1999'")
26-
old_id = select_value("SELECT id FROM terms WHERE value = 'After 2020'")
27-
return unless old_id && new_id
24+
def down
25+
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
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 = #{old_id}
35+
WHERE t.id = #{after_2000_id}
3636
AND i.date = '[2020]'
3737
)
3838
UPDATE items_terms it
39-
SET term_id = #{new_id}
39+
SET term_id = #{after_1999_id}
4040
FROM target
4141
WHERE it.item_id = target.item_id
4242
AND it.term_id = target.term_id;

0 commit comments

Comments
 (0)