updateable_views_inheritance 1.5.0 → 1.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f91d01980fe8925967bf0ad4372fd1e8fe7dd5ce279221976dde06ab62ae405
4
- data.tar.gz: ff35d58879a312f046b560a4121bf2c8efe0e3d65cff769ccd90559031a872fd
3
+ metadata.gz: 8cc7de06768bfaa7271e412ae2a2958b2eab9d67a82ea00f63937fee7819227e
4
+ data.tar.gz: 610d697e27f5c3a930ae3b73f9ca39d96e0306c1045d8bd7464d241612505662
5
5
  SHA512:
6
- metadata.gz: 5340d92a39cb5a46c12d6bae63acc02b7f1139f7f52e9b2640ec05efd04bcfb1519559567de6e1ca1f7137526276827d93a0f7d611905376202b989f3c01b703
7
- data.tar.gz: 29283b534f2fe02e503cecf6569abb3425e99cfce2a2f7180d7fc4147320a6824d60c0392bc5b4b6e436c7e9d3fd90514fd113f9d2f2cb54d5e4f9c41bda9480
6
+ metadata.gz: 487871f182d767012231ca8bc56167bd6365f6bed2641c3ff1d9bd9dbb6ac2e2bca0104775403c614f75091e3b25501ed4671eaad4a343c90439cc5b73e87ffe
7
+ data.tar.gz: bf8a7d7d021ba1316351ec069ba36fa0fbe42a89262b58332f629082b703b249969c52237411b446e8c0b48b5fecef4ca0892a6c84a4c583c24e785bd317d1c9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.7.0 (11 March 2025)
2
+
3
+ Upgrade to Rails 7 (tested with 7.0, 7.1, 7.2 and ruby 2.7.3, 3.1.6)
4
+
5
+ ## 1.5.1 (27 February 2025)
6
+
7
+ Upgrade to Rails 5.1
8
+
1
9
  ## 1.5.0 (31 January 2025)
2
10
 
3
11
  Upgrade to Rails 5
data/Gemfile CHANGED
@@ -3,9 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in updateable_views_inheritance.gemspec
4
4
  gemspec
5
5
 
6
- if RUBY_VERSION > "2"
7
- gem 'byebug'
8
- else
9
- gem 'debugger'
10
- end
6
+ gem 'byebug'
11
7
 
@@ -90,19 +90,29 @@ module ActiveRecord #:nodoc:
90
90
  if parent
91
91
  reset_pk_sequence!(parent, pk, sequence)
92
92
  else
93
- unless pk and sequence
93
+ unless pk && sequence
94
94
  default_pk, default_sequence = pk_and_sequence_for(table)
95
+
95
96
  pk ||= default_pk
96
97
  sequence ||= default_sequence
97
98
  end
98
- if pk
99
- if sequence
100
- select_value <<-SQL, 'Reset sequence'
101
- SELECT setval('#{sequence}', (SELECT COALESCE(MAX(#{pk})+(SELECT increment_by FROM #{sequence}), (SELECT min_value FROM #{sequence})) FROM #{table}), false)
102
- SQL
103
- else
104
- @logger.warn "#{table} has primary key #{pk} with no default sequence" if @logger
99
+
100
+ if @logger && pk && !sequence
101
+ @logger.warn "#{table} has primary key #{pk} with no default sequence."
102
+ end
103
+
104
+ if pk && sequence
105
+ quoted_sequence = quote_table_name(sequence)
106
+ max_pk = query_value("SELECT MAX(#{quote_column_name pk}) FROM #{quote_table_name(table)}", "SCHEMA")
107
+ if max_pk.nil?
108
+ if postgresql_version >= 100000
109
+ minvalue = query_value("SELECT seqmin FROM pg_sequence WHERE seqrelid = #{quote(quoted_sequence)}::regclass", "SCHEMA")
110
+ else
111
+ minvalue = query_value("SELECT min_value FROM #{quoted_sequence}", "SCHEMA")
112
+ end
105
113
  end
114
+
115
+ query_value("SELECT setval(#{quote(quoted_sequence)}, #{max_pk ? max_pk : minvalue}, #{max_pk ? true : false})", "SCHEMA")
106
116
  end
107
117
  end
108
118
  end
@@ -342,33 +352,37 @@ module ActiveRecord #:nodoc:
342
352
  SQL
343
353
 
344
354
  # update
345
- execute(<<~SQL)
355
+ update_rule = <<~SQL
346
356
  CREATE OR REPLACE RULE #{quote_column_name("#{child_view}_update")} AS
347
357
  ON UPDATE TO #{quote_table_name(child_view)} DO INSTEAD (
348
- #{ if parent_columns.empty?
349
- ''
350
- else
351
- "UPDATE #{parent_table}
352
- SET #{ parent_columns.map { |col| "#{quote_column_name(col)} = NEW.#{quote_column_name(col)}" }.join(', ')}
353
- WHERE #{parent_pk} = OLD.#{parent_pk};"
354
- end }
355
- #{ if child_columns.empty?
356
- ''
357
- else
358
- "UPDATE #{child_table}
359
- SET #{ child_columns.map { |col| "#{quote_column_name(col)} = NEW.#{quote_column_name(col)}" }.join(', ')}
360
- WHERE #{child_pk} = OLD.#{parent_pk}"
361
- end }
362
- )
363
358
  SQL
359
+ unless parent_columns.empty?
360
+ update_rule += <<~SQL
361
+ UPDATE #{parent_table}
362
+ SET #{parent_columns.map { |col| "#{quote_column_name(col)} = NEW.#{quote_column_name(col)}" }.join(', ')}
363
+ WHERE #{parent_pk} = OLD.#{parent_pk};
364
+ SQL
365
+ end
366
+ unless child_columns.empty?
367
+ update_rule += <<~SQL
368
+ UPDATE #{child_table}
369
+ SET #{ child_columns.map { |col| "#{quote_column_name(col)} = NEW.#{quote_column_name(col)}" }.join(', ')}
370
+ WHERE #{child_pk} = OLD.#{parent_pk}
371
+ SQL
372
+ end
373
+ update_rule += ")"
374
+ execute(update_rule)
364
375
  end
365
376
 
366
377
  def insert_returning_clause(parent_pk, child_pk, child_view)
367
- columns_cast_to_null = columns(child_view)
368
- .reject { |c| c.name == parent_pk }
369
- .map { |c| "CAST (NULL AS #{c.sql_type})" }
370
- .join(", ")
371
- "RETURNING #{child_pk}, #{columns_cast_to_null}"
378
+ columns_cast = columns(child_view).map do |c|
379
+ if c.name == parent_pk
380
+ "#{child_pk}::#{c.sql_type}"
381
+ else
382
+ "NULL::#{c.sql_type}"
383
+ end
384
+ end.join(", ")
385
+ "RETURNING #{columns_cast}"
372
386
  end
373
387
 
374
388
  def create_system_table_records(parent_relation, child_aggregate_view, child_relation)
@@ -1,3 +1,3 @@
1
1
  module UpdateableViewsInheritance
2
- VERSION = "1.5.0"
2
+ VERSION = "1.7.0"
3
3
  end
data/test/content_test.rb CHANGED
@@ -2,11 +2,10 @@ require_relative 'test_helper'
2
2
 
3
3
  class UpdateableViewsInheritanceContentTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 5)
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(5)
6
6
  ActiveRecord::FixtureSet.reset_cache
7
7
  end
8
8
 
9
-
10
9
  def test_find
11
10
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :steam_locomotives)
12
11
  locomotive = Locomotive.find(1)
@@ -33,10 +32,7 @@ class UpdateableViewsInheritanceContentTest < ActiveSupport::TestCase
33
32
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :electric_locomotives)
34
33
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :steam_locomotives)
35
34
 
36
- binds = [[ElectricLocomotive.columns.find { |c| c.name == 'electricity_consumption'}, 40],
37
- [ElectricLocomotive.columns.find { |c| c.name == 'max_speed'}, 120],
38
- [ElectricLocomotive.columns.find { |c| c.name == 'name'}, 'BoBo'],
39
- [ElectricLocomotive.columns.find { |c| c.name == 'type'}, 'ElectricLocomotive']]
35
+ binds = [40, 120, 'BoBo', 'ElectricLocomotive']
40
36
  res = ActiveRecord::Base.connection.exec_query(<<-SQL, 'Test prepared statement', binds)
41
37
  INSERT INTO electric_locomotives (electricity_consumption, max_speed, name, type) VALUES ($1, $2, $3, $4) RETURNING id
42
38
  SQL
@@ -63,7 +59,7 @@ class UpdateableViewsInheritanceContentTest < ActiveSupport::TestCase
63
59
  def test_update
64
60
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :steam_locomotives)
65
61
  steam_locomotive = Locomotive.find(1)
66
- steam_locomotive.update_attributes( :name => 'Rocket')
62
+ steam_locomotive.update(name: 'Rocket')
67
63
  steam_locomotive.reload
68
64
  assert_equal 'Rocket', steam_locomotive.name
69
65
  end
@@ -2,12 +2,12 @@ require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
3
  class DeepHierarchyTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 8)
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(8)
6
6
 
7
7
  ActiveRecord::FixtureSet.reset_cache
8
8
  # order of fixtures is important for the test - last loaded should not be with max(id)
9
- %w(boats electric_trains rack_trains steam_trains cars maglev_trains bicycles).each do |f|
10
- ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', f)
9
+ %w(boats electric_trains rack_trains steam_trains maglev_trains bicycles).each do |f|
10
+ ActiveRecord::FixtureSet.create_fixtures("#{__dir__}/fixtures/", f)
11
11
  end
12
12
  @connection = ActiveRecord::Base.connection
13
13
  end
@@ -41,17 +41,17 @@ class DeepHierarchyTest < ActiveSupport::TestCase
41
41
 
42
42
  def test_single_table_inheritance_deeper_hierarchy_contents
43
43
  mag = MaglevTrain.first
44
- assert_equal [mag.id, mag.name, mag.number_of_rails, mag.max_speed, mag.magnetic_field, (sprintf("%.2f",mag.electricity_consumption))], (@connection.query("SELECT id, name, number_of_rails, max_speed, magnetic_field, electricity_consumption FROM all_vehicles WHERE id=#{mag.id}").first)
44
+ assert_equal [mag.id, mag.name, mag.number_of_rails, mag.max_speed, mag.magnetic_field, mag.electricity_consumption], (@connection.query("SELECT id, name, number_of_rails, max_speed, magnetic_field, electricity_consumption FROM all_vehicles WHERE id=#{mag.id}").first)
45
45
  end
46
46
 
47
47
  class OrderColumnsInAggregateView < ActiveRecord::Migration[4.2]
48
- def self.up
48
+ def up
49
49
  rebuild_single_table_inheritance_view(:all_vehicles,:vehicles, %w(max_speed number_of_wheels id))
50
50
  end
51
51
  end
52
52
 
53
53
  def test_single_table_inheritance_view_order_view_columns
54
- OrderColumnsInAggregateView.up
54
+ OrderColumnsInAggregateView.new.up
55
55
  assert_equal %w(max_speed number_of_wheels id),
56
56
  (@connection.query("SELECT attname
57
57
  FROM pg_class, pg_attribute
@@ -42,12 +42,6 @@ module Dummy
42
42
  # This is necessary if your schema can't be completely dumped by the schema dumper,
43
43
  # like if you have constraints or database-specific column types
44
44
  # config.active_record.schema_format = :sql
45
-
46
- # Enable the asset pipeline
47
- config.assets.enabled = true
48
-
49
- # Version of your assets, change this if you want to expire all your assets
50
- config.assets.version = '1.0'
51
45
  end
52
46
  end
53
47
 
@@ -1,5 +1,5 @@
1
1
  class AddUpdateableViewsInheritance < ActiveRecord::Migration[4.2]
2
- def self.up
2
+ def up
3
3
  create_table(:updateable_views_inheritance, :id => false) do |t|
4
4
  t.column :parent_relation, :string
5
5
  t.column :child_aggregate_view, :string
@@ -1,5 +1,5 @@
1
1
  class CreateWithDefaultTable < ActiveRecord::Migration[4.2]
2
- def self.up
2
+ def up
3
3
  create_table :locomotives do |t|
4
4
  t.column :name, :string
5
5
  t.column :max_speed, :integer
@@ -1,5 +1,5 @@
1
1
  class CreateWithExplicitTable < ActiveRecord::Migration[4.2]
2
- def self.up
2
+ def up
3
3
  create_child(:electric_locomotives, :table => :raw_electric_locomotives, :parent => :locomotives) do |t|
4
4
  t.decimal :electricity_consumption, :precision => 6, :scale => 2
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class CreateDeeperHierarchy < ActiveRecord::Migration[4.2]
2
- def self.up
2
+ def up
3
3
  create_child(:maglev_locomotives, :parent => :electric_locomotives) do |t|
4
4
  t.column :magnetic_field, :integer
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class DefaultColumnValues < ActiveRecord::Migration[4.2]
2
- def self.up
2
+ def up
3
3
  create_child(:rack_locomotives, :parent => :locomotives) do |t|
4
4
  t.column :bidirectional, :boolean, :default => false
5
5
  t.column :narrow_gauge, :boolean, :default => true
@@ -1,5 +1,5 @@
1
1
  class SingleTableInheritanceView < ActiveRecord::Migration[4.2]
2
- def self.up
2
+ def up
3
3
  rebuild_parent_and_children_views(:locomotives)
4
4
  create_single_table_inheritance_view(:all_locomotives,:locomotives)
5
5
  end
@@ -13,7 +13,7 @@ class SecondDeepHierarchy < ActiveRecord::Migration[4.2]
13
13
  # steam_trains rack_trains electric_trains
14
14
  # |
15
15
  # maglev_trains
16
- def self.up
16
+ def up
17
17
  create_table :vehicles do |t|
18
18
  t.column :name, :string
19
19
  t.column :vehicle_type, :string
@@ -1,5 +1,5 @@
1
1
  class SecondSingleTableInheritanceView < ActiveRecord::Migration[4.2]
2
- def self.up
2
+ def up
3
3
  rebuild_parent_and_children_views(:vehicles)
4
4
  create_single_table_inheritance_view(:all_vehicles,:vehicles)
5
5
  end
@@ -2,8 +2,7 @@ require_relative 'test_helper'
2
2
 
3
3
  class InstantiationTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 7)
6
-
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(7)
7
6
  ActiveRecord::FixtureSet.reset_cache
8
7
  # order of fixtures is important for the test - last loaded should not be with max(id)
9
8
  %w[steam_locomotives electric_locomotives maglev_locomotives bicycles].each do |f|
@@ -7,20 +7,20 @@ class UpdateableViewsInheritanceMigrationTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  def test_create_child_default
10
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 2)
10
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(2)
11
11
  assert_equal %w(coal_consumption id max_speed name type water_consumption),
12
12
  @connection.columns(:steam_locomotives).map{ |c| c.name }.sort
13
13
  end
14
14
 
15
15
  def test_create_child_explicit_table
16
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 3)
16
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(3)
17
17
  assert_equal %w(electricity_consumption id max_speed name type),
18
18
  @connection.columns(:electric_locomotives).map{ |c| c.name }.sort
19
19
  end
20
20
 
21
21
  def test_drop_child
22
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 3)
23
- ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 2)
22
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(3)
23
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(2)
24
24
  assert_equal %w(steam_locomotives), @connection.views.sort
25
25
  assert_equal %w(ar_internal_metadata
26
26
  locomotives
data/test/schema_test.rb CHANGED
@@ -2,7 +2,7 @@ require_relative 'test_helper'
2
2
 
3
3
  class SchemaTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 5)
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(5)
6
6
  @connection = ActiveRecord::Base.connection
7
7
  end
8
8
 
@@ -13,7 +13,7 @@ class SchemaTest < ActiveSupport::TestCase
13
13
  end
14
14
 
15
15
  class CreateChildInSchemaWithPublicParent < ActiveRecord::Migration[4.2]
16
- def self.up
16
+ def up
17
17
  execute "CREATE SCHEMA interrail"
18
18
  create_child('interrail.steam_locomotives', parent: 'locomotives') do |t|
19
19
  t.decimal :interrail_water_consumption, precision: 6, scale: 2
@@ -23,14 +23,14 @@ class SchemaTest < ActiveSupport::TestCase
23
23
  end
24
24
 
25
25
  def test_pk_and_sequence_for_child_and_parent_in_different_schemas
26
- CreateChildInSchemaWithPublicParent.up
26
+ CreateChildInSchemaWithPublicParent.new.up
27
27
  pk, seq = @connection.pk_and_sequence_for('interrail.steam_locomotives')
28
28
  assert_equal 'id', pk
29
29
  assert_equal 'public.locomotives_id_seq', seq.to_s
30
30
  end
31
31
 
32
32
  class CreateChildInSchemaWithParentInSchema < ActiveRecord::Migration[4.2]
33
- def self.up
33
+ def up
34
34
  execute "CREATE SCHEMA interrail"
35
35
  create_table 'interrail.locomotives' do |t|
36
36
  t.column :interrail_name, :string
@@ -45,7 +45,7 @@ class SchemaTest < ActiveSupport::TestCase
45
45
  end
46
46
 
47
47
  def test_pk_and_sequence_for_child_and_parent_in_same_nonpublic_schema
48
- CreateChildInSchemaWithParentInSchema.up
48
+ CreateChildInSchemaWithParentInSchema.new.up
49
49
  pk, seq = @connection.pk_and_sequence_for('interrail.steam_locomotives')
50
50
  assert_equal 'id', pk
51
51
  assert_equal 'interrail.locomotives_id_seq', seq.to_s
@@ -65,7 +65,7 @@ class SchemaTest < ActiveSupport::TestCase
65
65
  end
66
66
 
67
67
  class ParentTableWithOnlyOneColumn < ActiveRecord::Migration[4.2]
68
- def self.up
68
+ def up
69
69
  create_table(:parent_pk_only){}
70
70
  create_table :child_data do |t|
71
71
  t.column :name, :string
@@ -80,7 +80,7 @@ class SchemaTest < ActiveSupport::TestCase
80
80
  end
81
81
 
82
82
  def test_parent_table_with_only_one_column
83
- ParentTableWithOnlyOneColumn.up
83
+ ParentTableWithOnlyOneColumn.new.up
84
84
  assert @connection.views.include?('child')
85
85
  assert_equal %w(id name), @connection.columns(:child).map{|c| c.name}.sort
86
86
  ensure
@@ -88,7 +88,7 @@ class SchemaTest < ActiveSupport::TestCase
88
88
  end
89
89
 
90
90
  class ChildTableWithOnlyOneColumn < ActiveRecord::Migration[4.2]
91
- def self.up
91
+ def up
92
92
  create_table :parent do |t|
93
93
  t.column :name, :string
94
94
  end
@@ -98,7 +98,7 @@ class SchemaTest < ActiveSupport::TestCase
98
98
  end
99
99
 
100
100
  def test_child_table_with_only_one_column
101
- ChildTableWithOnlyOneColumn.up
101
+ ChildTableWithOnlyOneColumn.new.up
102
102
  assert @connection.views.include?('child_pk_only'), "Could not create child view when child table has only one column"
103
103
  assert_equal %w(id name), @connection.columns(:child_pk_only).map{|c| c.name}.sort
104
104
  end
@@ -133,7 +133,7 @@ class SchemaTest < ActiveSupport::TestCase
133
133
  end
134
134
 
135
135
  class ChangeDefaultValueOfColumn < ActiveRecord::Migration[4.2]
136
- def self.up
136
+ def up
137
137
  remove_parent_and_children_views(:rack_locomotives)
138
138
  change_column_default(:rack_locomotives_data, :rail_system, 'Marsh')
139
139
  rebuild_parent_and_children_views(:rack_locomotives)
@@ -141,24 +141,24 @@ class SchemaTest < ActiveSupport::TestCase
141
141
  end
142
142
 
143
143
  def test_change_default_value_of_column
144
- ChangeDefaultValueOfColumn.up
144
+ ChangeDefaultValueOfColumn.new.up
145
145
  RackLocomotive.reset_column_information
146
146
  assert_equal 'Marsh', RackLocomotive.new.rail_system
147
147
  end
148
148
 
149
149
  class RemoveChildrenViews < ActiveRecord::Migration[4.2]
150
- def self.up
150
+ def up
151
151
  remove_parent_and_children_views(:locomotives)
152
152
  end
153
153
  end
154
154
 
155
155
  def test_remove_parent_and_children_views
156
- RemoveChildrenViews.up
156
+ RemoveChildrenViews.new.up
157
157
  assert @connection.views.empty?
158
158
  end
159
159
 
160
160
  class RemoveColumnInParentTable < ActiveRecord::Migration[4.2]
161
- def self.up
161
+ def up
162
162
  remove_parent_and_children_views(:locomotives)
163
163
  remove_column(:locomotives, :max_speed)
164
164
  rebuild_parent_and_children_views(:locomotives)
@@ -166,7 +166,7 @@ class SchemaTest < ActiveSupport::TestCase
166
166
  end
167
167
 
168
168
  def test_remove_column_parent_table
169
- RemoveColumnInParentTable.up
169
+ RemoveColumnInParentTable.new.up
170
170
  assert_equal %w(coal_consumption id name type water_consumption),
171
171
  @connection.columns(:steam_locomotives).map{ |c| c.name }.sort
172
172
  assert_equal %w(electricity_consumption id magnetic_field name type),
@@ -174,7 +174,7 @@ class SchemaTest < ActiveSupport::TestCase
174
174
  end
175
175
 
176
176
  class RenameColumnInParentTable < ActiveRecord::Migration[4.2]
177
- def self.up
177
+ def up
178
178
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :electric_locomotives)
179
179
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :maglev_locomotives)
180
180
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :steam_locomotives)
@@ -186,7 +186,7 @@ class SchemaTest < ActiveSupport::TestCase
186
186
  end
187
187
 
188
188
  def test_rename_column_parent_table
189
- RenameColumnInParentTable.up
189
+ RenameColumnInParentTable.new.up
190
190
  assert_equal %w(coal_consumption id maximal_speed name type water_consumption),
191
191
  @connection.columns(:steam_locomotives).map{ |c| c.name }.sort
192
192
  assert_equal %w(electricity_consumption id magnetic_field maximal_speed name type),
@@ -195,14 +195,14 @@ class SchemaTest < ActiveSupport::TestCase
195
195
  end
196
196
 
197
197
  class AddColumnToParentTable < ActiveRecord::Migration[4.2]
198
- def self.up
198
+ def up
199
199
  add_column(:raw_electric_locomotives, :number_of_engines, :integer)
200
200
  rebuild_parent_and_children_views(:electric_locomotives)
201
201
  end
202
202
  end
203
203
 
204
204
  def test_add_column_to_parent_table
205
- AddColumnToParentTable.up
205
+ AddColumnToParentTable.new.up
206
206
  assert_equal %w(electricity_consumption id max_speed name number_of_engines type),
207
207
  @connection.columns(:electric_locomotives).map{ |c| c.name }.sort
208
208
  assert_equal %w(electricity_consumption id magnetic_field max_speed name number_of_engines type),
@@ -211,7 +211,7 @@ class SchemaTest < ActiveSupport::TestCase
211
211
  end
212
212
 
213
213
  class ChangeChildRelationView < ActiveRecord::Migration[4.2]
214
- def self.up
214
+ def up
215
215
  remove_parent_and_children_views(:electric_locomotives)
216
216
  rename_column(:raw_electric_locomotives, :electricity_consumption, :electric_consumption)
217
217
  rebuild_parent_and_children_views(:electric_locomotives)
@@ -219,13 +219,13 @@ class SchemaTest < ActiveSupport::TestCase
219
219
  end
220
220
 
221
221
  def test_change_child_relation_view
222
- ChangeChildRelationView.up
222
+ ChangeChildRelationView.new.up
223
223
  assert_equal %w(electric_consumption id max_speed name type),
224
224
  @connection.columns(:electric_locomotives).map{ |c| c.name }.sort
225
225
  end
226
226
 
227
227
  class ChangeColumnInChildTable < ActiveRecord::Migration[4.2]
228
- def self.up
228
+ def up
229
229
  drop_view(:steam_locomotives)
230
230
  rename_column(:steam_locomotives_data, :coal_consumption, :fuel_consumption)
231
231
  create_child_view(:locomotives, :steam_locomotives)
@@ -233,13 +233,13 @@ class SchemaTest < ActiveSupport::TestCase
233
233
  end
234
234
 
235
235
  def test_change_column_in_child_table
236
- ChangeColumnInChildTable.up
236
+ ChangeColumnInChildTable.new.up
237
237
  assert_equal %w(fuel_consumption id max_speed name type water_consumption),
238
238
  @connection.columns(:steam_locomotives).map(&:name).sort
239
239
  end
240
240
 
241
241
  class CreateChildInSchema < ActiveRecord::Migration[4.2]
242
- def self.up
242
+ def up
243
243
  execute "CREATE SCHEMA interrail"
244
244
  create_table 'interrail.locomotives' do |t|
245
245
  t.column :interrail_name, :string
@@ -254,7 +254,7 @@ class SchemaTest < ActiveSupport::TestCase
254
254
  end
255
255
 
256
256
  def test_create_child_in_schema
257
- CreateChildInSchema.up
257
+ CreateChildInSchema.new.up
258
258
  assert_equal %w[id
259
259
  interrail_coal_consumption
260
260
  interrail_max_speed
@@ -265,7 +265,7 @@ class SchemaTest < ActiveSupport::TestCase
265
265
  end
266
266
 
267
267
  class ChangeTablesInTwoInheritanceChains < ActiveRecord::Migration[4.2]
268
- def self.up
268
+ def up
269
269
  add_column(:maglev_locomotives_data, :levitation_height, :integer)
270
270
  add_column(:bicycles_data, :wheel_size, :integer)
271
271
  rebuild_all_parent_and_children_views
@@ -273,9 +273,9 @@ class SchemaTest < ActiveSupport::TestCase
273
273
  end
274
274
 
275
275
  def test_rebuild_all_parent_and_children_views
276
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 7)
276
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(7)
277
277
  @connection.execute "DROP VIEW all_locomotives" #FIXME: single table inheritance view should be rebuilt as well
278
- ChangeTablesInTwoInheritanceChains.up
278
+ ChangeTablesInTwoInheritanceChains.new.up
279
279
 
280
280
  assert @connection.columns(:maglev_locomotives).map{ |c| c.name }.include?('levitation_height'),
281
281
  "Newly added column not present in view after rebuild for 1. hierarchy"
@@ -284,7 +284,7 @@ class SchemaTest < ActiveSupport::TestCase
284
284
  end
285
285
 
286
286
  class UseExistingTable < ActiveRecord::Migration[4.2]
287
- def self.up
287
+ def up
288
288
  create_table :tbl_diesel_locomotives do |t|
289
289
  t.belongs_to :locomotives
290
290
  t.integer :num_cylinders
@@ -297,12 +297,12 @@ class SchemaTest < ActiveSupport::TestCase
297
297
  end
298
298
 
299
299
  def test_skip_creating_child_table
300
- UseExistingTable.up
300
+ UseExistingTable.new.up
301
301
  assert @connection.columns(:diesel_locomotives).map(&:name).include?("num_cylinders")
302
302
  end
303
303
 
304
304
  class ReservedSQLWords < ActiveRecord::Migration[4.2]
305
- def self.up
305
+ def up
306
306
  create_child(:table, parent: :locomotives) do |t|
307
307
  t.integer :column
308
308
  end
@@ -313,14 +313,14 @@ class SchemaTest < ActiveSupport::TestCase
313
313
  end
314
314
 
315
315
  def test_reserved_words_in_tables_and_columns
316
- ReservedSQLWords.up
316
+ ReservedSQLWords.new.up
317
317
  assert @connection.columns(:table).map(&:name).include?("column")
318
318
  ensure
319
319
  ReservedSQLWords.down
320
320
  end
321
321
 
322
322
  class ChildTableIsActuallyView < ActiveRecord::Migration[4.2]
323
- def self.up
323
+ def up
324
324
  execute <<-SQL.squish
325
325
  CREATE VIEW punk_locomotives_data AS (
326
326
  SELECT steam_locomotives.id,
@@ -342,7 +342,7 @@ class SchemaTest < ActiveSupport::TestCase
342
342
  end
343
343
 
344
344
  def test_child_table_is_view
345
- ChildTableIsActuallyView.up
345
+ ChildTableIsActuallyView.new.up
346
346
  assert_equal @connection.columns(:punk_locomotives).map(&:name).sort,
347
347
  %w(coal electro id max_speed name type)
348
348
  end
@@ -2,7 +2,7 @@ require_relative 'test_helper'
2
2
 
3
3
  class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 6)
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(6)
6
6
  # order of fixtures is important for the test - last loaded should not be with max(id)
7
7
  %w(electric_locomotives maglev_locomotives steam_locomotives).each do |f|
8
8
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', f)
@@ -31,7 +31,7 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
31
31
  end
32
32
 
33
33
  class AddColumnToParentTable < ActiveRecord::Migration[4.2]
34
- def self.up
34
+ def up
35
35
  add_column(:raw_electric_locomotives, :number_of_engines, :integer)
36
36
  drop_view(:all_locomotives)
37
37
  rebuild_parent_and_children_views(:electric_locomotives)
@@ -40,13 +40,13 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
40
40
  end
41
41
 
42
42
  def test_single_table_inheritance_view_add_column_to_parent_table
43
- AddColumnToParentTable.up
43
+ AddColumnToParentTable.new.up
44
44
  assert_equal %w(coal_consumption id max_speed name type water_consumption electricity_consumption bidirectional narrow_gauge magnetic_field rail_system number_of_engines).sort,
45
45
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
46
46
  end
47
47
 
48
48
  class RemoveColumnInParentTable < ActiveRecord::Migration[4.2]
49
- def self.up
49
+ def up
50
50
  drop_view(:all_locomotives)
51
51
  remove_parent_and_children_views(:locomotives)
52
52
  remove_column(:locomotives, :max_speed)
@@ -56,13 +56,13 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
56
56
  end
57
57
 
58
58
  def test_single_table_inheritance_view_remove_column_parent_table
59
- RemoveColumnInParentTable.up
59
+ RemoveColumnInParentTable.new.up
60
60
  assert_equal %w(coal_consumption id name type water_consumption electricity_consumption bidirectional narrow_gauge magnetic_field rail_system).sort,
61
61
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
62
62
  end
63
63
 
64
64
  class RenameColumnInParentTable < ActiveRecord::Migration[4.2]
65
- def self.up
65
+ def up
66
66
  drop_view(:all_locomotives)
67
67
  remove_parent_and_children_views(:locomotives)
68
68
  rename_column(:locomotives, :max_speed, :maximal_speed)
@@ -72,13 +72,13 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
72
72
  end
73
73
 
74
74
  def test_single_table_inheritance_view_rename_column_parent_table
75
- RenameColumnInParentTable.up
75
+ RenameColumnInParentTable.new.up
76
76
  assert_equal %w(coal_consumption id maximal_speed name type water_consumption electricity_consumption bidirectional narrow_gauge magnetic_field rail_system).sort,
77
77
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
78
78
  end
79
79
 
80
80
  class ChangeChildRelationView < ActiveRecord::Migration[4.2]
81
- def self.up
81
+ def up
82
82
  drop_view(:all_locomotives)
83
83
  remove_parent_and_children_views(:electric_locomotives)
84
84
  rename_column(:raw_electric_locomotives, :electricity_consumption, :electric_consumption)
@@ -88,13 +88,13 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
88
88
  end
89
89
 
90
90
  def test_single_table_inheritance_view_change_child_relation_view
91
- ChangeChildRelationView.up
91
+ ChangeChildRelationView.new.up
92
92
  assert_equal %w(coal_consumption id max_speed name type water_consumption electric_consumption bidirectional narrow_gauge magnetic_field rail_system).sort,
93
93
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
94
94
  end
95
95
 
96
96
  class ConflictColumns < ActiveRecord::Migration[4.2]
97
- def self.up
97
+ def up
98
98
  drop_view(:all_locomotives)
99
99
  add_column(:raw_electric_locomotives, :number_of_engines, :integer)
100
100
  add_column(:steam_locomotives_data, :number_of_engines, :string)
@@ -105,14 +105,14 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
105
105
  end
106
106
 
107
107
  def test_single_table_inheritance_view_conflict_columns
108
- ConflictColumns.up
108
+ ConflictColumns.new.up
109
109
  assert_equal %w(coal_consumption id max_speed name type water_consumption electricity_consumption bidirectional narrow_gauge magnetic_field rail_system number_of_engines).sort,
110
110
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
111
111
  assert_equal 'text', @connection.columns(:all_locomotives).detect{|c| c.name == "number_of_engines"}.sql_type
112
112
  end
113
113
 
114
114
  class ConflictColumnsWithValues < ActiveRecord::Migration[4.2]
115
- def self.up
115
+ def up
116
116
  add_column(:raw_electric_locomotives, :number_of_engines, :integer)
117
117
  add_column(:steam_locomotives_data, :number_of_engines, :string)
118
118
  execute("UPDATE raw_electric_locomotives SET number_of_engines = 2")
@@ -126,7 +126,7 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
126
126
 
127
127
  # FIXME: flaky test_single_table_inheritance_view_conflict_columns_with_values
128
128
  # def test_single_table_inheritance_view_conflict_columns_with_values
129
- # ConflictColumnsWithValues.up
129
+ # ConflictColumnsWithValues.new.up
130
130
  # ::SteamLocomotive.reset_column_information
131
131
  # ::ElectricLocomotive.reset_column_information
132
132
  # assert_equal %w(coal_consumption id max_speed name type water_consumption electricity_consumption bidirectional narrow_gauge magnetic_field rail_system number_of_engines).sort,
data/test/test_helper.rb CHANGED
@@ -33,9 +33,7 @@ require 'byebug'
33
33
 
34
34
  class ActiveSupport::TestCase #:nodoc:
35
35
  include ActiveRecord::TestFixtures
36
- self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
37
36
  ActiveRecord::Migration.verbose = false
38
- # self.use_transactional_fixtures = true
39
37
 
40
38
  # def teardown
41
39
  # ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
@@ -18,14 +18,14 @@ Gem::Specification.new do |s|
18
18
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency "activerecord", "~> 5.0.7"
21
+ s.add_dependency "activerecord", '>= 7', '< 8'
22
22
  s.add_dependency "pg"
23
23
 
24
- s.add_development_dependency 'bigdecimal', '1.3.5'
25
24
  s.add_development_dependency "bundler"
25
+ s.add_development_dependency "concurrent-ruby", '1.3.4'
26
26
  s.add_development_dependency "minitest"
27
27
  s.add_development_dependency "minitest-reporters"
28
- s.add_development_dependency "rails", '~> 5.0.7'
28
+ s.add_development_dependency "rails", '>= 7', '< 8'
29
29
  s.add_development_dependency "rake"
30
30
  s.add_development_dependency "simplecov"
31
31
  s.add_development_dependency "simplecov_json_formatter"
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.5.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sava Chankov
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-01-31 00:00:00.000000000 Z
12
+ date: 2025-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '7'
21
+ - - "<"
19
22
  - !ruby/object:Gem::Version
20
- version: 5.0.7
23
+ version: '8'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
- version: 5.0.7
30
+ version: '7'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '8'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: pg
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -40,33 +46,33 @@ dependencies:
40
46
  - !ruby/object:Gem::Version
41
47
  version: '0'
42
48
  - !ruby/object:Gem::Dependency
43
- name: bigdecimal
49
+ name: bundler
44
50
  requirement: !ruby/object:Gem::Requirement
45
51
  requirements:
46
- - - '='
52
+ - - ">="
47
53
  - !ruby/object:Gem::Version
48
- version: 1.3.5
54
+ version: '0'
49
55
  type: :development
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
52
58
  requirements:
53
- - - '='
59
+ - - ">="
54
60
  - !ruby/object:Gem::Version
55
- version: 1.3.5
61
+ version: '0'
56
62
  - !ruby/object:Gem::Dependency
57
- name: bundler
63
+ name: concurrent-ruby
58
64
  requirement: !ruby/object:Gem::Requirement
59
65
  requirements:
60
- - - ">="
66
+ - - '='
61
67
  - !ruby/object:Gem::Version
62
- version: '0'
68
+ version: 1.3.4
63
69
  type: :development
64
70
  prerelease: false
65
71
  version_requirements: !ruby/object:Gem::Requirement
66
72
  requirements:
67
- - - ">="
73
+ - - '='
68
74
  - !ruby/object:Gem::Version
69
- version: '0'
75
+ version: 1.3.4
70
76
  - !ruby/object:Gem::Dependency
71
77
  name: minitest
72
78
  requirement: !ruby/object:Gem::Requirement
@@ -99,16 +105,22 @@ dependencies:
99
105
  name: rails
100
106
  requirement: !ruby/object:Gem::Requirement
101
107
  requirements:
102
- - - "~>"
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '7'
111
+ - - "<"
103
112
  - !ruby/object:Gem::Version
104
- version: 5.0.7
113
+ version: '8'
105
114
  type: :development
106
115
  prerelease: false
107
116
  version_requirements: !ruby/object:Gem::Requirement
108
117
  requirements:
109
- - - "~>"
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '7'
121
+ - - "<"
110
122
  - !ruby/object:Gem::Version
111
- version: 5.0.7
123
+ version: '8'
112
124
  - !ruby/object:Gem::Dependency
113
125
  name: rake
114
126
  requirement: !ruby/object:Gem::Requirement