Skip to content

Commit

Permalink
Reenable barcodes for items, generate migration to assign barcode data
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNaessens committed Apr 20, 2015
1 parent 0fcfe79 commit 306431d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
2 changes: 2 additions & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Item < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
validates :price, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }

before_create :generate_barcode

def price
from_cents read_attribute(:price)
end
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20150420181046_add_barcode_to_all_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddBarcodeToAllItems < ActiveRecord::Migration
def change
Item.all.each do |i|
if i.barcode.nil?
i.generate_barcode
i.save
end
end
end
end
56 changes: 28 additions & 28 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140826191310) do
ActiveRecord::Schema.define(version: 20150420181046) do

create_table "items", force: true do |t|
t.string "name"
t.string "description"
create_table "items", force: :cascade do |t|
t.string "name", limit: 255
t.string "description", limit: 255
t.integer "price"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "quantity"
t.string "barcode"
t.string "barcode_data"
t.string "barcode", limit: 255
t.string "barcode_data", limit: 255
end

create_table "reservations", force: true do |t|
create_table "reservations", force: :cascade do |t|
t.integer "item_id"
t.integer "user_id"
t.integer "count"
Expand All @@ -41,44 +41,44 @@
add_index "reservations", ["item_id"], name: "index_reservations_on_item_id"
add_index "reservations", ["user_id"], name: "index_reservations_on_user_id"

create_table "settings", force: true do |t|
create_table "settings", force: :cascade do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string "email"
t.string "email", limit: 255
t.datetime "deadline"
t.string "name"
t.string "name", limit: 255
end

create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
create_table "users", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "reset_password_token", limit: 255
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.string "authentication_token"
t.string "role", default: "partner"
t.string "name"
t.boolean "sent", default: true
t.string "barcode"
t.string "barcode_data"
t.string "authentication_token", limit: 255
t.string "role", limit: 255, default: "partner"
t.string "name", limit: 255
t.boolean "sent", default: true
t.string "barcode", limit: 255
t.string "barcode_data", limit: 255
end

add_index "users", ["authentication_token"], name: "index_users_on_authentication_token"
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

create_table "versions", force: true do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
create_table "versions", force: :cascade do |t|
t.string "item_type", limit: 255, null: false
t.integer "item_id", null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object"
t.datetime "created_at"
t.text "object_changes"
Expand Down

0 comments on commit 306431d

Please sign in to comment.