db_leftovers 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.html CHANGED
@@ -126,13 +126,13 @@ If you want to add support for something else, just send me a pull request!</li>
126
126
  <h2>Contributing to db_leftovers</h2>
127
127
 
128
128
  <ul>
129
- <li>Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet</li>
130
- <li>Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it</li>
131
- <li>Fork the project</li>
132
- <li>Start a feature/bugfix branch</li>
133
- <li>Commit and push until you are happy with your contribution</li>
134
- <li>Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.</li>
135
- <li>Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.</li>
129
+ <li>Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.</li>
130
+ <li>Check out the issue tracker to make sure someone hasn't already requested and/or contributed it.</li>
131
+ <li>Fork the project.</li>
132
+ <li>Start a feature/bugfix branch.</li>
133
+ <li>Commit and push until you are happy with your contribution.</li>
134
+ <li>Make be sure to add tests for it. This is important so I don't break it in a future version unintentionally.</li>
135
+ <li>Please try not to mess with the Rakefile, version, or history. If you want to have your own version, that is fine, but please isolate that change to its own commit so I can cherry-pick around it.</li>
136
136
  </ul>
137
137
 
138
138
  <h2>Copyright</h2>
data/README.md CHANGED
@@ -124,13 +124,13 @@ Known Issues
124
124
  Contributing to db\_leftovers
125
125
  -----------------------------
126
126
 
127
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
128
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
129
- * Fork the project
130
- * Start a feature/bugfix branch
131
- * Commit and push until you are happy with your contribution
132
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
133
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
127
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
128
+ * Check out the issue tracker to make sure someone hasn't already requested and/or contributed it.
129
+ * Fork the project.
130
+ * Start a feature/bugfix branch.
131
+ * Commit and push until you are happy with your contribution.
132
+ * Make be sure to add tests for it. This is important so I don't break it in a future version unintentionally.
133
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, that is fine, but please isolate that change to its own commit so I can cherry-pick around it.
134
134
 
135
135
  Copyright
136
136
  ---------
data/TODO CHANGED
@@ -1,19 +1,3 @@
1
- - Abbreviated notation for conventional foreign keys:
2
-
3
- table :books do
4
- foreign_key :authors
5
- foreign_key :publishers, :on_delete => :cascade
6
-
7
- # and with a funny FK column but implicit PK of 'id':
8
-
9
- foreign_key :ghost_writer_id, :authors, :on_delete => :cascade
10
- end
11
-
12
- In other words, the params are foreign_key(from_table, [from_column], to_table, [to_column], [opts]).
13
-
14
-
15
- - Print the actual WHERE-clause/CHECK expression used by postgres whenever the index/constraint is created (even the first time).
16
-
17
1
  - Refactor DatabaseInterface so all methods are instance methods and Definition/DSL uses an instance, set according to the Rails database adapter and also settable to a test subclass, so we can change the definition from test to test.
18
2
 
19
3
  - Add optional tests that use a real Postgres/MySQL/SQLite if available.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.9.2
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.9.1"
8
+ s.version = "0.9.2"
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"]
@@ -80,22 +80,10 @@ module DBLeftovers
80
80
  when STATUS_CHANGED
81
81
  @db.execute_drop_index(idx.table_name, idx.index_name)
82
82
  @db.execute_add_index(idx)
83
- if idx.where_clause
84
- # NB: This is O(n*m) where n is your indexes and m is your indexes with WHERE clauses.
85
- # But it's hard to believe it matters:
86
- new_idx = @db.lookup_all_indexes[truncate_index_name(idx.index_name)]
87
- puts "Dropped & re-created index: #{idx.index_name} on #{idx.table_name} WHERE #{new_idx.where_clause}"
88
- else
89
- puts "Dropped & re-created index: #{idx.index_name} on #{idx.table_name}"
90
- end
83
+ log_new_index(idx, true)
91
84
  when STATUS_NEW
92
85
  @db.execute_add_index(idx)
93
- if idx.where_clause
94
- new_idx = @db.lookup_all_indexes[truncate_index_name(idx.index_name)]
95
- puts "Created index: #{idx.index_name} on #{idx.table_name} WHERE #{new_idx.where_clause}"
96
- else
97
- puts "Created index: #{idx.index_name} on #{idx.table_name}"
98
- end
86
+ log_new_index(idx, false)
99
87
  end
100
88
  @new_indexes[truncate_index_name(idx.index_name)] = table_name
101
89
  end
@@ -149,14 +137,10 @@ module DBLeftovers
149
137
  when STATUS_CHANGED
150
138
  @db.execute_drop_constraint(chk.constraint_name, chk.on_table)
151
139
  @db.execute_add_constraint(chk)
152
- # NB: This is O(n^2) where n is your check constraints.
153
- # But it's hard to believe it matters:
154
- new_chk = @db.lookup_all_constraints[chk.constraint_name]
155
- puts "Dropped & re-created CHECK constraint: #{chk.constraint_name} on #{chk.on_table} as #{new_chk.check}"
140
+ log_new_constraint(chk, true)
156
141
  when STATUS_NEW
157
142
  @db.execute_add_constraint(chk)
158
- new_chk = @db.lookup_all_constraints[chk.constraint_name]
159
- puts "Created CHECK constraint: #{chk.constraint_name} on #{chk.on_table} as #{new_chk.check}"
143
+ log_new_constraint(chk, false)
160
144
  end
161
145
  @new_constraints[chk.constraint_name] = chk
162
146
  end
@@ -173,6 +157,25 @@ module DBLeftovers
173
157
 
174
158
  private
175
159
 
160
+ def log_new_index(idx, altered=false)
161
+ did_what = altered ? "Dropped & re-created" : "Created"
162
+ if idx.where_clause
163
+ # NB: This is O(n*m) where n is your indexes and m is your indexes with WHERE clauses.
164
+ # But it's hard to believe it matters:
165
+ new_idx = @db.lookup_all_indexes[truncate_index_name(idx.index_name)]
166
+ puts "#{did_what} index: #{idx.index_name} on #{idx.table_name} WHERE #{new_idx.where_clause}"
167
+ else
168
+ puts "#{did_what} index: #{idx.index_name} on #{idx.table_name}"
169
+ end
170
+ end
171
+
172
+ def log_new_constraint(chk, altered=false)
173
+ # NB: This is O(n^2) where n is your check constraints.
174
+ # But it's hard to believe it matters:
175
+ new_chk = @db.lookup_all_constraints[chk.constraint_name]
176
+ puts "#{altered ? "Dropped & re-created" : "Created"} CHECK constraint: #{chk.constraint_name} on #{chk.on_table} as #{new_chk.check}"
177
+ end
178
+
176
179
  def add_index(idx)
177
180
  t = (@indexes_by_table[idx.table_name] ||= [])
178
181
  t << idx
@@ -16,6 +16,18 @@ class DBLeftovers::DatabaseInterface
16
16
  @@sqls << DBLeftovers::DatabaseInterface.normal_whitespace(sql)
17
17
  end
18
18
 
19
+ alias :old_execute_add_index :execute_add_index
20
+ def execute_add_index(idx)
21
+ old_execute_add_index(idx)
22
+ @@indexes[idx.index_name] = idx
23
+ end
24
+
25
+ alias :old_execute_add_constraint :execute_add_constraint
26
+ def execute_add_constraint(chk)
27
+ old_execute_add_constraint(chk)
28
+ @@constraints[chk.constraint_name] = chk
29
+ end
30
+
19
31
  def self.saw_sql(sql)
20
32
  # puts sqls.join("\n\n\n")
21
33
  # Don't fail if only the whitespace is different:
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.9.1
4
+ version: 0.9.2
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: 712708189
142
+ hash: 269207025
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  none: false
145
145
  requirements: