db_leftovers 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +6 -0
- data/README.md +1 -1
- data/lib/db_leftovers/dsl.rb +11 -4
- data/lib/db_leftovers/index.rb +4 -4
- data/lib/db_leftovers/version.rb +1 -1
- data/spec/postgres_spec.rb +2 -2
- metadata +2 -2
data/Changelog
CHANGED
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:
|
data/lib/db_leftovers/dsl.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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)
|
data/lib/db_leftovers/index.rb
CHANGED
@@ -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
|
data/lib/db_leftovers/version.rb
CHANGED
data/spec/postgres_spec.rb
CHANGED
@@ -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
|
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
|
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.
|
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:
|
115
|
+
hash: -1384874147210537505
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|