Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Chapter 11 null value in boolean column #58

Open
JunichiIto opened this issue Feb 11, 2018 · 0 comments
Open

Chapter 11 null value in boolean column #58

JunichiIto opened this issue Feb 11, 2018 · 0 comments

Comments

@JunichiIto
Copy link
Contributor

Chapter 11, page 192,

NOTE: This is a problem related to RDBMS.

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants