From 87d30ea91570f72c8252026916016e337e67884f Mon Sep 17 00:00:00 2001 From: Stephen Clark Date: Thu, 23 Mar 2017 12:43:28 -0400 Subject: [PATCH 1/4] Changed store items price datatype to support fractional prices #168 --- app/models/store_item.rb | 2 +- app/models/store_purchase.rb | 2 +- ...163001_change_store_item_price_datatype.rb | 6 +++++ db/schema.rb | 22 +++++++++---------- db/seeds.rb | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20170323163001_change_store_item_price_datatype.rb diff --git a/app/models/store_item.rb b/app/models/store_item.rb index 75ea2ec4..df60a6f3 100644 --- a/app/models/store_item.rb +++ b/app/models/store_item.rb @@ -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` # diff --git a/app/models/store_purchase.rb b/app/models/store_purchase.rb index 64683360..332ef98b 100644 --- a/app/models/store_purchase.rb +++ b/app/models/store_purchase.rb @@ -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` diff --git a/db/migrate/20170323163001_change_store_item_price_datatype.rb b/db/migrate/20170323163001_change_store_item_price_datatype.rb new file mode 100644 index 00000000..9b767922 --- /dev/null +++ b/db/migrate/20170323163001_change_store_item_price_datatype.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 7746d390..0d504102 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/db/seeds.rb b/db/seeds.rb index f9e6d14b..e08af734 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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}) From b6fa64ab009d070eca97a0c2bcdaa81e0c54984e Mon Sep 17 00:00:00 2001 From: Stephen Clark Date: Thu, 23 Mar 2017 13:00:42 -0400 Subject: [PATCH 2/4] Added rake db:migrate to travis script so it can build with migrations --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5cbcbff5..924502e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,4 @@ bundler_args: --without development staging production sudo: false before_script: - bundle exec rake db:test:prepare + - bundle exec rake db:migrate RAILS_ENV=test From 3135ef7336b5b2d9646e4e4b8faac7528895348d Mon Sep 17 00:00:00 2001 From: Stephen Clark Date: Fri, 24 Mar 2017 14:34:41 -0400 Subject: [PATCH 3/4] Using migration technique from http://stackoverflow.com/questions/17150529 --- .travis.yml | 4 ++-- test/test_helper.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 924502e7..410b09ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,5 @@ rvm: bundler_args: --without development staging production sudo: false before_script: - - bundle exec rake db:test:prepare - - bundle exec rake db:migrate RAILS_ENV=test + - bundle exec rake test:prepare + - bundle exec rake db:migrate diff --git a/test/test_helper.rb b/test/test_helper.rb index e7d175b3..ba9ed8c3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,6 +8,8 @@ require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' +ActiveRecord::Migration.maintain_test_schema! + class ActiveSupport::TestCase def deny(condition) From e5c81fa917e6d0da24417b309603dbddae962079 Mon Sep 17 00:00:00 2001 From: Stephen Clark Date: Fri, 24 Mar 2017 14:38:48 -0400 Subject: [PATCH 4/4] Reverting to previous 9V battery price --- db/seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index e08af734..f9e6d14b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -719,7 +719,7 @@ # Store ------------------------------------------------------------------------- puts 'Store' -StoreItem.create({ name: '9 Volt Battery', price: 0.99, quantity: 1000}) +StoreItem.create({ name: '9 Volt Battery', price: 1, 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})