Skip to content

Commit e078bdd

Browse files
author
Lewis Youl
committed
feat: add migration to change user bio default
1 parent c44896a commit e078bdd

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

app/models/user.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class User < ApplicationRecord
55
include Rails.application.routes.url_helpers
66

77
DEFAULT_FOLDER_NAME = 'My First Folder'.freeze
8-
BIO_MISSING_TEXT = "This user hasn't updated their bio yet."
98
ALPHANUMERIC = /\A[a-zA-Z0-9]*\z/.freeze
109

1110
friendly_id :name, use: :slugged
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class UpdateBioTextForUsers < ActiveRecord::Migration[6.0]
2+
OLD_DEFAULT = "This user hasn't updated their bio yet.".freeze
3+
NEW_DEFAULT = "404 - bio not found".freeze
4+
5+
def change
6+
change_column_default(:users, :bio, from: OLD_DEFAULT, to: NEW_DEFAULT)
7+
8+
User.where(bio: OLD_DEFAULT).each { |u| u.update!(bio: NEW_DEFAULT) }
9+
end
10+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2021_03_15_202025) do
13+
ActiveRecord::Schema.define(version: 2021_03_15_204751) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -133,7 +133,7 @@
133133
t.datetime "remember_created_at"
134134
t.datetime "created_at", precision: 6, null: false
135135
t.datetime "updated_at", precision: 6, null: false
136-
t.string "bio", default: "This user hasn't updated their bio yet."
136+
t.string "bio", default: "404 - bio not found"
137137
t.string "location", default: ""
138138
t.string "confirmation_token"
139139
t.datetime "confirmed_at"

0 commit comments

Comments
 (0)