lib/posgra/client.rb in posgra-0.2.0 vs lib/posgra/client.rb in posgra-0.2.1

- old
+ new

@@ -1,6 +1,8 @@ class Posgra::Client + include Posgra::Utils::Helper + DEFAULT_EXCLUDE_SCHEMA = /\A(?:pg_.*|information_schema)\z/ DEFAULT_EXCLUDE_ROLE = /\A\z/ DEFAULT_EXCLUDE_DATABASE = /\A(?:template\d+|postgres)\z/ def initialize(options = {}) @@ -142,18 +144,24 @@ def pre_walk_groups(expected, actual) updated = false actual.reject {|group, _| expected.has_key?(group) - }.each {|group, _| - updated = @driver.drop_group(group) || updated + }.each {|group, actual_users| + if matched?(group, @options[:include_role], @options[:exclude_role]) + updated = @driver.drop_group(group) || updated + else + actual_users.each do |user| + updated = @driver.drop_user_from_group(user, group) || updated + end + end } updated end - def walk_groups(expected, actual, expected_users) + def walk_groups(expected, actual, current_users) updated = false expected.each do |expected_group, expected_users| actual_users = actual.delete(expected_group) @@ -165,10 +173,10 @@ (expected_users - actual_users).each do |user| updated = @driver.add_user_to_group(user, expected_group) || updated end (actual_users - expected_users).each do |user| - if expected_users.include?(user) + if current_users.include?(user) updated = @driver.drop_user_from_group(user, expected_group) || updated end end end