bin/rails g migration add_completed_to_projects completed:boolean
bin/rails db:migrate
This migration fills null value in existing projects. And developers have to distinguish null or false, like this:
# If there are ten projects before running the migration
Project.where(completed: false).count #=> 0
Project.where(completed: null).count #=> 10
This issue could lead to a bug because developers tend to believe that completed column has true or false only. So I think it is better to edit the migration file like this:
class AddCompletedToProjects < ActiveRecord::Migration[5.1]
def change
add_column :projects, :completed, :boolean, default: false, null: false
end
end
Chapter 11, page 192,
NOTE: This is a problem related to RDBMS.
This migration fills null value in existing projects. And developers have to distinguish null or false, like this:
This issue could lead to a bug because developers tend to believe that completed column has true or false only. So I think it is better to edit the migration file like this: