diff --git a/app/resources/api/v1/planting_resource.rb b/app/resources/api/v1/planting_resource.rb index 030f57892..dce3aaf7d 100644 --- a/app/resources/api/v1/planting_resource.rb +++ b/app/resources/api/v1/planting_resource.rb @@ -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 diff --git a/db/migrate/20190317023129_finished_boolean.rb b/db/migrate/20190317023129_finished_boolean.rb new file mode 100644 index 000000000..5f8601fca --- /dev/null +++ b/db/migrate/20190317023129_finished_boolean.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index d2d475824..5c98e630d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"