Sha256: 9a2b348213fa9eafb794fe2633be3f4323a84f5e25b01545430e868b1becd181

Contents?: true

Size: 1.14 KB

Versions: 64

Compression:

Stored size: 1.14 KB

Contents

class AddPermissionTemplateToSipityWorkflow < ActiveRecord::Migration<%= migration_version %>
  def change
    add_column :sipity_workflows, :permission_template_id, :integer, index: true
    remove_index :sipity_workflows, :name
    add_index :sipity_workflows, [:permission_template_id, :name], name: :index_sipity_workflows_on_permission_template_and_name, unique: true
    remove_index :permission_templates, :admin_set_id
    add_index :permission_templates, :admin_set_id, unique: true

    # Only allow one to be true; Note the options should be nil or true to enforce uniqueness
    add_column :sipity_workflows, :active, :boolean, default: nil, index: :unique

    # Doing an inline data migration
    begin
      if Hyrax::PermissionTemplate.column_names.include?('workflow_id')
        Hyrax::PermissionTemplate.each do |permission_template|
          workflow_id = permission_template.workflow_id
          next unless workflow_id
          Sipity::Workflow.find(workflow_id).update(active: true)
        end
        remove_column :permission_templates, :workflow_id
      end
    rescue
      # It's okay, we didn't have the column
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
hyrax-5.0.1 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-5.0.0 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-5.0.0.rc3 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-5.0.0.rc2 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-5.0.0.rc1 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-3.6.0 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-4.0.0 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-4.0.0.rc3 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-4.0.0.rc2 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-4.0.0.rc1 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-3.5.0 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-4.0.0.beta2 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-3.4.2 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-4.0.0.beta1 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-3.4.1 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-3.4.0 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-3.3.0 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-3.2.0 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-2.9.6 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb
hyrax-3.1.0 lib/generators/hyrax/templates/db/migrate/20170131142607_add_permission_template_to_sipity_workflow.rb.erb