fix: added desc field to styles

This commit is contained in:
Aaro Koivukangas
2023-11-30 00:20:49 +02:00
parent 365dc892f8
commit 766cf3eaa2
2 changed files with 6 additions and 5 deletions
+5 -5
View File
@@ -3,6 +3,7 @@ class CreateStyles < ActiveRecord::Migration[7.0]
create_table :styles do |t|
t.index :id
t.text :name
t.text :description
t.timestamps
end
@@ -33,20 +34,19 @@ class CreateStyles < ActiveRecord::Migration[7.0]
end
def self.down
add_column :beers, :style, :text
add_column :beers, :style_name, :text
Beer.all.each do |beer|
style = Style.find_by id: beer.style_id
if style.nil?
Beer.update beer.id, { :style => "IPA" }
Beer.update beer.id, { :style_name => "IPA" }
else
Beer.update beer.id, { :style => style.name }
Beer.update beer.id, { :style_name => style.name }
end
end
remove_column :beers, :style_id
remove_column :beers, :old_style
rename_column :beers, :style_name, :style
drop_table :styles
end
end
Generated
+1
View File
@@ -52,6 +52,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_20_133953) do
create_table "styles", force: :cascade do |t|
t.text "name"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["id"], name: "index_styles_on_id"