class CreateLibraryBibs < ActiveRecord::Migration[6.0]
  def change
    create_table :library_bibs do |t|
      t.references :school, type: :integer, null: false, index: false,
        foreign_key: { to_table: :Schools, primary_key: :SchoolID }
      t.references :item_type, null: false, index: false,
        foreign_key: { to_table: :library_item_types }

      t.string :title, null: false, limit: 128
      t.string :subtitle, limit: 128
      t.integer :published_on, limit: 4
      t.string :isbn10, limit: 10
      t.string :isbn13, limit: 13
      t.integer :lccn
      t.text :summary
      t.string :dewey, limit: 32
      t.string :lcc, limit: 32
      t.integer :page_count

      t.index [:school_id, :isbn10], unique: true
      t.index [:school_id, :isbn13], unique: true
      t.index [:school_id, :lccn], unique: true
      t.index [:school_id, :title, :subtitle]
    end
  end
end
