class CreateDownloads < ActiveRecord::Migration[8.1]
  def change
    create_table :downloads, id: { type: :bigint, unsigned: true },
                             charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
      t.string   :file_path,   null: false
      t.bigint   :release_id,  unsigned: true
      t.string   :ip_address
      t.string   :user_agent,  limit: 500
      t.string   :referer,     limit: 500
      t.datetime :created_at,  precision: 3
      t.datetime :updated_at,  precision: 3

      t.index :file_path
      t.index :release_id
    end

    add_foreign_key :downloads, :releases, name: "fk_downloads_release" if table_exists?(:releases)
  end
end
