db_leftovers 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.html CHANGED
@@ -81,6 +81,16 @@ end
81
81
  <pre><code>rake db:leftovers
82
82
  </code></pre>
83
83
 
84
+ <p>To print messages even about indexes/foreign keys/constraints that haven't changed, you can say:</p>
85
+
86
+ <pre><code>rake db:leftovers VERBOSE=true
87
+ </code></pre>
88
+
89
+ <p>or</p>
90
+
91
+ <pre><code>rake db:leftovers DB_LEFTOVERS_VERBOSE=true
92
+ </code></pre>
93
+
84
94
  <h2>Known Issues</h2>
85
95
 
86
96
  <ul>
@@ -100,10 +110,6 @@ make an existing index unique, add a column, remove a WHERE clause, or
100
110
  anything else, it will notice and drop and re-create the index.
101
111
  I'm working on doing the same thing for foreign keys/constraints,
102
112
  but it's not done just yet.</p></li>
103
- <li><p>If your database is mostly up-to-date, then running the Rake task will spam
104
- you with messages about how this index and that foreign key already exist.
105
- These should be hidden by default and shown only if you request a higher
106
- verbosity.</p></li>
107
113
  </ul>
108
114
 
109
115
  <h2>Contributing to db_leftovers</h2>
data/README.md CHANGED
@@ -78,6 +78,14 @@ db\_leftovers comes with a Rake task named `db:leftovers`. So you can update you
78
78
 
79
79
  rake db:leftovers
80
80
 
81
+ To print messages even about indexes/foreign keys/constraints that haven't changed, you can say:
82
+
83
+ rake db:leftovers VERBOSE=true
84
+
85
+ or
86
+
87
+ rake db:leftovers DB_LEFTOVERS_VERBOSE=true
88
+
81
89
 
82
90
  Known Issues
83
91
  ------------
@@ -100,11 +108,7 @@ Known Issues
100
108
  I'm working on doing the same thing for foreign keys/constraints,
101
109
  but it's not done just yet.
102
110
 
103
- * If your database is mostly up-to-date, then running the Rake task will spam
104
- you with messages about how this index and that foreign key already exist.
105
- These should be hidden by default and shown only if you request a higher
106
- verbosity.
107
-
111
+
108
112
 
109
113
  Contributing to db\_leftovers
110
114
  -----------------------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.6.0
data/db_leftovers.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "db_leftovers"
8
- s.version = "0.5.4"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Paul A. Jungwirth"]
@@ -7,7 +7,7 @@ module DBLeftovers
7
7
  :do_foreign_keys => true,
8
8
  :do_constraints => true
9
9
  }.merge(opts)
10
- dsl = DSL.new
10
+ dsl = DSL.new(:verbose => ENV['DB_LEFTOVERS_VERBOSE'] || false)
11
11
  dsl.define(&block)
12
12
  dsl.record_indexes if opts[:do_indexes]
13
13
  dsl.record_foreign_keys if opts[:do_foreign_keys]
@@ -6,8 +6,10 @@ module DBLeftovers
6
6
  STATUS_CHANGED = 'changed'
7
7
  STATUS_NEW = 'new'
8
8
 
9
- def initialize
9
+ def initialize(opts={})
10
+ @verbose = !!opts[:verbose]
10
11
  @db = DatabaseInterface.new
12
+
11
13
  @indexes_by_table = {} # Set from the DSL
12
14
  @old_indexes = @db.lookup_all_indexes
13
15
  @new_indexes = {}
@@ -51,7 +53,7 @@ module DBLeftovers
51
53
  # puts "#{idx.table_name}.[#{idx.column_names.join(',')}]"
52
54
  case index_status(idx)
53
55
  when STATUS_EXISTS
54
- puts "Index already exists: #{idx.index_name} on #{idx.table_name}"
56
+ puts "Index already exists: #{idx.index_name} on #{idx.table_name}" if @verbose
55
57
  when STATUS_CHANGED
56
58
  @db.execute_drop_index(idx.table_name, idx.index_name)
57
59
  @db.execute_add_index(idx)
@@ -79,7 +81,7 @@ module DBLeftovers
79
81
  @foreign_keys_by_table.each do |table_name, fks|
80
82
  fks.each do |fk|
81
83
  if foreign_key_exists?(fk)
82
- puts "Foreign Key already exists: #{fk.constraint_name} on #{fk.from_table}"
84
+ puts "Foreign Key already exists: #{fk.constraint_name} on #{fk.from_table}" if @verbose
83
85
  else
84
86
  @db.execute_add_foreign_key(fk)
85
87
  puts "Created foreign key: #{fk.constraint_name} on #{fk.from_table}"
@@ -102,7 +104,7 @@ module DBLeftovers
102
104
  @constraints_by_table.each do |table_name, chks|
103
105
  chks.each do |chk|
104
106
  if constraint_exists?(chk)
105
- puts "Constraint already exists: #{chk.constraint_name} on #{chk.on_table}"
107
+ puts "Constraint already exists: #{chk.constraint_name} on #{chk.on_table}" if @verbose
106
108
  else
107
109
  @db.execute_add_constraint(chk)
108
110
  puts "Created CHECK constraint: #{chk.constraint_name} on #{chk.on_table}"
@@ -2,6 +2,7 @@ namespace :db do
2
2
 
3
3
  desc "Set up indexes, foreign keys, and constraints"
4
4
  task :leftovers, [] => [:environment] do
5
+ ENV['DB_LEFTOVERS_VERBOSE'] = ENV['VERBOSE'] || ENV['DB_LEFTOVERS_VERBOSE']
5
6
  load File.join(::Rails.root.to_s, 'config', 'db_leftovers.rb')
6
7
  end
7
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_leftovers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -139,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  segments:
141
141
  - 0
142
- hash: -1286552012513738437
142
+ hash: -2522100486146355365
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  none: false
145
145
  requirements: