Sha256: 7f429165463f0c262c7dda87ca928fb29c27c114679698e88dc17b0885136523

Contents?: true

Size: 925 Bytes

Versions: 16

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

class MigrateUserRolesToParticipatoryProcessRoles < ActiveRecord::Migration[5.1]
  class User < ApplicationRecord
    self.table_name = :decidim_users
  end

  def up
    participatory_processes = Decidim::ParticipatoryProcess.includes(:organization).all
    User.find_each do |user|
      next if user.roles.empty? || user.roles.include?("admin")

      processes = participatory_processes.select { |process| process.organization == user.organization }
      values = processes.map do |process|
        user.roles.map do |role|
          "(#{user.id}, #{process.id}, '#{role}', NOW(), NOW())"
        end
      end

      execute("
        INSERT INTO decidim_admin_participatory_process_user_roles
        (decidim_user_id, decidim_participatory_process_id, role, created_at, updated_at)
        VALUES #{values.join(", ")}
      ")
    end
    remove_column :decidim_users, :roles
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
decidim-core-0.6.5 db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-0.6.5 decidim-core/db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-core-0.6.4 db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-0.6.4 decidim-core/db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-core-0.6.3 db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-0.6.3 decidim-core/db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-core-0.6.2 db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-0.6.2 decidim-core/db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-core-0.6.1 db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-0.6.1 decidim-core/db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-core-0.6.0 db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-0.6.0 decidim-core/db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-core-0.5.1 db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-0.5.1 decidim-core/db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-core-0.5.0 db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb
decidim-0.5.0 decidim-core/db/migrate/20170713131308_migrate_user_roles_to_participatory_process_roles.rb