Added credit tracking and stats

Added credit_conversions table so conversions can change over time
Added default credit conversion fixture
Added User#transaction_logs
Added User#total_credits (earned minus spent)
Added User#total_credits_spent (through transaction_logs)
Added User#total_earned_credits (complicated query which finds the conversion rate for a log depending on its created_at date)
This commit is contained in:
Jason Denney
2013-06-29 15:19:38 -04:00
parent bccd5f10d7
commit 7736ac5c34
6 changed files with 67 additions and 6 deletions
@@ -0,0 +1,8 @@
class CreateCreditConversions < ActiveRecord::Migration
def change
create_table(:credit_conversions) do |t|
t.integer :conversion, :default => 1
t.timestamps
end
end
end
+10 -4
View File
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130614003934) do
ActiveRecord::Schema.define(:version => 20130629152047) do
create_table "bike_actions", :force => true do |t|
t.string "action", :limit => 128, :null => false
@@ -65,6 +65,12 @@ ActiveRecord::Schema.define(:version => 20130614003934) do
add_index "bikes", ["shop_id"], :name => "index_bikes_on_shop_id", :unique => true
create_table "credit_conversions", :force => true do |t|
t.integer "conversion", :default => 1
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "customers", :force => true do |t|
t.string "first_name", :null => false
t.string "last_name", :null => false
@@ -155,9 +161,9 @@ ActiveRecord::Schema.define(:version => 20130614003934) do
end
create_table "user_role_joins", :force => true do |t|
t.integer "role_id", :limit => 255
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "role_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "ends"
t.integer "user_id"
end
+3
View File
@@ -0,0 +1,3 @@
conversion:
id: 1
conversion: 10