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