class CreateSalePayments < ActiveRecord::Migration[5.1]
  def change
    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, :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
      t.string :payment_status, :null => false, :default => "new"

      t.timestamps
    end
    add_index :sale_payments, [:sale_id, :payment_method]
  end
end
