Skip to content

Commit

Permalink
Change refill column type (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr1d99 authored Nov 21, 2018
1 parent 63693e5 commit dd0d42b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/helpers/medications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def medication_refill
{
type: 'date',
label: t('medications.form.refill'),
value: @medication.refill || nil,
value: @medication.refill&.to_date || nil,
info: t('medications.form.refill_hint'),
required: true
}.merge(medication_basic_props('refill'))
Expand Down
3 changes: 0 additions & 3 deletions app/services/medication_reminders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def ready_for_refill
.where('medications.refill': one_week_from_now_as_string)
end

# TODO: Medication Refill dates are currently stored as strings in the
# database instead of timestamps. If we want to do more complicated reminders,
# we should migrate the data to timestamps.
def one_week_from_now_as_string
(Time.current + 1.week).strftime('%m/%d/%Y')
end
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20181119152925_change_refill_column_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ChangeRefillColumnType < ActiveRecord::Migration[5.2]
def up
change_column(:medications, :refill, 'timestamptz USING CAST(refill AS timestamptz)')
end

def down
change_column(:medications, :refill, :string)
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_11_03_000904) do
ActiveRecord::Schema.define(version: 2018_11_19_152925) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -91,7 +91,6 @@
create_table "medications", force: :cascade do |t|
t.string "name"
t.integer "dosage"
t.string "refill"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
Expand All @@ -104,6 +103,7 @@
t.string "slug"
t.boolean "add_to_google_cal", default: false
t.integer "weekly_dosage", default: [0, 1, 2, 3, 4, 5, 6], array: true
t.datetime "refill"
t.index ["slug"], name: "index_medications_on_slug", unique: true
end

Expand Down

0 comments on commit dd0d42b

Please sign in to comment.