db_leftovers 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog CHANGED
@@ -1,3 +1,9 @@
1
+ 1.4.1
2
+ -----
3
+
4
+ - Improved feedback so we print the expression on functional indexes
5
+
6
+
1
7
  1.4.0
2
8
  -----
3
9
 
data/README.md CHANGED
@@ -138,7 +138,7 @@ The second time you run db\_leftovers, it will read the expression from Postgres
138
138
  and so it will drop and re-create the constraint.
139
139
  It will drop and re-create it every time you run the rake task.
140
140
  To get around this, make sure your config file uses the same expression as printed by db\_leftovers in the rake output.
141
- This can also happen for index WHERE clauses, fixable by a similar workaround.
141
+ This can also happen for index WHERE clauses and functional indexes, fixable by a similar workaround.
142
142
  MySQL doesn't have this problem because it doesn't support CHECK constraints or index WHERE clauses.
143
143
 
144
144
  To print messages even about indexes/foreign keys/constraints that haven't changed, you can say:
@@ -173,14 +173,21 @@ module DBLeftovers
173
173
 
174
174
  def log_new_index(idx, altered=false)
175
175
  did_what = altered ? "Dropped & re-created" : "Created"
176
- if idx.where_clause
176
+
177
+ msg = "#{did_what} index: #{idx.index_name} on #{idx.table_name}"
178
+ if idx.index_function
177
179
  # NB: This is O(n*m) where n is your indexes and m is your indexes with WHERE clauses.
178
180
  # But it's hard to believe it matters:
179
181
  new_idx = @db.lookup_all_indexes[idx.index_name]
180
- puts "#{did_what} index: #{idx.index_name} on #{idx.table_name} WHERE #{new_idx.where_clause}"
181
- else
182
- puts "#{did_what} index: #{idx.index_name} on #{idx.table_name}"
182
+ msg = "#{msg}: #{new_idx.index_function}"
183
183
  end
184
+
185
+ if idx.where_clause
186
+ new_idx ||= @db.lookup_all_indexes[idx.index_name]
187
+ msg = "#{msg} WHERE #{new_idx.where_clause}"
188
+ end
189
+
190
+ puts msg
184
191
  end
185
192
 
186
193
  def log_new_constraint(chk, altered=false)
@@ -15,8 +15,8 @@ module DBLeftovers
15
15
  opts.keys.each do |k|
16
16
  raise "Unknown option: #{k}" unless [:where, :function, :unique, :using, :name].include?(k)
17
17
  end
18
- if column_names.is_a?(String) and opts[:function].nil?
19
- opts[:function] = column_names
18
+ if column_names.is_a?(Array) and column_names[0].is_a?(String) and opts[:function].nil?
19
+ opts[:function] = column_names[0]
20
20
  column_names = []
21
21
  end
22
22
  @table_name = table_name.to_s
@@ -25,7 +25,7 @@ module DBLeftovers
25
25
  @index_function = opts[:function]
26
26
  @using_clause = opts[:using]
27
27
  @unique = !!opts[:unique]
28
- @index_name = (opts[:name] || choose_name(@table_name, @column_names)).to_s
28
+ @index_name = (opts[:name] || choose_name(@table_name, @column_names, @index_function)).to_s
29
29
 
30
30
  raise "Indexes need a table!" unless @table_name
31
31
  raise "Indexes need at least column or an expression!" unless (@column_names.any? or @index_function)
@@ -52,7 +52,7 @@ module DBLeftovers
52
52
 
53
53
  private
54
54
 
55
- def choose_name(table_name, column_names)
55
+ def choose_name(table_name, column_names, index_function)
56
56
  topic = if column_names.any?
57
57
  column_names.join("_and_")
58
58
  else
@@ -1,3 +1,3 @@
1
1
  module DbLeftovers
2
- VERSION = '1.4.0'
2
+ VERSION = '1.4.1'
3
3
  end
@@ -102,7 +102,7 @@ describe DBLeftovers::PostgresDatabaseInterface do
102
102
  @db.lookup_all_constraints['books_have_positive_pages'].check.should == 'pages_count > 12'
103
103
  end
104
104
 
105
- it "should allow functional indexes, specified as a string" do
105
+ it "should allow functional indexes specified as a string" do
106
106
  DBLeftovers::Definition.define :db_interface => @db do
107
107
  index :authors, 'lower(name)'
108
108
  end
@@ -110,7 +110,7 @@ describe DBLeftovers::PostgresDatabaseInterface do
110
110
  @db.lookup_all_indexes.keys.sort.should == ['index_authors_on_lower_name']
111
111
  end
112
112
 
113
- it "should allow functional indexes, specified with an option" do
113
+ it "should allow functional indexes specified with an option" do
114
114
  DBLeftovers::Definition.define :db_interface => @db do
115
115
  index :authors, [], function: 'lower(name)'
116
116
  end
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: 1.4.0
4
+ version: 1.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  segments:
114
114
  - 0
115
- hash: 1649859164079023412
115
+ hash: -1384874147210537505
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements: