diff options
Diffstat (limited to 'db/migrate/20171015171556_remove_boxes.pokeviewer.rb')
-rw-r--r-- | db/migrate/20171015171556_remove_boxes.pokeviewer.rb | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/db/migrate/20171015171556_remove_boxes.pokeviewer.rb b/db/migrate/20171015171556_remove_boxes.pokeviewer.rb new file mode 100644 index 0000000..c3cbbb1 --- /dev/null +++ b/db/migrate/20171015171556_remove_boxes.pokeviewer.rb | |||
@@ -0,0 +1,107 @@ | |||
1 | # This migration comes from pokeviewer (originally 20171003191205) | ||
2 | class RemoveBoxes < ActiveRecord::Migration[5.1] | ||
3 | def up | ||
4 | change_table :pokeviewer_trainers do |t| | ||
5 | t.string :box_1_name, null: false, default: "" | ||
6 | t.string :box_2_name, null: false, default: "" | ||
7 | t.string :box_3_name, null: false, default: "" | ||
8 | t.string :box_4_name, null: false, default: "" | ||
9 | t.string :box_5_name, null: false, default: "" | ||
10 | t.string :box_6_name, null: false, default: "" | ||
11 | t.string :box_7_name, null: false, default: "" | ||
12 | t.string :box_8_name, null: false, default: "" | ||
13 | t.string :box_9_name, null: false, default: "" | ||
14 | t.string :box_10_name, null: false, default: "" | ||
15 | t.string :box_11_name, null: false, default: "" | ||
16 | t.string :box_12_name, null: false, default: "" | ||
17 | t.string :box_13_name, null: false, default: "" | ||
18 | t.string :box_14_name, null: false, default: "" | ||
19 | end | ||
20 | |||
21 | change_column_default :pokeviewer_trainers, :box_1_name, nil | ||
22 | change_column_default :pokeviewer_trainers, :box_2_name, nil | ||
23 | change_column_default :pokeviewer_trainers, :box_3_name, nil | ||
24 | change_column_default :pokeviewer_trainers, :box_4_name, nil | ||
25 | change_column_default :pokeviewer_trainers, :box_5_name, nil | ||
26 | change_column_default :pokeviewer_trainers, :box_6_name, nil | ||
27 | change_column_default :pokeviewer_trainers, :box_7_name, nil | ||
28 | change_column_default :pokeviewer_trainers, :box_8_name, nil | ||
29 | change_column_default :pokeviewer_trainers, :box_9_name, nil | ||
30 | change_column_default :pokeviewer_trainers, :box_10_name, nil | ||
31 | change_column_default :pokeviewer_trainers, :box_11_name, nil | ||
32 | change_column_default :pokeviewer_trainers, :box_12_name, nil | ||
33 | change_column_default :pokeviewer_trainers, :box_13_name, nil | ||
34 | change_column_default :pokeviewer_trainers, :box_14_name, nil | ||
35 | |||
36 | Pokeviewer::Trainer.all.each do |t| | ||
37 | boxes = ActiveRecord::Base.connection.select_all( | ||
38 | "SELECT * FROM pokeviewer_boxes WHERE trainer_id = ? ORDER BY number ASC", | ||
39 | t.trainer_id).map { |b| b["name"] } | ||
40 | |||
41 | t.box_1_name = boxes.shift | ||
42 | t.box_2_name = boxes.shift | ||
43 | t.box_3_name = boxes.shift | ||
44 | t.box_4_name = boxes.shift | ||
45 | t.box_5_name = boxes.shift | ||
46 | t.box_6_name = boxes.shift | ||
47 | t.box_7_name = boxes.shift | ||
48 | t.box_8_name = boxes.shift | ||
49 | t.box_9_name = boxes.shift | ||
50 | t.box_10_name = boxes.shift | ||
51 | t.box_11_name = boxes.shift | ||
52 | t.box_12_name = boxes.shift | ||
53 | t.box_13_name = boxes.shift | ||
54 | t.box_14_name = boxes.shift | ||
55 | |||
56 | t.save | ||
57 | end | ||
58 | |||
59 | drop_table :pokeviewer_boxes | ||
60 | end | ||
61 | |||
62 | def down | ||
63 | create_table :pokeviewer_boxes do |t| | ||
64 | t.integer "trainer_id", null: false | ||
65 | t.integer "number", null: false | ||
66 | t.string "name", null: false | ||
67 | |||
68 | t.timestamps | ||
69 | end | ||
70 | |||
71 | add_index :pokeviewer_boxes, [:trainer_id, :number], unique: true | ||
72 | |||
73 | add_foreign_key :pokeviewer_boxes, :pokeviewer_trainers, column: :trainer_id | ||
74 | |||
75 | Pokeviewer::Trainer.all.each do |t| | ||
76 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 1, name: t.box_1_name) | ||
77 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 2, name: t.box_2_name) | ||
78 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 3, name: t.box_3_name) | ||
79 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 4, name: t.box_4_name) | ||
80 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 5, name: t.box_5_name) | ||
81 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 6, name: t.box_6_name) | ||
82 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 7, name: t.box_7_name) | ||
83 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 8, name: t.box_8_name) | ||
84 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 9, name: t.box_9_name) | ||
85 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 10, name: t.box_10_name) | ||
86 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 11, name: t.box_11_name) | ||
87 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 12, name: t.box_12_name) | ||
88 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 13, name: t.box_13_name) | ||
89 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 14, name: t.box_14_name) | ||
90 | end | ||
91 | |||
92 | remove_column :pokeviewer_trainers, :box_1_name | ||
93 | remove_column :pokeviewer_trainers, :box_2_name | ||
94 | remove_column :pokeviewer_trainers, :box_3_name | ||
95 | remove_column :pokeviewer_trainers, :box_4_name | ||
96 | remove_column :pokeviewer_trainers, :box_5_name | ||
97 | remove_column :pokeviewer_trainers, :box_6_name | ||
98 | remove_column :pokeviewer_trainers, :box_7_name | ||
99 | remove_column :pokeviewer_trainers, :box_8_name | ||
100 | remove_column :pokeviewer_trainers, :box_9_name | ||
101 | remove_column :pokeviewer_trainers, :box_10_name | ||
102 | remove_column :pokeviewer_trainers, :box_11_name | ||
103 | remove_column :pokeviewer_trainers, :box_12_name | ||
104 | remove_column :pokeviewer_trainers, :box_13_name | ||
105 | remove_column :pokeviewer_trainers, :box_14_name | ||
106 | end | ||
107 | end | ||