scientist-softserv/iiif_print

Add guard clauses to iiif print migrations

ShanaLMoore opened this issue · 0 comments

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