Sha256: bee45087f9ab29fb4df8b0bf8292d6c8b428969b729c91bd6712b5623167ec46

Contents?: true

Size: 1017 Bytes

Versions: 33

Compression:

Stored size: 1017 Bytes

Contents

class NoMorePrivateNodes < ActiveRecord::Migration
  def self.up
    remove_column :sites, :allow_private
    Site.all.each do |site|
      private_count = Node.count(:conditions => ['site_id = ? AND rgroup_id = 0', site.id])
      if private_count > 0
        puts "===== changing access rights on private nodes for #{site.host} (#{private_count} nodes)"
        # create 'private' group
        private_group = Group.new(:name => '__private')
        private_group[:site_id] = site.id
        private_group.save_with_validation(false)
        if p_id = private_group.id
          execute "UPDATE nodes SET rgroup_id = #{p_id}, wgroup_id = #{p_id}, pgroup_id = #{p_id} WHERE site_id = #{site.id} AND rgroup_id = 0"
          execute "UPDATE nodes SET inherit = 0 WHERE site_id = #{site.id} AND inherit = -1"
        else
          puts "Could not create private group: #{private_group.errors.inspect}"
        end
      end
    end
  end

  def self.down
    create_column :sites, :allow_private, :boolean
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
zena-1.2.8 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.2.7 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.2.6 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.2.5 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.2.4 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.2.3 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.2.2 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.2.1 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.2.0 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.1.3 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.1.2 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.1.1 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.1.0 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.0.0 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.0.0.rc3 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.0.0.rc2 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-1.0.0.rc1 db/fix/old_migrations/20090928133440_no_more_private_nodes.rb
zena-0.16.9 db/migrate/20090928133440_no_more_private_nodes.rb
zena-1.0.0.beta3 db/migrate/20090928133440_no_more_private_nodes.rb
zena-0.16.8 db/migrate/20090928133440_no_more_private_nodes.rb