Sha256: 8186f7acd98f1fd0ebd7d6c8f72bbc9df6a07f506a085a1f19135121b2894c30

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literals: true

require "jobshop/helpers/migration.rb"

class CreateOrders < ActiveRecord::Migration[5.2]
  include Jobshop::Helpers::Migration

  def change # rubocop:disable Metrics/MethodLength
    create_table_with_auditing :jobshop_orders, primary_key: %i[
      organization_id order_id
    ] do |t|
      t.uuid :customer_id, null: false
      t.string :number
      t.timestamps
    end

    add_index :jobshop_orders, %i[ organization_id number ], unique: true
    add_index :jobshop_orders, %i[ organization_id customer_id ],
      name: :idx_jobshop_orders_organization_customer
    fk_organization :jobshop_orders
    foreign_key :jobshop_orders, :jobshop_customers,
      %i[ organization_id customer_id ]

    create_table_with_auditing :jobshop_order_lines, primary_key: %i[
      organization_id order_id order_line_id
    ] do |t|
      t.uuid :product_id, null: false
      t.timestamps
    end

    add_index :jobshop_order_lines, %i[ organization_id product_id ]
    fk_organization :jobshop_order_lines
    foreign_key :jobshop_order_lines, :jobshop_orders,
      %i[ organization_id order_id ]
    foreign_key :jobshop_order_lines, :jobshop_products,
      %i[ organization_id product_id ]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobshop-0.0.167 db/migrate/20171216022605_create_orders.rb