# frozen_string_literals: true require "jobshop/helpers/migration.rb" class CreateRFQs < ActiveRecord::Migration[5.2] include Jobshop::Helpers::Migration def change # rubocop:disable Metrics/MethodLength create_table_with_auditing :jobshop_rfqs, primary_key: %i[ organization_id rfq_id ] do |t| t.uuid :customer_id, null: true t.uuid :requested_by_id, null: true t.string :from t.string :subject, null: false t.text :content, null: false t.timestamps end # Index for RFQs from known customer add_index :jobshop_rfqs, %i[ organization_id customer_id ], where: "customer_id IS NOT NULL" # Index for RFQs from unknown party add_index :jobshop_rfqs, %i[ organization_id customer_id ], where: "customer_id IS NULL", name: :idx_jobshop_rfqs_customer_id_is_null fk_organization :jobshop_rfqs foreign_key :jobshop_rfqs, :jobshop_customers, %i[ organization_id customer_id ] foreign_key :jobshop_rfqs, :jobshop_customer_contacts, { organization_id: :organization_id, customer_id: :customer_id, requested_by_id: :contact_id } create_table :jobshop_rfq_lines, id: false do |t| t.uuid :organization_id, null: false t.uuid :rfq_id, null: false t.uuid :rfq_line_id, null: false t.index %i[ organization_id rfq_id rfq_line_id ], unique: true, name: "idx_jobshop_rfq_lines_pkey" t.timestamps end end end