Permalink
Browse files

Adds exclude_tables filter to exclude certain tables by name

The filter option uses Regular Expressions which make it extremely hard to
exclude a set of tables from a pull/push. Therefore a new option
(-e or --exclude_tables=A,B,C) was added to exclude certain tables by name.
  • Loading branch information...
walski authored and ricardochimal committed Jan 26, 2011
1 parent 17835e0 commit 146dd2242f4aec273d2857ab8a6f14bc8b56e69b
Showing with 28 additions and 5 deletions.
  1. +1 −0 lib/taps/cli.rb
  2. +9 −4 lib/taps/operation.rb
  3. +6 −0 spec/cli_spec.rb
  4. +12 −1 spec/operation_spec.rb
View
@@ -137,6 +137,7 @@ def clientoptparse(cmd)
r_tables = v.collect { |t| "^#{t}$" }.join("|")
opts[:table_filter] = "(#{r_tables})"
end
o.on("-e", "--exclude_tables=A,B,C", Array, "Shortcut to exclude a list of tables") {|v| opts[:exclude_tables] = v}
o.on("-d", "--debug", "Enable Debug Messages") { |v| opts[:debug] = true }
o.parse!(argv)
View
@@ -36,20 +36,25 @@ def indexes_first?
def table_filter
opts[:table_filter]
end
def exclude_tables
opts[:exclude_tables] || []
end
def apply_table_filter(tables)
return tables unless table_filter
re = Regexp.new(table_filter)
return tables unless table_filter || exclude_tables
re = table_filter ? Regexp.new(table_filter) : nil
if tables.kind_of?(Hash)
ntables = {}
tables.each do |t, d|
unless re.match(t.to_s).nil?
if !exclude_tables.include?(t.to_s) && (!re || !re.match(t.to_s).nil?)
ntables[t] = d
end
end
ntables
else
tables.reject { |t| re.match(t.to_s).nil? }
tables.reject { |t| exclude_tables.include?(t.to_s) || (re && re.match(t.to_s).nil?) }
end
end
View
@@ -7,4 +7,10 @@
opts = @cli.clientoptparse(:pull)
opts[:table_filter].should == "(^mytable1$|^logs$)"
end
it "translates a list of tables to exclude into a regex that can be used in table_filter" do
@cli = Taps::Cli.new(["-e", "mytable1,logs", "sqlite://tmp.db", "http://x:y@localhost:5000"])
opts = @cli.clientoptparse(:pull)
opts[:exclude_tables].should == ['mytable1','logs']
end
end
View
@@ -10,11 +10,22 @@
@op = Taps::Operation.new('dummy://localhost', 'http://x:y@localhost:5000', :table_filter => 'abc')
@op.apply_table_filter(['abc', 'def']).should == ['abc']
end
it "returns a hash of tables that match the regex table_filter" do
@op = Taps::Operation.new('dummy://localhost', 'http://x:y@localhost:5000', :table_filter => 'abc')
@op.apply_table_filter({ 'abc' => 1, 'def' => 2 }).should == { 'abc' => 1 }
end
it "returns an array of tables without the exclude_tables tables" do
@op = Taps::Operation.new('dummy://localhost', 'http://x:y@localhost:5000', :exclude_tables => ['abc', 'ghi', 'jkl'])
@op.apply_table_filter(['abc', 'def', 'ghi', 'jkl', 'mno']).should == ['def', 'mno']
end
it "returns a hash of tables without the exclude_tables tables" do
@op = Taps::Operation.new('dummy://localhost', 'http://x:y@localhost:5000', :exclude_tables => ['abc', 'ghi', 'jkl'])
@op.apply_table_filter({ 'abc' => 1, 'def' => 2, 'ghi' => 3, 'jkl' => 4, 'mno' => 5 }).should == { 'def' => 2, 'mno' => 5 }
end
it "masks a url's password" do
@op.safe_url("mysql://root:password@localhost/mydb").should == "mysql://root:[hidden]@localhost/mydb"

0 comments on commit 146dd22

Please sign in to comment.