From 617890c2097c554b69382ecfec5cc9a7f016fddd Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:34:06 +0200 Subject: badge migration now contains default badges and creation of badge table --- db/migrate/20170319193517_add_badge_id_to_users.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/db/migrate/20170319193517_add_badge_id_to_users.rb b/db/migrate/20170319193517_add_badge_id_to_users.rb index 08328cf..4e9d7ed 100644 --- a/db/migrate/20170319193517_add_badge_id_to_users.rb +++ b/db/migrate/20170319193517_add_badge_id_to_users.rb @@ -1,8 +1,16 @@ class AddBadgeIdToUsers < ActiveRecord::Migration def change - add_column :users, :badge_id, :integer + + create_table "badges", force: :cascade do |t| + t.string "name" + t.string "symbol" + t.string "color" + end + + dbadge = Badge.create!({name: "donor", symbol: "$", color: "#f60"}) + add_column :users, :badge_id, :integer, default: 0 - User.where(donor: true).update_all(badge_id: 1) + User.where(donor: true).update_all(badge_id: dbadge.id) remove_column :users, :donor end end -- cgit v1.2.3