diff --git a/db/migrate/20170331024749_create_menu_items.rb b/db/migrate/20170331024749_create_menu_items.rb index 3ab06a94..ea74275a 100755 --- a/db/migrate/20170331024749_create_menu_items.rb +++ b/db/migrate/20170331024749_create_menu_items.rb @@ -1,7 +1,7 @@ class CreateMenuItems < ActiveRecord::Migration[5.1] def change create_table :menu_items do |t| - t.string :item_code, :null => false + t.string :item_code, :null => false, :index => true t.string :name, :null => false t.string :alt_name t.string :image_path diff --git a/db/migrate/20170403135934_create_orders.rb b/db/migrate/20170403135934_create_orders.rb index 4439bdba..0ccb3ef2 100755 --- a/db/migrate/20170403135934_create_orders.rb +++ b/db/migrate/20170403135934_create_orders.rb @@ -2,17 +2,18 @@ class CreateOrders < ActiveRecord::Migration[5.1] def change create_table :orders, :id => false do |t| t.string :order_id, :limit => 16, :primary_key => true #custom foreign_key to prevent conflict during sync - t.datetime :date, :null => false - t.string :source, :null => false, :default => "emenu" + t.datetime :date, :index => true, :null => false + t.string :source, :index => true, :null => false, :default => "emenu" t.string :order_type, :null => false, :default => "dine-in" t.string :customer_id, foreign_key: true, :limit => 16 t.integer :item_count, :null => false, :default => 0 t.integer :quantity_count, :null => false, :default => 0 - t.string :status, :null => false, :default => "new" + t.string :status, :index => true, :null => false, :default => "new" t.json :waiters t.json :guest_info t.timestamps end + add_index :orders, [:date, :source, :status], name: 'index_date_source_status' end end diff --git a/db/migrate/20170403140820_create_order_items.rb b/db/migrate/20170403140820_create_order_items.rb index 0bca8500..14ec9ac3 100755 --- a/db/migrate/20170403140820_create_order_items.rb +++ b/db/migrate/20170403140820_create_order_items.rb @@ -2,7 +2,7 @@ class CreateOrderItems < ActiveRecord::Migration[5.1] def change create_table :order_items, :id => false do |t| t.string :order_items_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing - t.string :order_id, foreign_key: true, :null => false, :limit => 16 + t.string :order_id, foreign_key: true, :index => true, :null => false, :limit => 16 t.string :order_item_status, :null => false, :default => "new" t.string :item_order_by #person who order this t.string :item_code, :null => false diff --git a/db/migrate/20170403142424_create_dining_facilities.rb b/db/migrate/20170403142424_create_dining_facilities.rb index cf81e775..2b227908 100755 --- a/db/migrate/20170403142424_create_dining_facilities.rb +++ b/db/migrate/20170403142424_create_dining_facilities.rb @@ -3,15 +3,16 @@ class CreateDiningFacilities < ActiveRecord::Migration[5.1] create_table :dining_facilities do |t| t.references :zone, foreign_key: true t.string :name, :null => false - t.string :status, :null => false, :default => "available" - t.string :type, :null => false, :default => "Table" + t.string :status, :null => false, :default => "available", :index => true + t.string :type, :null => false, :default => "Table", :index => true t.integer :seater, :null => false, :default => 2 t.integer :order_by t.string :created_by - t.boolean :is_active, :null => false, :default => true + t.boolean :is_active, :null => false, :default => true, :index => true t.timestamps end + add_index :dining_facilities, [:status, :type, :is_active] end end diff --git a/db/migrate/20170403155230_create_employees.rb b/db/migrate/20170403155230_create_employees.rb index 16e741d8..b984b4c2 100755 --- a/db/migrate/20170403155230_create_employees.rb +++ b/db/migrate/20170403155230_create_employees.rb @@ -3,15 +3,16 @@ class CreateEmployees < ActiveRecord::Migration[5.1] create_table :employees do |t| t.string :name, :null => false t.string :role, :null => false, :default => "cashier" - t.boolean :is_active, :default => true + t.boolean :is_active, :default => true, :index=>true t.string :emp_id, :null => false t.string :password_digest, :null => false - t.string :token_session + t.string :token_session, :index=>true t.datetime :session_expiry t.datetime :session_last_login t.string :created_by t.string :image_path t.timestamps end + add_index :employees, [:is_active, :token_session] end end diff --git a/db/migrate/20170403161857_create_sale_items.rb b/db/migrate/20170403161857_create_sale_items.rb index 2135e715..14882cbc 100755 --- a/db/migrate/20170403161857_create_sale_items.rb +++ b/db/migrate/20170403161857_create_sale_items.rb @@ -2,21 +2,22 @@ class CreateSaleItems < ActiveRecord::Migration[5.1] def change create_table :sale_items, :id => false do |t| t.string :sale_item_id, :limit => 16, :primary_key => true#custom primary key - to ensure consistence for cloud syncing - t.string :sale_id, foreign_key: true, :limit => 16 + t.string :sale_id, foreign_key: true, :limit => 16, :index => true t.string :product_code, :null => false t.string :item_instance_code t.string :product_name, :null => false t.string :product_alt_name, :null => false - t.integer :account_id, :limit => 8, :null => false, :default => 1 - t.string :status - t.string :remark - t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.decimal :unit_price, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.decimal :taxable_price, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.decimal :price, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.boolean :is_taxable, :null => false, :default => true + t.integer :account_id, :index => true, :limit => 8, :null => false, :default => 1 + t.string :status, :index => true + t.string :remark, :index => true + t.decimal :qty, :index => true, :precision => 10, :scale => 2, :null => false, :default => 0.00 + t.decimal :unit_price, :index => true, :precision => 10, :scale => 2, :null => false, :default => 0.00 + t.decimal :taxable_price, :index => true, :precision => 10, :scale => 2, :null => false, :default => 0.00 + t.decimal :price, :index => true, :precision => 10, :scale => 2, :null => false, :default => 0.00 + t.boolean :is_taxable, :index => true, :null => false, :default => true t.timestamps end + add_index :sale_items, [:sale_id, :account_id, :status, :remark, :qty, :unit_price, :taxable_price, :price, :is_taxable], name: 'index_sale_items' end end diff --git a/db/migrate/20170403163219_create_sale_taxes.rb b/db/migrate/20170403163219_create_sale_taxes.rb index ef52c9dc..046680ba 100755 --- a/db/migrate/20170403163219_create_sale_taxes.rb +++ b/db/migrate/20170403163219_create_sale_taxes.rb @@ -3,7 +3,7 @@ class CreateSaleTaxes < ActiveRecord::Migration[5.1] create_table :sale_taxes, :id => false do |t| t.string :sale_tax_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing - t.string :sale_id, foreign_key: true, :limit => 16 + t.string :sale_id, foreign_key: true, :limit => 16, :index => true, :null => false t.string :tax_name, :null => false t.decimal :tax_rate, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :tax_payable_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00 diff --git a/db/migrate/20170403163734_create_sale_payments.rb b/db/migrate/20170403163734_create_sale_payments.rb index 0e2f308a..28e59e84 100755 --- a/db/migrate/20170403163734_create_sale_payments.rb +++ b/db/migrate/20170403163734_create_sale_payments.rb @@ -3,8 +3,8 @@ class CreateSalePayments < ActiveRecord::Migration[5.1] create_table :sale_payments, :id => false do |t| t.string :sale_payment_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing - t.string :sale_id, foreign_key: true, :limit => 16 - t.string :payment_method, :null => false, :default => "cash" + t.string :sale_id, foreign_key: true, :limit => 16, :index => true + t.string :payment_method, :null => false, :default => "cash", :index => true t.decimal :payment_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :outstanding_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.string :payment_reference @@ -12,5 +12,6 @@ class CreateSalePayments < ActiveRecord::Migration[5.1] t.timestamps end + add_index :sale_payments, [:sale_id, :payment_method] end end diff --git a/db/migrate/20170403174029_create_sale_orders.rb b/db/migrate/20170403174029_create_sale_orders.rb index a786163b..8c9da5b1 100755 --- a/db/migrate/20170403174029_create_sale_orders.rb +++ b/db/migrate/20170403174029_create_sale_orders.rb @@ -3,10 +3,11 @@ class CreateSaleOrders < ActiveRecord::Migration[5.1] create_table :sale_orders, :id => false do |t| t.string :sale_order_id, :limit => 16, :primary_key => true - t.string :sale_id, foreign_key: true,:limit => 16 - t.string :order_id, foreign_key: true, :limit => 16 + t.string :sale_id, foreign_key: true,:limit => 16, :index => true + t.string :order_id, foreign_key: true, :limit => 16, :index => true t.timestamps end + add_index :sale_orders, [:sale_id, :order_id], name: 'index_sale_id_order_id' end end diff --git a/db/migrate/20170403174309_create_lookups.rb b/db/migrate/20170403174309_create_lookups.rb index 2fbd3fa7..4bdb2b52 100755 --- a/db/migrate/20170403174309_create_lookups.rb +++ b/db/migrate/20170403174309_create_lookups.rb @@ -1,7 +1,7 @@ class CreateLookups < ActiveRecord::Migration[5.1] def change create_table :lookups do |t| - t.string :lookup_type, :null => false + t.string :lookup_type, :null => false, :index => true t.string :name, :null => false t.string :value, :null => false end diff --git a/db/migrate/20170404034234_create_bookings.rb b/db/migrate/20170404034234_create_bookings.rb index 89795a83..e2dada28 100755 --- a/db/migrate/20170404034234_create_bookings.rb +++ b/db/migrate/20170404034234_create_bookings.rb @@ -5,17 +5,18 @@ class CreateBookings < ActiveRecord::Migration[5.1] t.references :dining_facility, foreign_key: true t.string :type, :null => false, :default => "Table" - t.datetime :checkin_at, :null => false + t.datetime :checkin_at, :index => true, :null => false t.string :checkin_by t.datetime :checkout_at - t.string :checkout_by + t.string :checkout_by, :index => true t.datetime :reserved_at - t.string :reserved_by - t.string :booking_status, :null => false, :default => "new" + t.string :reserved_by, :index => true + t.string :booking_status, :index => true, :null => false, :default => "new" t.string :sale_id, foreign_key: true, :limit => 16 t.string :customer_id, foreign_key: true, :limit => 16 t.timestamps end + add_index :bookings, [:checkin_at, :checkout_by, :reserved_by, :booking_status], name: 'index_bookings' end end diff --git a/db/migrate/20170408105938_create_seed_generators.rb b/db/migrate/20170408105938_create_seed_generators.rb index 14e62fe1..79bc56f6 100755 --- a/db/migrate/20170408105938_create_seed_generators.rb +++ b/db/migrate/20170408105938_create_seed_generators.rb @@ -1,7 +1,7 @@ class CreateSeedGenerators < ActiveRecord::Migration[5.1] def change create_table :seed_generators do |t| - t.string :model, :null => false, :default => "sale" + t.string :model, :null => false, :default => "sale", :index => true t.integer :increase_by, :null => false, :default => 1 t.bigint :current, :null => false ,:default => 1 t.bigint :next, :null => false, :default => 2 diff --git a/db/migrate/20170414090001_create_assigned_order_items.rb b/db/migrate/20170414090001_create_assigned_order_items.rb index e7cd8986..30cc5553 100755 --- a/db/migrate/20170414090001_create_assigned_order_items.rb +++ b/db/migrate/20170414090001_create_assigned_order_items.rb @@ -4,12 +4,14 @@ class CreateAssignedOrderItems < ActiveRecord::Migration[5.1] t.string :assigned_order_item_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing t.string :item_code, :null => false, :index => true t.string :instance_code, :null => false, :index => true - t.references :order_queue_station, foreign_key: true + t.references :order_queue_station, foreign_key: true, :index => true t.string :order_id, foreign_key: true, :limit => 16 t.boolean :print_status - t.boolean :delivery_status + t.boolean :delivery_status, :index => true t.timestamps end + add_index :assigned_order_items, :created_at + add_index :assigned_order_items, [:item_code, :instance_code, :order_queue_station_id, :delivery_status, :created_at], name: 'index_assigned_order_items' end end diff --git a/db/migrate/20170414110918_create_booking_orders.rb b/db/migrate/20170414110918_create_booking_orders.rb index 25e24b43..28fd6f08 100755 --- a/db/migrate/20170414110918_create_booking_orders.rb +++ b/db/migrate/20170414110918_create_booking_orders.rb @@ -3,10 +3,11 @@ class CreateBookingOrders < ActiveRecord::Migration[5.1] create_table :booking_orders, :id => false do |t| #t.string :booking_order_id, :limit => 16, :null => false, :index => true, :unique => true #custom primary key - to ensure consistence for cloud syncing t.primary_key :booking_order_id - t.string :booking_id, foreign_key: true, :limit => 16 - t.string :order_id, foreign_key: true, :limit => 16 + t.string :booking_id, foreign_key: true, :index => true, :limit => 16 + t.string :order_id, foreign_key: true, :index => true, :limit => 16 t.timestamps end + add_index :booking_orders, [:booking_id, :order_id], name: 'index_booking_id_order_id' end end diff --git a/db/migrate/20170622050926_create_customers.rb b/db/migrate/20170622050926_create_customers.rb index b01362fe..a98002db 100755 --- a/db/migrate/20170622050926_create_customers.rb +++ b/db/migrate/20170622050926_create_customers.rb @@ -13,12 +13,13 @@ class CreateCustomers < ActiveRecord::Migration[5.1] t.string :address t.string :card_no, :unique => true t.string :paypar_account_no, :unique => true - t.string :membership_id + t.string :membership_id, :index => true t.string :membership_type t.string :membership_authentication_code - t.string :customer_type, :default => "Dinein" + t.string :customer_type, :default => "Dinein", :index => true t.json :tax_profiles t.string :image_path end + add_index :customers, [:membership_id, :customer_type] end end diff --git a/db/migrate/20170626191519_create_shift_sales.rb b/db/migrate/20170626191519_create_shift_sales.rb index bd19a8cf..733e44b5 100755 --- a/db/migrate/20170626191519_create_shift_sales.rb +++ b/db/migrate/20170626191519_create_shift_sales.rb @@ -2,8 +2,8 @@ class CreateShiftSales < ActiveRecord::Migration[5.1] def change create_table :shift_sales do |t| t.references :cashier_terminal, foreign_key: true, :null => false - t.datetime :shift_started_at - t.datetime :shift_closed_at + t.datetime :shift_started_at, :index => true + t.datetime :shift_closed_at, :index => true t.references :employee, foreign_key: true #cashier t.decimal :opening_balance, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :closing_balance, :precision => 10, :scale => 2, :null => false, :default => 0.00 @@ -26,5 +26,6 @@ class CreateShiftSales < ActiveRecord::Migration[5.1] t.decimal :total_void, :default => 0 t.timestamps end + add_index :shift_sales, [:shift_started_at, :shift_closed_at] end end diff --git a/db/migrate/20170628103624_create_print_settings.rb b/db/migrate/20170628103624_create_print_settings.rb index 17df2411..fc705d4e 100755 --- a/db/migrate/20170628103624_create_print_settings.rb +++ b/db/migrate/20170628103624_create_print_settings.rb @@ -2,7 +2,7 @@ class CreatePrintSettings < ActiveRecord::Migration[5.1] def change create_table :print_settings do |t| t.string :name, :null => false - t.string :unique_code, :null => false + t.string :unique_code, :null => false, :index => true t.string :template t.string :font, :default => "" t.integer :header_font_size, :null => false, :default => 10 diff --git a/db/migrate/20170701101420_create_sales.rb b/db/migrate/20170701101420_create_sales.rb index 381e11a0..ac0f1615 100755 --- a/db/migrate/20170701101420_create_sales.rb +++ b/db/migrate/20170701101420_create_sales.rb @@ -8,10 +8,10 @@ class CreateSales < ActiveRecord::Migration[5.1] t.string :requested_by, :null => false t.datetime :requested_at, :null => false t.string :receipt_no, :null => false - t.datetime :receipt_date, :null => false + t.datetime :receipt_date, :index => true, :null => false t.string :customer_id, foreign_key: true, :limit => 16 - t.string :payment_status, :null => false, :default => "outstanding" - t.string :sale_status, :null => false, :default => "new" + t.string :payment_status, :index => true, :null => false, :default => "outstanding" + t.string :sale_status, :index => true, :null => false, :default => "new" t.decimal :total_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.string :discount_type, :default => "overall" t.decimal :total_discount, :precision => 10, :scale => 2, :null => false, :default => 0.00 @@ -21,11 +21,13 @@ class CreateSales < ActiveRecord::Migration[5.1] t.decimal :rounding_adjustment, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_received, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_changed, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.integer :shift_sale_id + t.integer :shift_sale_id, :index => true t.decimal :old_grand_total t.string :rebate_status t.integer :equal_persons t.timestamps end + add_index :sales, :created_at, name: 'index_created_at' + add_index :sales, [:cashier_id, :receipt_date, :payment_status, :sale_status, :shift_sale_id, :created_at], name: 'index_sales' end end diff --git a/db/migrate/20170815044557_create_promotion.rb b/db/migrate/20170815044557_create_promotion.rb index fddf293b..9b78fa89 100755 --- a/db/migrate/20170815044557_create_promotion.rb +++ b/db/migrate/20170815044557_create_promotion.rb @@ -3,10 +3,10 @@ class CreatePromotion < ActiveRecord::Migration[5.1] create_table :promotions do |t| t.string :promo_code, :limit => 16 - t.date :promo_start_date, :null => false - t.date :promo_end_date, :null => false - t.time :promo_start_hour, :null => false - t.time :promo_end_hour, :null => false + t.date :promo_start_date, :null => false, :index => true + t.date :promo_end_date, :null => false, :index => true + t.time :promo_start_hour, :null => false, :index => true + t.time :promo_end_hour, :null => false, :index => true t.string :promo_day, :null => false, :default => "[0,1,2,3,4,5,6]" t.string :promo_type, :null => false, :default => "Quantity" t.string :original_product @@ -14,5 +14,6 @@ class CreatePromotion < ActiveRecord::Migration[5.1] t.string :created_by, :null => false t.timestamps end + add_index :promotions, [:promo_start_date, :promo_end_date, :promo_start_hour, :promo_end_hour], name: 'index_promotions' end end diff --git a/db/migrate/20180109085256_create_card_sale_trans.rb b/db/migrate/20180109085256_create_card_sale_trans.rb index 45702cb9..7c610c94 100644 --- a/db/migrate/20180109085256_create_card_sale_trans.rb +++ b/db/migrate/20180109085256_create_card_sale_trans.rb @@ -1,7 +1,7 @@ class CreateCardSaleTrans < ActiveRecord::Migration[5.1] def change create_table :card_sale_trans do |t| - t.string :sale_id + t.string :sale_id, :index=>true t.date :req_date t.time :req_time t.float :req_amt, :limit=>50