Skip to content

Commit b55dd71

Browse files
committed
Set comment's author and text as not null and defaults as empty string
The last parameter of change_column_null only affects existing records, thus the default still needs to be set in another migration.
1 parent 192c64e commit b55dd71

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class SetDefaultForAuthorAndText < ActiveRecord::Migration
2+
def up
3+
change_column_default(:comments, :author, "")
4+
change_column_default(:comments, :text, "")
5+
end
6+
7+
def down
8+
change_column_default(:comments, :author, nil)
9+
change_column_default(:comments, :text, nil)
10+
end
11+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class ChangeAuthorAndTextToNotNull < ActiveRecord::Migration
2+
def change
3+
change_column_null(:comments, :author, false, "")
4+
change_column_null(:comments, :text, false, "")
5+
end
6+
end

db/schema.rb

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

14-
ActiveRecord::Schema.define(version: 20140823052830) do
14+
ActiveRecord::Schema.define(version: 20151015160334) do
1515

1616
create_table "comments", force: :cascade do |t|
17-
t.string "author"
18-
t.text "text"
19-
t.datetime "created_at", null: false
20-
t.datetime "updated_at", null: false
17+
t.string "author", default: "", null: false
18+
t.text "text", default: "", null: false
19+
t.datetime "created_at", null: false
20+
t.datetime "updated_at", null: false
2121
end
2222

2323
end

0 commit comments

Comments
 (0)