updateable_views_inheritance 1.4.8 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7b78d1ecf36dad960f1b6ffccb8a640cbb9e1f06a8a8c1719f25f022e040aff
4
- data.tar.gz: 2a3f41c5bb02ca8b2907c1a563cac2c4ed06429f712fed5f3b5f6ffcd988f34c
3
+ metadata.gz: 2f91d01980fe8925967bf0ad4372fd1e8fe7dd5ce279221976dde06ab62ae405
4
+ data.tar.gz: ff35d58879a312f046b560a4121bf2c8efe0e3d65cff769ccd90559031a872fd
5
5
  SHA512:
6
- metadata.gz: 33bbf8b1caf17c212f5f8f2712476f212cea3fd09c5d8ada27c6ee235bd1e8e65792afff98606daeb2c462756f21331f76597bc2f27dae17ecbcc90cfaa41ecc
7
- data.tar.gz: b26957b4721cffcae777c4e9e7e7280f2a5ab2d1a008c00f551bb6c0db39fe7c6f19616570efde7d8cc8e18802d36814ce1fca80c6add8401571bc73a6e880bb
6
+ metadata.gz: 5340d92a39cb5a46c12d6bae63acc02b7f1139f7f52e9b2640ec05efd04bcfb1519559567de6e1ca1f7137526276827d93a0f7d611905376202b989f3c01b703
7
+ data.tar.gz: 29283b534f2fe02e503cecf6569abb3425e99cfce2a2f7180d7fc4147320a6824d60c0392bc5b4b6e436c7e9d3fd90514fd113f9d2f2cb54d5e4f9c41bda9480
@@ -41,15 +41,14 @@ jobs:
41
41
  - name: Set up Ruby
42
42
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
43
43
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
44
- # uses: ruby/setup-ruby@v1
45
- uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
44
+ uses: ruby/setup-ruby@v1
46
45
  with:
47
46
  ruby-version: ${{ matrix.ruby-version }}
48
- bundler: 1.17.3 # temporary set until rails 5 upgrade
47
+ bundler: 2.4.22 # temporary set until rails 5 upgrade
49
48
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
50
49
 
51
50
  - name: Run tests
52
- run: bundle exec rake 2>/dev/null # disable warnings until ruby 3 upgrade
51
+ run: bundle exec rake
53
52
 
54
53
  # From https://stackoverflow.com/questions/74199483/sonarcloud-ci-cant-find-source-files-for-ruby-simplecov-coverage
55
54
  - name: Fix code coverage paths for DeepSource
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.5.0 (31 January 2025)
2
+
3
+ Upgrade to Rails 5
4
+
1
5
  ## 1.4.8 (17 December 2024)
2
6
  Bugfixes:
3
7
  - Fix pk_and_sequence_for to be interoperable with other AR methods
@@ -0,0 +1,22 @@
1
+
2
+ module UpdateableViewsInheritance# :nodoc:
3
+ module ActiveRecordExtensions #:nodoc:
4
+ module ClassMethods #:nodoc:
5
+ attr_accessor :disable_inheritance_instantiation
6
+
7
+ def instantiate(attributes, column_types = {})
8
+ object = super(attributes, column_types = {})
9
+ if object.class.name == self.name || self.disable_inheritance_instantiation
10
+ object
11
+ else
12
+ object.class.find(attributes.with_indifferent_access[:id])
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ # Here we override AR class methods. If you need to override
20
+ # instance methods, prepend() them to the class, not to the singleton class
21
+ ActiveRecord::Base.singleton_class.send :prepend, UpdateableViewsInheritance::ActiveRecordExtensions::ClassMethods
22
+
@@ -150,16 +150,6 @@ module ActiveRecord #:nodoc:
150
150
  execute "DROP VIEW #{quote_table_name(name)}"
151
151
  end
152
152
 
153
- # Return the list of all views in the schema search path.
154
- def views(name=nil)
155
- schemas = schema_search_path.split(/,\s*/).map { |p| quote(p) }.join(',')
156
- query(<<~SQL, name).map { |row| row[0] }
157
- SELECT viewname
158
- FROM pg_views
159
- WHERE schemaname IN (#{schemas})
160
- SQL
161
- end
162
-
163
153
  # Checks whether relation +name+ is a view.
164
154
  def is_view?(name)
165
155
  result = query(<<~SQL, name).map { |row| row[0] }
@@ -262,11 +252,6 @@ module ActiveRecord #:nodoc:
262
252
  false
263
253
  end
264
254
 
265
- def table_exists_with_updateable_views_inheritance_support?(name)
266
- is_view?(name) ? true : table_exists_without_updateable_views_inheritance_support?(name)
267
- end
268
- alias_method_chain :table_exists?, :updateable_views_inheritance_support
269
-
270
255
  module Tutuf #:nodoc:
271
256
  class ClassTableReflection
272
257
  class << self
@@ -403,7 +388,7 @@ module ActiveRecord #:nodoc:
403
388
  end
404
389
 
405
390
  def parent_table(relation)
406
- if table_exists?('updateable_views_inheritance')
391
+ if data_source_exists?('updateable_views_inheritance')
407
392
  res = query(<<-SQL, 'Parent relation')[0]
408
393
  SELECT parent_relation
409
394
  FROM updateable_views_inheritance
@@ -1,3 +1,3 @@
1
1
  module UpdateableViewsInheritance
2
- VERSION = "1.4.8"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'active_record'
2
2
  require 'active_record/connection_adapters/postgresql_adapter'
3
3
  require "updateable_views_inheritance/version"
4
- require "updateable_views_inheritance/active_record"
4
+ require "updateable_views_inheritance/active_record_extensions"
5
5
  require 'updateable_views_inheritance/postgresql_adapter'
@@ -3,6 +3,8 @@ require File.join(File.dirname(__FILE__), 'test_helper')
3
3
  class DeepHierarchyTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 8)
6
+
7
+ ActiveRecord::FixtureSet.reset_cache
6
8
  # order of fixtures is important for the test - last loaded should not be with max(id)
7
9
  %w(boats electric_trains rack_trains steam_trains cars maglev_trains bicycles).each do |f|
8
10
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', f)
@@ -10,10 +12,6 @@ class DeepHierarchyTest < ActiveSupport::TestCase
10
12
  @connection = ActiveRecord::Base.connection
11
13
  end
12
14
 
13
- def teardown
14
- ActiveRecord::FixtureSet.reset_cache
15
- end
16
-
17
15
  def test_deeper_hierarchy
18
16
  assert_equal [["boats"], ["railed_vehicles", ["trains", ["steam_trains"], ["rack_trains"], ["electric_trains", ["maglev_trains"]]]], ["wheeled_vehicles", ["bicycles"], ["cars"]]].sort,
19
17
  @connection.send(:get_view_hierarchy_for, :vehicles).sort
@@ -43,10 +41,10 @@ class DeepHierarchyTest < ActiveSupport::TestCase
43
41
 
44
42
  def test_single_table_inheritance_deeper_hierarchy_contents
45
43
  mag = MaglevTrain.first
46
- assert_equal [mag.id.to_s, mag.name, mag.number_of_rails.to_s, mag.max_speed.to_s, mag.magnetic_field.to_s, (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, (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)
47
45
  end
48
46
 
49
- class OrderColumnsInAggregateView < ActiveRecord::Migration
47
+ class OrderColumnsInAggregateView < ActiveRecord::Migration[4.2]
50
48
  def self.up
51
49
  rebuild_single_table_inheritance_view(:all_vehicles,:vehicles, %w(max_speed number_of_wheels id))
52
50
  end
@@ -1,3 +1,2 @@
1
1
  class Locomotive < ActiveRecord::Base
2
- abstract_class = true
3
2
  end
@@ -1,4 +1,3 @@
1
1
  class Vehicle < ActiveRecord::Base
2
- abstract_class = true
3
2
  self.inheritance_column = :vehicle_type
4
- end
3
+ end
@@ -8,8 +8,8 @@ Dummy::Application.configure do
8
8
  config.cache_classes = true
9
9
 
10
10
  # Configure static asset server for tests with Cache-Control for performance
11
- config.serve_static_files = true
12
- config.static_cache_control = "public, max-age=3600"
11
+ config.public_file_server.enabled = true
12
+ config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
13
13
 
14
14
  # Show full error reports and disable caching
15
15
  config.consider_all_requests_local = true
@@ -1,4 +1,4 @@
1
- class AddUpdateableViewsInheritance < ActiveRecord::Migration
1
+ class AddUpdateableViewsInheritance < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_table(:updateable_views_inheritance, :id => false) do |t|
4
4
  t.column :parent_relation, :string
@@ -1,4 +1,4 @@
1
- class CreateWithDefaultTable < ActiveRecord::Migration
1
+ class CreateWithDefaultTable < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_table :locomotives do |t|
4
4
  t.column :name, :string
@@ -1,11 +1,11 @@
1
- class CreateWithExplicitTable < ActiveRecord::Migration
1
+ class CreateWithExplicitTable < ActiveRecord::Migration[4.2]
2
2
  def self.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
6
6
  end
7
-
7
+
8
8
  def self.down
9
9
  drop_child :electric_locomotives
10
10
  end
11
- end
11
+ end
@@ -1,10 +1,10 @@
1
- class CreateDeeperHierarchy < ActiveRecord::Migration
1
+ class CreateDeeperHierarchy < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_child(:maglev_locomotives, :parent => :electric_locomotives) do |t|
4
4
  t.column :magnetic_field, :integer
5
5
  end
6
6
  end
7
-
7
+
8
8
  def self.down
9
9
  drop_child :maglev_locomotives
10
10
  end
@@ -1,4 +1,4 @@
1
- class DefaultColumnValues < ActiveRecord::Migration
1
+ class DefaultColumnValues < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_child(:rack_locomotives, :parent => :locomotives) do |t|
4
4
  t.column :bidirectional, :boolean, :default => false
@@ -6,8 +6,8 @@ class DefaultColumnValues < ActiveRecord::Migration
6
6
  t.column :rail_system, :string, :default => 'Abt'
7
7
  end
8
8
  end
9
-
9
+
10
10
  def self.down
11
11
  drop_child :rack_locomotives
12
12
  end
13
- end
13
+ end
@@ -1,4 +1,4 @@
1
- class SingleTableInheritanceView < ActiveRecord::Migration
1
+ class SingleTableInheritanceView < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  rebuild_parent_and_children_views(:locomotives)
4
4
  create_single_table_inheritance_view(:all_locomotives,:locomotives)
@@ -7,4 +7,4 @@ class SingleTableInheritanceView < ActiveRecord::Migration
7
7
  def self.down
8
8
  drop_view(:all_locomotives)
9
9
  end
10
- end
10
+ end
@@ -1,4 +1,4 @@
1
- class SecondDeepHierarchy < ActiveRecord::Migration
1
+ class SecondDeepHierarchy < ActiveRecord::Migration[4.2]
2
2
  # Create tables and views for the following inheritance hierarchy:
3
3
  #
4
4
  # vehicles
@@ -18,32 +18,32 @@ class SecondDeepHierarchy < ActiveRecord::Migration
18
18
  t.column :name, :string
19
19
  t.column :vehicle_type, :string
20
20
  end
21
-
21
+
22
22
  create_child(:wheeled_vehicles, :parent => :vehicles) do |t|
23
23
  t.column :number_of_wheels, :integer
24
24
  end
25
-
25
+
26
26
  create_child(:bicycles, :parent => :wheeled_vehicles) do |t|
27
27
  t.column :number_of_gears, :integer
28
28
  end
29
-
29
+
30
30
  create_child(:cars, :parent => :wheeled_vehicles) do |t|
31
31
  t.column :number_of_doors, :integer
32
32
  end
33
-
33
+
34
34
  create_child(:railed_vehicles, :parent => :vehicles) do |t|
35
35
  t.column :number_of_rails, :integer
36
36
  end
37
-
37
+
38
38
  create_child(:trains, :parent => :railed_vehicles) do |t|
39
39
  t.column :max_speed, :integer
40
40
  end
41
-
41
+
42
42
  create_child(:steam_trains, :parent => :trains) do |t|
43
43
  t.column :water_consumption, :decimal, :precision => 6, :scale => 2
44
44
  t.column :coal_consumption, :decimal, :precision => 6, :scale => 2
45
45
  end
46
-
46
+
47
47
  create_child(:rack_trains, :parent => :trains) do |t|
48
48
  t.column :bidirectional, :boolean, :default => false
49
49
  t.column :narrow_gauge, :boolean, :default => true
@@ -53,7 +53,7 @@ class SecondDeepHierarchy < ActiveRecord::Migration
53
53
  create_child(:electric_trains, :parent => :trains) do |t|
54
54
  t.column :electricity_consumption, :decimal, :precision => 6, :scale => 2
55
55
  end
56
-
56
+
57
57
  create_child(:maglev_trains, :parent => :electric_trains) do |t|
58
58
  t.column :magnetic_field, :integer
59
59
  end
@@ -62,9 +62,9 @@ class SecondDeepHierarchy < ActiveRecord::Migration
62
62
  t.column :mast_number, :integer
63
63
  end
64
64
  end
65
-
65
+
66
66
  def self.down
67
67
  %w(boats maglev_trains electric_trains steam_trains rack_trains trains railed_vehicles cars bicycles wheeled_vehicles).each{|child| drop_child(child)}
68
68
  drop_table :vehicles
69
69
  end
70
- end
70
+ end
@@ -1,4 +1,4 @@
1
- class SecondSingleTableInheritanceView < ActiveRecord::Migration
1
+ class SecondSingleTableInheritanceView < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  rebuild_parent_and_children_views(:vehicles)
4
4
  create_single_table_inheritance_view(:all_vehicles,:vehicles)
@@ -7,4 +7,4 @@ class SecondSingleTableInheritanceView < ActiveRecord::Migration
7
7
  def self.down
8
8
  drop_view(:all_vehicles)
9
9
  end
10
- end
10
+ end
@@ -3,11 +3,12 @@ require_relative 'test_helper'
3
3
  class InstantiationTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 7)
6
+
7
+ ActiveRecord::FixtureSet.reset_cache
6
8
  # order of fixtures is important for the test - last loaded should not be with max(id)
7
9
  %w[steam_locomotives electric_locomotives maglev_locomotives bicycles].each do |f|
8
10
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', f)
9
11
  end
10
- @connection = ActiveRecord::Base.connection
11
12
 
12
13
  Locomotive.disable_inheritance_instantiation = true
13
14
  ElectricLocomotive.disable_inheritance_instantiation = false
@@ -15,7 +16,6 @@ class InstantiationTest < ActiveSupport::TestCase
15
16
 
16
17
  def teardown
17
18
  Locomotive.disable_inheritance_instantiation = false
18
- ActiveRecord::FixtureSet.reset_cache
19
19
  end
20
20
 
21
21
  # FIXME: flaky test_setting_disable_inheritance_instantiation_does_not_load_child_columns
@@ -22,7 +22,8 @@ class UpdateableViewsInheritanceMigrationTest < ActiveSupport::TestCase
22
22
  ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 3)
23
23
  ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 2)
24
24
  assert_equal %w(steam_locomotives), @connection.views.sort
25
- assert_equal %w(locomotives
25
+ assert_equal %w(ar_internal_metadata
26
+ locomotives
26
27
  schema_migrations
27
28
  steam_locomotives_data
28
29
  updateable_views_inheritance), @connection.tables.sort
@@ -0,0 +1,60 @@
1
+ require_relative 'test_helper'
2
+
3
+ class InsertReturningOnViewWithRulesAndDefaultValue < ActiveSupport::TestCase
4
+ def setup
5
+ @conn = ActiveRecord::Base.connection.raw_connection
6
+ @conn.exec("SET client_min_messages TO 'ERROR'")
7
+
8
+ @conn.exec(<<-SQL.squish)
9
+ CREATE TABLE parent (
10
+ id SERIAL PRIMARY KEY,
11
+ name TEXT
12
+ )
13
+ SQL
14
+
15
+ @conn.exec(<<-SQL.squish)
16
+ CREATE TABLE child (
17
+ parent_id INTEGER PRIMARY KEY REFERENCES parent(id),
18
+ surname TEXT
19
+ )
20
+ SQL
21
+
22
+ @conn.exec(<<-SQL.squish)
23
+ CREATE VIEW v AS (
24
+ SELECT id, name, surname
25
+ FROM parent JOIN child ON parent.id=child.parent_id
26
+ )
27
+ SQL
28
+
29
+ @conn.exec(<<-SQL.squish)
30
+ ALTER VIEW v ALTER id SET DEFAULT nextval('parent_id_seq'::regclass)
31
+ SQL
32
+
33
+ @conn.exec(<<-SQL.squish)
34
+ CREATE RULE v_on_insert AS ON INSERT TO v DO INSTEAD (
35
+ INSERT INTO parent (id, name)
36
+ VALUES( DEFAULT, NEW.name );
37
+ INSERT INTO child (parent_id, surname)
38
+ VALUES( currval('parent_id_seq'), NEW.surname ) RETURNING parent_id, NULL::text, NULL::text;
39
+ )
40
+ SQL
41
+
42
+ @sql = "INSERT INTO v (name, surname) VALUES ('parent', 'child') RETURNING id"
43
+ end
44
+
45
+ def teardown
46
+ @conn.exec("DROP VIEW IF EXISTS v")
47
+ @conn.exec("DROP TABLE IF EXISTS parent CASCADE")
48
+ @conn.exec("DROP TABLE IF EXISTS child CASCADE")
49
+ end
50
+
51
+ def test_async_exec_with_empty_binds
52
+ res = @conn.async_exec(@sql, [])
53
+ assert_equal [[1]], res.values
54
+ end
55
+
56
+ def test_async_exec_with_no_binds
57
+ res = @conn.async_exec(@sql)
58
+ assert_equal [[1]], res.values
59
+ end
60
+ end
data/test/schema_test.rb CHANGED
@@ -12,7 +12,7 @@ class SchemaTest < ActiveSupport::TestCase
12
12
  assert_equal 'public.locomotives_id_seq', seq.to_s
13
13
  end
14
14
 
15
- class CreateChildInSchemaWithPublicParent < ActiveRecord::Migration
15
+ class CreateChildInSchemaWithPublicParent < ActiveRecord::Migration[4.2]
16
16
  def self.up
17
17
  execute "CREATE SCHEMA interrail"
18
18
  create_child('interrail.steam_locomotives', parent: 'locomotives') do |t|
@@ -29,7 +29,7 @@ class SchemaTest < ActiveSupport::TestCase
29
29
  assert_equal 'public.locomotives_id_seq', seq.to_s
30
30
  end
31
31
 
32
- class CreateChildInSchemaWithParentInSchema < ActiveRecord::Migration
32
+ class CreateChildInSchemaWithParentInSchema < ActiveRecord::Migration[4.2]
33
33
  def self.up
34
34
  execute "CREATE SCHEMA interrail"
35
35
  create_table 'interrail.locomotives' do |t|
@@ -64,7 +64,7 @@ class SchemaTest < ActiveSupport::TestCase
64
64
  @connection.views.sort
65
65
  end
66
66
 
67
- class ParentTableWithOnlyOneColumn < ActiveRecord::Migration
67
+ class ParentTableWithOnlyOneColumn < ActiveRecord::Migration[4.2]
68
68
  def self.up
69
69
  create_table(:parent_pk_only){}
70
70
  create_table :child_data do |t|
@@ -87,7 +87,7 @@ class SchemaTest < ActiveSupport::TestCase
87
87
  ParentTableWithOnlyOneColumn.down
88
88
  end
89
89
 
90
- class ChildTableWithOnlyOneColumn < ActiveRecord::Migration
90
+ class ChildTableWithOnlyOneColumn < ActiveRecord::Migration[4.2]
91
91
  def self.up
92
92
  create_table :parent do |t|
93
93
  t.column :name, :string
@@ -132,7 +132,7 @@ class SchemaTest < ActiveSupport::TestCase
132
132
  assert SteamLocomotive.columns.find { |c| c.name == 'water_consumption' }.null
133
133
  end
134
134
 
135
- class ChangeDefaultValueOfColumn < ActiveRecord::Migration
135
+ class ChangeDefaultValueOfColumn < ActiveRecord::Migration[4.2]
136
136
  def self.up
137
137
  remove_parent_and_children_views(:rack_locomotives)
138
138
  change_column_default(:rack_locomotives_data, :rail_system, 'Marsh')
@@ -146,7 +146,7 @@ class SchemaTest < ActiveSupport::TestCase
146
146
  assert_equal 'Marsh', RackLocomotive.new.rail_system
147
147
  end
148
148
 
149
- class RemoveChildrenViews < ActiveRecord::Migration
149
+ class RemoveChildrenViews < ActiveRecord::Migration[4.2]
150
150
  def self.up
151
151
  remove_parent_and_children_views(:locomotives)
152
152
  end
@@ -157,7 +157,7 @@ class SchemaTest < ActiveSupport::TestCase
157
157
  assert @connection.views.empty?
158
158
  end
159
159
 
160
- class RemoveColumnInParentTable < ActiveRecord::Migration
160
+ class RemoveColumnInParentTable < ActiveRecord::Migration[4.2]
161
161
  def self.up
162
162
  remove_parent_and_children_views(:locomotives)
163
163
  remove_column(:locomotives, :max_speed)
@@ -173,7 +173,7 @@ class SchemaTest < ActiveSupport::TestCase
173
173
  @connection.columns(:maglev_locomotives).map{ |c| c.name }.sort
174
174
  end
175
175
 
176
- class RenameColumnInParentTable < ActiveRecord::Migration
176
+ class RenameColumnInParentTable < ActiveRecord::Migration[4.2]
177
177
  def self.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)
@@ -194,7 +194,7 @@ class SchemaTest < ActiveSupport::TestCase
194
194
 
195
195
  end
196
196
 
197
- class AddColumnToParentTable < ActiveRecord::Migration
197
+ class AddColumnToParentTable < ActiveRecord::Migration[4.2]
198
198
  def self.up
199
199
  add_column(:raw_electric_locomotives, :number_of_engines, :integer)
200
200
  rebuild_parent_and_children_views(:electric_locomotives)
@@ -210,7 +210,7 @@ class SchemaTest < ActiveSupport::TestCase
210
210
 
211
211
  end
212
212
 
213
- class ChangeChildRelationView < ActiveRecord::Migration
213
+ class ChangeChildRelationView < ActiveRecord::Migration[4.2]
214
214
  def self.up
215
215
  remove_parent_and_children_views(:electric_locomotives)
216
216
  rename_column(:raw_electric_locomotives, :electricity_consumption, :electric_consumption)
@@ -224,7 +224,7 @@ class SchemaTest < ActiveSupport::TestCase
224
224
  @connection.columns(:electric_locomotives).map{ |c| c.name }.sort
225
225
  end
226
226
 
227
- class ChangeColumnInChildTable < ActiveRecord::Migration
227
+ class ChangeColumnInChildTable < ActiveRecord::Migration[4.2]
228
228
  def self.up
229
229
  drop_view(:steam_locomotives)
230
230
  rename_column(:steam_locomotives_data, :coal_consumption, :fuel_consumption)
@@ -238,11 +238,7 @@ class SchemaTest < ActiveSupport::TestCase
238
238
  @connection.columns(:steam_locomotives).map(&:name).sort
239
239
  end
240
240
 
241
- def test_table_exists
242
- #TODO: test table_exists? monkey patch
243
- end
244
-
245
- class CreateChildInSchema < ActiveRecord::Migration
241
+ class CreateChildInSchema < ActiveRecord::Migration[4.2]
246
242
  def self.up
247
243
  execute "CREATE SCHEMA interrail"
248
244
  create_table 'interrail.locomotives' do |t|
@@ -268,7 +264,7 @@ class SchemaTest < ActiveSupport::TestCase
268
264
  @connection.columns('interrail.steam_locomotives').map(&:name).sort
269
265
  end
270
266
 
271
- class ChangeTablesInTwoInheritanceChains < ActiveRecord::Migration
267
+ class ChangeTablesInTwoInheritanceChains < ActiveRecord::Migration[4.2]
272
268
  def self.up
273
269
  add_column(:maglev_locomotives_data, :levitation_height, :integer)
274
270
  add_column(:bicycles_data, :wheel_size, :integer)
@@ -287,7 +283,7 @@ class SchemaTest < ActiveSupport::TestCase
287
283
  "Newly added column not present in view after rebuild for 2. hierarchy"
288
284
  end
289
285
 
290
- class UseExistingTable < ActiveRecord::Migration
286
+ class UseExistingTable < ActiveRecord::Migration[4.2]
291
287
  def self.up
292
288
  create_table :tbl_diesel_locomotives do |t|
293
289
  t.belongs_to :locomotives
@@ -305,7 +301,7 @@ class SchemaTest < ActiveSupport::TestCase
305
301
  assert @connection.columns(:diesel_locomotives).map(&:name).include?("num_cylinders")
306
302
  end
307
303
 
308
- class ReservedSQLWords < ActiveRecord::Migration
304
+ class ReservedSQLWords < ActiveRecord::Migration[4.2]
309
305
  def self.up
310
306
  create_child(:table, parent: :locomotives) do |t|
311
307
  t.integer :column
@@ -323,7 +319,7 @@ class SchemaTest < ActiveSupport::TestCase
323
319
  ReservedSQLWords.down
324
320
  end
325
321
 
326
- class ChildTableIsActuallyView < ActiveRecord::Migration
322
+ class ChildTableIsActuallyView < ActiveRecord::Migration[4.2]
327
323
  def self.up
328
324
  execute <<-SQL.squish
329
325
  CREATE VIEW punk_locomotives_data AS (
@@ -30,7 +30,7 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
30
30
  assert_equal electric_locomotive.name, @connection.query("SELECT name FROm all_locomotives WHERE id=#{electric_locomotive.id}").first.first
31
31
  end
32
32
 
33
- class AddColumnToParentTable < ActiveRecord::Migration
33
+ class AddColumnToParentTable < ActiveRecord::Migration[4.2]
34
34
  def self.up
35
35
  add_column(:raw_electric_locomotives, :number_of_engines, :integer)
36
36
  drop_view(:all_locomotives)
@@ -45,7 +45,7 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
45
45
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
46
46
  end
47
47
 
48
- class RemoveColumnInParentTable < ActiveRecord::Migration
48
+ class RemoveColumnInParentTable < ActiveRecord::Migration[4.2]
49
49
  def self.up
50
50
  drop_view(:all_locomotives)
51
51
  remove_parent_and_children_views(:locomotives)
@@ -61,7 +61,7 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
61
61
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
62
62
  end
63
63
 
64
- class RenameColumnInParentTable < ActiveRecord::Migration
64
+ class RenameColumnInParentTable < ActiveRecord::Migration[4.2]
65
65
  def self.up
66
66
  drop_view(:all_locomotives)
67
67
  remove_parent_and_children_views(:locomotives)
@@ -77,7 +77,7 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
77
77
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
78
78
  end
79
79
 
80
- class ChangeChildRelationView < ActiveRecord::Migration
80
+ class ChangeChildRelationView < ActiveRecord::Migration[4.2]
81
81
  def self.up
82
82
  drop_view(:all_locomotives)
83
83
  remove_parent_and_children_views(:electric_locomotives)
@@ -93,7 +93,7 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
93
93
  @connection.columns(:all_locomotives).map{ |c| c.name }.sort
94
94
  end
95
95
 
96
- class ConflictColumns < ActiveRecord::Migration
96
+ class ConflictColumns < ActiveRecord::Migration[4.2]
97
97
  def self.up
98
98
  drop_view(:all_locomotives)
99
99
  add_column(:raw_electric_locomotives, :number_of_engines, :integer)
@@ -111,7 +111,7 @@ class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
111
111
  assert_equal 'text', @connection.columns(:all_locomotives).detect{|c| c.name == "number_of_engines"}.sql_type
112
112
  end
113
113
 
114
- class ConflictColumnsWithValues < ActiveRecord::Migration
114
+ class ConflictColumnsWithValues < ActiveRecord::Migration[4.2]
115
115
  def self.up
116
116
  add_column(:raw_electric_locomotives, :number_of_engines, :integer)
117
117
  add_column(:steam_locomotives_data, :number_of_engines, :string)
@@ -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", "~> 4.2.8"
22
- s.add_dependency "pg", "~> 0.21"
21
+ s.add_dependency "activerecord", "~> 5.0.7"
22
+ s.add_dependency "pg"
23
23
 
24
24
  s.add_development_dependency 'bigdecimal', '1.3.5'
25
25
  s.add_development_dependency "bundler"
26
26
  s.add_development_dependency "minitest"
27
27
  s.add_development_dependency "minitest-reporters"
28
- s.add_development_dependency "rails", '= 4.2.11.1'
28
+ s.add_development_dependency "rails", '~> 5.0.7'
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.4.8
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sava Chankov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-12-17 00:00:00.000000000 Z
12
+ date: 2025-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 4.2.8
20
+ version: 5.0.7
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 4.2.8
27
+ version: 5.0.7
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: pg
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '0.21'
34
+ version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '0.21'
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bigdecimal
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -99,16 +99,16 @@ dependencies:
99
99
  name: rails
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '='
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: 4.2.11.1
104
+ version: 5.0.7
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '='
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: 4.2.11.1
111
+ version: 5.0.7
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: rake
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -187,7 +187,7 @@ files:
187
187
  - lib/generators/updateable_views_inheritance/install_generator.rb
188
188
  - lib/generators/updateable_views_inheritance/templates/create_updateable_views_inheritance.rb
189
189
  - lib/updateable_views_inheritance.rb
190
- - lib/updateable_views_inheritance/active_record.rb
190
+ - lib/updateable_views_inheritance/active_record_extensions.rb
191
191
  - lib/updateable_views_inheritance/postgresql_adapter.rb
192
192
  - lib/updateable_views_inheritance/version.rb
193
193
  - tasks/updateable_views_inheritance_tasks.rake
@@ -261,7 +261,7 @@ files:
261
261
  - test/install_generator_test.rb
262
262
  - test/instantiation_test.rb
263
263
  - test/migration_test.rb
264
- - test/pg_insert_returning_with_rules_spec.rb
264
+ - test/pg_insert_returning_with_rules_test.rb
265
265
  - test/schema_test.rb
266
266
  - test/single_table_inheritance_test.rb
267
267
  - test/test_helper.rb
@@ -360,7 +360,7 @@ test_files:
360
360
  - test/install_generator_test.rb
361
361
  - test/instantiation_test.rb
362
362
  - test/migration_test.rb
363
- - test/pg_insert_returning_with_rules_spec.rb
363
+ - test/pg_insert_returning_with_rules_test.rb
364
364
  - test/schema_test.rb
365
365
  - test/single_table_inheritance_test.rb
366
366
  - test/test_helper.rb
@@ -1,18 +0,0 @@
1
- module ActiveRecord #:nodoc:
2
- class Base #:nodoc:
3
- class << self
4
- attr_accessor :disable_inheritance_instantiation
5
-
6
- private
7
- def instantiate_with_updateable_views_inheritance_support(attributes, column_types = {})
8
- object = instantiate_without_updateable_views_inheritance_support(attributes, column_types = {})
9
- if object.class.name == self.name || self.disable_inheritance_instantiation
10
- object
11
- else
12
- object.class.find(attributes.with_indifferent_access[:id])
13
- end
14
- end
15
- alias_method_chain :instantiate, :updateable_views_inheritance_support
16
- end
17
- end
18
- end
@@ -1,58 +0,0 @@
1
- gem "pg", "0.18.2"
2
-
3
- require "pg"
4
- require "rspec"
5
-
6
- describe "Insert returning on view with rules and default value" do
7
- before(:each) do
8
- @conn = PG.connect(dbname: 'updateable_views_inheritance_test')
9
- @conn.exec(%q{ SET client_min_messages TO 'ERROR' })
10
-
11
- @conn.exec(%q{ CREATE TABLE parent ( id SERIAL PRIMARY KEY,
12
- name TEXT) })
13
- @conn.exec(%q{ CREATE TABLE child ( parent_id INTEGER PRIMARY KEY REFERENCES parent(id),
14
- surname TEXT) })
15
-
16
- @conn.exec(%q{ CREATE VIEW v AS (SELECT id, name, surname FROM parent JOIN child ON parent.id=child.parent_id) })
17
- @conn.exec(%q{ ALTER VIEW v ALTER id SET DEFAULT nextval('parent_id_seq'::regclass) })
18
- #
19
- # The old way that didn't return anything when binds are empty
20
- #
21
- # @conn.exec(%q{ CREATE RULE v_on_insert AS ON INSERT TO v DO INSTEAD
22
- # (
23
- # SELECT setval('parent_id_seq', NEW.id);
24
- # INSERT INTO parent (id, name)
25
- # VALUES( currval('parent_id_seq'), NEW.name ) RETURNING id, name, NULL::text;
26
- # INSERT INTO child (parent_id, surname)
27
- # VALUES( currval('parent_id_seq'), NEW.surname );
28
- #
29
- # )
30
- # })
31
- @conn.exec(%q{ CREATE RULE v_on_insert AS ON INSERT TO v DO INSTEAD
32
- (
33
- INSERT INTO parent (id, name)
34
- VALUES( DEFAULT, NEW.name );
35
- INSERT INTO child (parent_id, surname)
36
- VALUES( currval('parent_id_seq'), NEW.surname ) RETURNING parent_id, NULL::text, NULL::te;
37
- )
38
- })
39
-
40
- @sql = %q{ INSERT INTO v (name, surname) VALUES ('parent', 'child') RETURNING id}
41
- end
42
-
43
- after(:each) do
44
- @conn.exec(%q{ DROP VIEW IF EXISTS v })
45
- @conn.exec(%q{ DROP TABLE IF EXISTS parent CASCADE})
46
- @conn.exec(%q{ DROP TABLE IF EXISTS child CASCADE})
47
- end
48
-
49
- it 'async exec with empty binds' do
50
- res = @conn.async_exec(@sql, [])
51
- expect(res.values).to eq([["1"]])
52
- end
53
-
54
- it 'async exec with no binds' do
55
- res = @conn.async_exec(@sql)
56
- expect(res.values).to eq([["1"]])
57
- end
58
- end