Set planting.finished as a boolean

This commit is contained in:
Brenda Wallace
2019-03-18 13:25:11 +13:00
parent 6559645265
commit 62f2fa134d
3 changed files with 11 additions and 3 deletions

View File

@@ -30,7 +30,7 @@ module Api
filter :planted_from
filter :garden
filter :owner
filter :finished, default: nil
filter :finished
attribute :percentage_grown
def percentage_grown

View File

@@ -0,0 +1,8 @@
class FinishedBoolean < ActiveRecord::Migration[5.2]
def change
Planting.where('finished_at < now()').update_all(finished: true)
Planting.where(finished: nil).update_all(finished: false)
change_column_null :plantings, :finished, false
change_column_default :plantings, :finished, from: nil, to: false
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_01_30_090437) do
ActiveRecord::Schema.define(version: 2019_03_17_023129) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -385,7 +385,7 @@ ActiveRecord::Schema.define(version: 2019_01_30_090437) do
t.string "sunniness"
t.string "planted_from"
t.integer "owner_id"
t.boolean "finished", default: false
t.boolean "finished", default: false, null: false
t.date "finished_at"
t.integer "lifespan"
t.integer "days_to_first_harvest"