updateable_views_inheritance 1.2.2 → 1.3.0

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.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.3.0 (20 August 2015)
2
+
3
+ Features:
4
+
5
+ - rebuild views in all inheritance chains (must be run when upgrading from <= 1.2.1)
6
+
1
7
  ## 1.2.2 (18 August 2015)
2
8
 
3
9
  Bugfixes:
@@ -158,6 +158,12 @@ module ActiveRecord #:nodoc:
158
158
  drop_view(parent_relation) if is_view?(parent_relation)
159
159
  end
160
160
 
161
+ # Recreates all views in all hierarchy chains
162
+ def rebuild_all_parent_and_children_views
163
+ parent_relations = select_values('SELECT DISTINCT parent_relation FROM updateable_views_inheritance')
164
+ parent_relations.each { |parent_relation| rebuild_parent_and_children_views(parent_relation) }
165
+ end
166
+
161
167
  # Recreates views in the part of the hierarchy chain starting from the +parent_relation+.
162
168
  def rebuild_parent_and_children_views(parent_relation)
163
169
  # Current implementation is not very efficient - it can drop and recreate one and the same view in the bottom of the hierarchy many times.
@@ -1,3 +1,3 @@
1
1
  module UpdateableViewsInheritance
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
data/test/schema_test.rb CHANGED
@@ -202,4 +202,23 @@ class UpdateableViewsInheritanceSchemaTest < ActiveSupport::TestCase
202
202
  type),
203
203
  @connection.columns('interrail.steam_locomotives').map{ |c| c.name }.sort
204
204
  end
205
- end
205
+
206
+ class ChangeTablesInTwoInheritanceChains < ActiveRecord::Migration
207
+ def self.up
208
+ add_column(:maglev_locomotives_data, :levitation_height, :integer)
209
+ add_column(:bicycles_data, :wheel_size, :integer)
210
+ rebuild_all_parent_and_children_views
211
+ end
212
+ end
213
+
214
+ def test_rebuild_all_parent_and_children_views
215
+ ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 7)
216
+ @connection.execute "DROP VIEW all_locomotives" #FIXME: single table inheritance view should be rebuilt as well
217
+ ChangeTablesInTwoInheritanceChains.up
218
+
219
+ assert @connection.columns(:maglev_locomotives).map{ |c| c.name }.include?('levitation_height'),
220
+ "Newly added column not present in view after rebuild for 1. hierarchy"
221
+ assert @connection.columns(:bicycles).map{ |c| c.name }.include?('wheel_size'),
222
+ "Newly added column not present in view after rebuild for 2. hierarchy"
223
+ end
224
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: updateable_views_inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-08-18 00:00:00.000000000 Z
13
+ date: 2015-08-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord