class CreateEffectiveOrders < ActiveRecord::Migration[4.2] def self.up create_table <%= @orders_table_name %> do |t| t.integer :user_id t.string :state t.datetime :purchased_at t.text :note t.text :note_to_buyer t.text :note_internal t.string :billing_name t.text :payment t.string :payment_provider t.string :payment_card t.decimal :tax_rate, :precision => 6, :scale => 3 t.integer :subtotal t.integer :tax t.integer :total t.timestamps end add_index <%= @orders_table_name %>, :user_id create_table <%= @order_items_table_name %> do |t| t.integer :order_id t.string :purchasable_type t.integer :purchasable_id t.string :title t.integer :quantity t.integer :price, :default => 0 t.boolean :tax_exempt t.timestamps end add_index <%= @order_items_table_name %>, :order_id add_index <%= @order_items_table_name %>, :purchasable_id add_index <%= @order_items_table_name %>, [:purchasable_type, :purchasable_id] create_table <%= @carts_table_name %> do |t| t.integer :user_id t.integer :cart_items_count, :default => 0 t.timestamps end add_index <%= @carts_table_name %>, :user_id create_table <%= @cart_items_table_name %> do |t| t.integer :cart_id t.string :purchasable_type t.integer :purchasable_id t.string :unique t.integer :quantity t.timestamps end add_index <%= @cart_items_table_name %>, :cart_id add_index <%= @cart_items_table_name %>, :purchasable_id add_index <%= @cart_items_table_name %>, [:purchasable_type, :purchasable_id] create_table <%= @customers_table_name %> do |t| t.integer :user_id t.string :stripe_customer_id t.string :active_card t.string :stripe_subscription_id t.string :status t.integer :subscriptions_count, :default => 0 t.timestamps end add_index <%= @customers_table_name %>, :user_id create_table <%= @subscriptions_table_name %> do |t| t.integer :customer_id t.integer :subscribable_id t.string :subscribable_type t.string :stripe_plan_id t.string :status t.string :name t.integer :price, :default => 0 t.timestamps end add_index <%= @subscriptions_table_name %>, :customer_id add_index <%= @subscriptions_table_name %>, :subscribable_id add_index <%= @subscriptions_table_name %>, [:subscribable_type, :subscribable_id] create_table <%= @products_table_name %> do |t| t.integer :purchased_order_id t.string :title t.integer :price t.boolean :tax_exempt, :default => false t.string :qb_item_name t.timestamps end end def self.down drop_table <%= @orders_table_name %> drop_table <%= @order_items_table_name %> drop_table <%= @carts_table_name %> drop_table <%= @cart_items_table_name %> drop_table <%= @customers_table_name %> drop_table <%= @subscriptions_table_name %> drop_table <%= @products_table_name %> end end