scientist-softserv / iiif_print

A gem for Hyrax/Samvera for displaying PDF pages in a IIIF Compliant viewer
Apache License 2.0
4 stars 1 forks source link

Add guard clauses to iiif print migrations #344

Closed ShanaLMoore closed 4 months ago

ShanaLMoore commented 5 months ago

Per Rob's request, we should be able to run migrations multiple times. Currently we cannot because there are some migrations in iiif print that are missing guard clauses. ie - run unless X table exists.

Several examples of this can be found in bulkrax.

class AddStatusToEntry < ActiveRecord::Migration[5.1]
  def change
    add_column :bulkrax_entries, :last_error, :text unless column_exists?(:bulkrax_entries, :last_error)
    add_column :bulkrax_entries, :last_error_at, :datetime unless column_exists?(:bulkrax_entries, :last_error_at)

    add_column :bulkrax_entries, :last_succeeded_at, :datetime unless column_exists?(:bulkrax_entries, :last_succeeded_at)

  end
end
class CreateBulkraxEntries < ActiveRecord::Migration[5.1]
  def change
    unless table_exists?(:bulkrax_entries)
      create_table :bulkrax_entries do |t|
        t.string :identifier
        t.string :collection_id
        t.string :type
        t.references :importer, foreign_key: {to_table: :bulkrax_importers}
        t.text :raw_metadata
        t.text :parsed_metadata

        t.timestamps
      end
    end
  end
end