Skip to content

Database migrations

Akash Devaraju edited this page Jan 22, 2016 · 10 revisions

Model Migrations

User

rails generate model user name image address

Chef

rails generate model chef name email rating:float address

Review

rails generate model review description rating:float

Menu

rails generate model menu chef_id:integer name max_capacity:integer min_capacity:integer

MenuItems

rails generate model menu_item menu_id:integer name menu_items_category_id:integer

MenuItemscategory

rails generate model menu_items_category name

Cuisine

rails generate model cuisine name description

EventCuisine

rails generate model event_cuisine menu_id:integer cuisine_id:integer

Booking

rails generate model booking menu_id user_id

Migration for authentication token

rails generate migration add_auth_token_to_users

db/migrate/20140326204628_add_auth_token_to_users.rb
class AddAuthTokenToUsers < ActiveRecord::Migration
  def self.up
    change_table :users do |t|
    t.string :authentication_token
  end

  add_index  :users, :authentication_token, :unique => true
end

def self.down remove_column :users, :authentication_token end end

Price

rails generate model price menu_id json_for_chef_and_customer_price??

Models

Chef.rb

has_many :menus
has_many :bookings, through: :menus
has_many :reviews 

Review.rb

belongs_to :chef

Menu.rb

belongs_to :chef
has_many :bookings
has_many :menu_items
has_many :cuisines, through: :event_cuisine

Cuisine.rb

has_many :menus, through: :event_cuisine

Event_cuisine.rb

belongs_to :cuisine
belongs_to :menu

Menu_items.rb

belongs_to :menu
belongs_to :menu_items_category

Menu_items_category.rb

has_many :menu_items

Booking.rb

belongs_to :menu

Devise Token Auth Gem

rails g devise_token_auth:install User auth

We are authenticating user based on two scenarios – If user is logged on to the web app then use the same session – If session is not available and auth token is passed then find user based on the token