Skip to content

Commit

Permalink
Changed store items price datatype to support fractional prices #168
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Clark committed Mar 23, 2017
1 parent bbb4739 commit 87d30ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/store_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
# **`price`** | `decimal(10, )` |
# **`price`** | `decimal(8, 2)` |
# **`quantity`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
#
Expand Down
2 changes: 1 addition & 1 deletion app/models/store_purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# **`charge_id`** | `integer` |
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
# **`price_at_purchase`** | `decimal(10, )` |
# **`price_at_purchase`** | `decimal(8, 2)` |
# **`quantity_purchased`** | `integer` |
# **`store_item_id`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20170323163001_change_store_item_price_datatype.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ChangeStoreItemPriceDatatype < ActiveRecord::Migration
def change
change_column :store_items, :price, :decimal, :precision => 8, :scale => 2
change_column :store_purchases, :price_at_purchase, :decimal, :precision => 8, :scale => 2
end
end
22 changes: 11 additions & 11 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,20 @@
add_index "shifts", ["organization_id"], name: "index_shifts_on_organization_id"

create_table "store_items", force: :cascade do |t|
t.string "name"
t.decimal "price"
t.integer "quantity"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", limit: 255
t.decimal "price", precision: 8, scale: 2
t.integer "quantity", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "store_purchases", force: :cascade do |t|
t.integer "charge_id"
t.integer "store_item_id"
t.decimal "price_at_purchase"
t.integer "quantity_purchased"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "charge_id", limit: 4
t.integer "store_item_id", limit: 4
t.decimal "price_at_purchase", precision: 8, scale: 2
t.integer "quantity_purchased", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "store_purchases", ["charge_id"], name: "index_store_purchases_on_charge_id"
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@
# Store -------------------------------------------------------------------------
puts 'Store'

StoreItem.create({ name: '9 Volt Battery', price: 1, quantity: 1000})
StoreItem.create({ name: '9 Volt Battery', price: 0.99, quantity: 1000})
StoreItem.create({ name: 'Drill Bit', price: 1, quantity: 1000})
StoreItem.create({ name: 'Drop Cloth', price: 2, quantity: 1000})
StoreItem.create({ name: 'Electrical Box - 1 Gang', price: 1, quantity: 1000})
Expand Down

0 comments on commit 87d30ea

Please sign in to comment.