diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-07 11:49:49 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-07 11:49:49 -0500 |
commit | 56f5841d4b9c12296cdfcaeff174b2627d59afc8 (patch) | |
tree | 4f7da4ebbe5ee15a1594b26466ed78e2cf10de35 /db/migrate/20171003191205_remove_boxes.rb | |
parent | c1b0443ba2aebdbd39291ddab0c189f3f4831320 (diff) | |
download | pokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.tar.gz pokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.tar.bz2 pokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.zip |
Migrate to full rails app
Diffstat (limited to 'db/migrate/20171003191205_remove_boxes.rb')
-rw-r--r-- | db/migrate/20171003191205_remove_boxes.rb | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/db/migrate/20171003191205_remove_boxes.rb b/db/migrate/20171003191205_remove_boxes.rb index 476b98a..f7258fd 100644 --- a/db/migrate/20171003191205_remove_boxes.rb +++ b/db/migrate/20171003191205_remove_boxes.rb | |||
@@ -1,6 +1,6 @@ | |||
1 | class RemoveBoxes < ActiveRecord::Migration[5.1] | 1 | class RemoveBoxes < ActiveRecord::Migration[5.1] |
2 | def up | 2 | def up |
3 | change_table :pokeviewer_trainers do |t| | 3 | change_table :trainers do |t| |
4 | t.string :box_1_name, null: false, default: "" | 4 | t.string :box_1_name, null: false, default: "" |
5 | t.string :box_2_name, null: false, default: "" | 5 | t.string :box_2_name, null: false, default: "" |
6 | t.string :box_3_name, null: false, default: "" | 6 | t.string :box_3_name, null: false, default: "" |
@@ -17,24 +17,24 @@ class RemoveBoxes < ActiveRecord::Migration[5.1] | |||
17 | t.string :box_14_name, null: false, default: "" | 17 | t.string :box_14_name, null: false, default: "" |
18 | end | 18 | end |
19 | 19 | ||
20 | change_column_default :pokeviewer_trainers, :box_1_name, nil | 20 | change_column_default :trainers, :box_1_name, nil |
21 | change_column_default :pokeviewer_trainers, :box_2_name, nil | 21 | change_column_default :trainers, :box_2_name, nil |
22 | change_column_default :pokeviewer_trainers, :box_3_name, nil | 22 | change_column_default :trainers, :box_3_name, nil |
23 | change_column_default :pokeviewer_trainers, :box_4_name, nil | 23 | change_column_default :trainers, :box_4_name, nil |
24 | change_column_default :pokeviewer_trainers, :box_5_name, nil | 24 | change_column_default :trainers, :box_5_name, nil |
25 | change_column_default :pokeviewer_trainers, :box_6_name, nil | 25 | change_column_default :trainers, :box_6_name, nil |
26 | change_column_default :pokeviewer_trainers, :box_7_name, nil | 26 | change_column_default :trainers, :box_7_name, nil |
27 | change_column_default :pokeviewer_trainers, :box_8_name, nil | 27 | change_column_default :trainers, :box_8_name, nil |
28 | change_column_default :pokeviewer_trainers, :box_9_name, nil | 28 | change_column_default :trainers, :box_9_name, nil |
29 | change_column_default :pokeviewer_trainers, :box_10_name, nil | 29 | change_column_default :trainers, :box_10_name, nil |
30 | change_column_default :pokeviewer_trainers, :box_11_name, nil | 30 | change_column_default :trainers, :box_11_name, nil |
31 | change_column_default :pokeviewer_trainers, :box_12_name, nil | 31 | change_column_default :trainers, :box_12_name, nil |
32 | change_column_default :pokeviewer_trainers, :box_13_name, nil | 32 | change_column_default :trainers, :box_13_name, nil |
33 | change_column_default :pokeviewer_trainers, :box_14_name, nil | 33 | change_column_default :trainers, :box_14_name, nil |
34 | 34 | ||
35 | Pokeviewer::Trainer.all.each do |t| | 35 | Pokeviewer::Trainer.all.each do |t| |
36 | boxes = ActiveRecord::Base.connection.select_all( | 36 | boxes = ActiveRecord::Base.connection.select_all( |
37 | "SELECT * FROM pokeviewer_boxes WHERE trainer_id = ? ORDER BY number ASC", | 37 | "SELECT * FROM boxes WHERE trainer_id = ? ORDER BY number ASC", |
38 | t.trainer_id).map { |b| b["name"] } | 38 | t.trainer_id).map { |b| b["name"] } |
39 | 39 | ||
40 | t.box_1_name = boxes.shift | 40 | t.box_1_name = boxes.shift |
@@ -55,11 +55,11 @@ class RemoveBoxes < ActiveRecord::Migration[5.1] | |||
55 | t.save | 55 | t.save |
56 | end | 56 | end |
57 | 57 | ||
58 | drop_table :pokeviewer_boxes | 58 | drop_table :boxes |
59 | end | 59 | end |
60 | 60 | ||
61 | def down | 61 | def down |
62 | create_table :pokeviewer_boxes do |t| | 62 | create_table :boxes do |t| |
63 | t.integer "trainer_id", null: false | 63 | t.integer "trainer_id", null: false |
64 | t.integer "number", null: false | 64 | t.integer "number", null: false |
65 | t.string "name", null: false | 65 | t.string "name", null: false |
@@ -67,9 +67,9 @@ class RemoveBoxes < ActiveRecord::Migration[5.1] | |||
67 | t.timestamps | 67 | t.timestamps |
68 | end | 68 | end |
69 | 69 | ||
70 | add_index :pokeviewer_boxes, [:trainer_id, :number], unique: true | 70 | add_index :boxes, [:trainer_id, :number], unique: true |
71 | 71 | ||
72 | add_foreign_key :pokeviewer_boxes, :pokeviewer_trainers, column: :trainer_id | 72 | add_foreign_key :boxes, :trainers, column: :trainer_id |
73 | 73 | ||
74 | Pokeviewer::Trainer.all.each do |t| | 74 | Pokeviewer::Trainer.all.each do |t| |
75 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 1, name: t.box_1_name) | 75 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 1, name: t.box_1_name) |
@@ -88,19 +88,19 @@ class RemoveBoxes < ActiveRecord::Migration[5.1] | |||
88 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 14, name: t.box_14_name) | 88 | Pokeviewer::Box.create(trainer_id: t.trainer_id, number: 14, name: t.box_14_name) |
89 | end | 89 | end |
90 | 90 | ||
91 | remove_column :pokeviewer_trainers, :box_1_name | 91 | remove_column :trainers, :box_1_name |
92 | remove_column :pokeviewer_trainers, :box_2_name | 92 | remove_column :trainers, :box_2_name |
93 | remove_column :pokeviewer_trainers, :box_3_name | 93 | remove_column :trainers, :box_3_name |
94 | remove_column :pokeviewer_trainers, :box_4_name | 94 | remove_column :trainers, :box_4_name |
95 | remove_column :pokeviewer_trainers, :box_5_name | 95 | remove_column :trainers, :box_5_name |
96 | remove_column :pokeviewer_trainers, :box_6_name | 96 | remove_column :trainers, :box_6_name |
97 | remove_column :pokeviewer_trainers, :box_7_name | 97 | remove_column :trainers, :box_7_name |
98 | remove_column :pokeviewer_trainers, :box_8_name | 98 | remove_column :trainers, :box_8_name |
99 | remove_column :pokeviewer_trainers, :box_9_name | 99 | remove_column :trainers, :box_9_name |
100 | remove_column :pokeviewer_trainers, :box_10_name | 100 | remove_column :trainers, :box_10_name |
101 | remove_column :pokeviewer_trainers, :box_11_name | 101 | remove_column :trainers, :box_11_name |
102 | remove_column :pokeviewer_trainers, :box_12_name | 102 | remove_column :trainers, :box_12_name |
103 | remove_column :pokeviewer_trainers, :box_13_name | 103 | remove_column :trainers, :box_13_name |
104 | remove_column :pokeviewer_trainers, :box_14_name | 104 | remove_column :trainers, :box_14_name |
105 | end | 105 | end |
106 | end | 106 | end |