Adding enterprise limit to spree users

This commit is contained in:
Rob H
2014-09-04 14:06:53 +10:00
parent e83e2295ed
commit 2253859cd1
2 changed files with 20 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
class AddEnterpriseLimitToSpreeUsers < ActiveRecord::Migration
def up
add_column :spree_users, :enterprise_limit, :integer, default: 1, null: false
Spree::User.all.each do |u|
e_count = u.owned_enterprises.length
if u.admin? || e_count > 1
e_limit = 100
e_limit = 1000 if u.admin?
u.update_column :enterprise_limit, e_limit
end
end
end
def down
remove_column :spree_users, :enterprise_limit
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140828023619) do
ActiveRecord::Schema.define(:version => 20140904003026) do
create_table "adjustment_metadata", :force => true do |t|
t.integer "adjustment_id"
@@ -971,6 +971,7 @@ ActiveRecord::Schema.define(:version => 20140828023619) do
t.string "spree_api_key", :limit => 48
t.datetime "reset_password_sent_at"
t.string "api_key", :limit => 40
t.integer "enterprise_limit", :default => 1, :null => false
end
add_index "spree_users", ["email"], :name => "email_idx_unique", :unique => true