Skip to content

Commit

Permalink
🐛 fix barcode table schema
Browse files Browse the repository at this point in the history
  • Loading branch information
nomaster committed Nov 4, 2017
1 parent 20df3df commit d665739
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
3 changes: 2 additions & 1 deletion app/models/barcode.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Barcode < ActiveRecord::Base

validates_presence_of :drink
validates_presence_of :drink, :value
belongs_to :drink

end
3 changes: 2 additions & 1 deletion app/models/drink.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Drink < ActiveRecord::Base
validates_attachment_content_type :logo, :content_type => %w(image/jpeg image/jpg image/png)
before_post_process :normalize_filename
after_initialize :set_defaults, unless: :persisted?

has_one :barcode

def as_json(options)
h = super(options)
h["donation_recommendation"] = price # API compatibility
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20171104191523_recreate_barcodes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class RecreateBarcodes < ActiveRecord::Migration[5.1]
def change
remove_column :drinks, :barcode, :integer
drop_table :barcodes, id: false do |t|
t.string :id
t.primary_key :id
end
create_table :barcodes do |t|
t.string :value
t.index :value
t.references :drinks
end
end
end
44 changes: 23 additions & 21 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,45 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170929201659) do
ActiveRecord::Schema.define(version: 20171104191523) do

create_table "audits", force: :cascade do |t|
t.datetime "created_at"
t.decimal "difference", precision: 20, scale: 2, default: "0.0"
t.integer "drink"
t.integer "user"
t.decimal "difference", precision: 20, scale: 2, default: "0.0"
t.integer "drink"
t.integer "user"
end

create_table "barcodes", id: :string, force: :cascade do |t|
t.integer "drink", null: false
t.index ["id"], name: "sqlite_autoindex_barcodes_1", unique: true
create_table "barcodes", force: :cascade do |t|
t.string "value"
t.integer "drinks_id"
t.index ["drinks_id"], name: "index_barcodes_on_drinks_id"
t.index ["value"], name: "index_barcodes_on_value"
end

create_table "drinks", force: :cascade do |t|
t.string "name"
t.decimal "bottle_size", precision: 20, scale: 2, default: "0.0"
t.integer "caffeine"
t.decimal "price", precision: 20, scale: 2, default: "0.0"
t.string "logo_file_name"
t.string "name"
t.decimal "bottle_size", precision: 20, scale: 2, default: "0.0"
t.integer "caffeine"
t.decimal "price", precision: 20, scale: 2, default: "0.0"
t.string "logo_file_name"
t.datetime "created_at"
t.datetime "updated_at"
t.string "logo_content_type"
t.integer "logo_file_size"
t.string "logo_content_type"
t.integer "logo_file_size"
t.datetime "logo_updated_at"
t.boolean "active", default: true
t.boolean "active", default: true
end

create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "balance", precision: 20, scale: 2, default: "0.0"
t.boolean "active", default: true
t.boolean "audit", default: false
t.boolean "redirect", default: true
t.decimal "balance", precision: 20, scale: 2, default: "0.0"
t.boolean "active", default: true
t.boolean "audit", default: false
t.boolean "redirect", default: true
end

end

0 comments on commit d665739

Please sign in to comment.