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 +10 -4
- data/README.md +9 -5
- data/VERSION +1 -1
- data/db_leftovers.gemspec +1 -1
- data/lib/db_leftovers/definition.rb +1 -1
- data/lib/db_leftovers/dsl.rb +6 -4
- data/lib/tasks/leftovers.rake +1 -0
- metadata +2 -2
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
|
-
|
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.
|
1
|
+
0.6.0
|
data/db_leftovers.gemspec
CHANGED
@@ -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]
|
data/lib/db_leftovers/dsl.rb
CHANGED
@@ -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}"
|
data/lib/tasks/leftovers.rake
CHANGED
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.
|
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: -
|
142
|
+
hash: -2522100486146355365
|
143
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
144
|
none: false
|
145
145
|
requirements:
|