updateable_views_inheritance 1.5.1 → 1.8.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -5
- data/lib/updateable_views_inheritance/active_record_extensions.rb +1 -1
- data/lib/updateable_views_inheritance/postgresql_adapter.rb +18 -8
- data/lib/updateable_views_inheritance/version.rb +1 -1
- data/test/content_test.rb +3 -7
- data/test/deep_hierarchy_test.rb +4 -4
- data/test/dummy/config/application.rb +1 -6
- data/test/instantiation_test.rb +1 -2
- data/test/migration_test.rb +4 -4
- data/test/schema_test.rb +2 -2
- data/test/single_table_inheritance_test.rb +1 -1
- data/test/test_helper.rb +0 -2
- data/updateable_views_inheritance.gemspec +2 -3
- metadata +17 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9822cbe06d8820cf3d4dcf96e4bf9c527f130b16d83edc1335858e250e392b55
|
|
4
|
+
data.tar.gz: 32755fb6541e0acb5ee155cb5ceb94021a9c838a28b73c033cc0b8e5c8a60110
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6fbed4ffbc44f4841eeb0613fe64196f9e38b7e6f01c94aaa3a786d70401b3685a12c7a078d7a2bf26e58e6c615511619abc8b8d4195cf3f0bfddeaafc80ce24
|
|
7
|
+
data.tar.gz: b954e8fc8706faa9e081710292992e1cd60fd3003aa4e7b500f9c52ee71e4c5c5aab944277ab7d48b94f1279f9797dabef61c73cb8b7781dae2a4a2b5178892d
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
|
@@ -9,7 +9,7 @@ module UpdateableViewsInheritance# :nodoc:
|
|
|
9
9
|
if object.class.name == self.name || self.disable_inheritance_instantiation
|
|
10
10
|
object
|
|
11
11
|
else
|
|
12
|
-
object.class.find(attributes.with_indifferent_access[:id])
|
|
12
|
+
object.class.find(attributes.to_h.with_indifferent_access[:id])
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -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
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
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::
|
|
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 = [
|
|
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.
|
|
62
|
+
steam_locomotive.update(name: 'Rocket')
|
|
67
63
|
steam_locomotive.reload
|
|
68
64
|
assert_equal 'Rocket', steam_locomotive.name
|
|
69
65
|
end
|
data/test/deep_hierarchy_test.rb
CHANGED
|
@@ -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::
|
|
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
|
|
10
|
-
ActiveRecord::FixtureSet.create_fixtures(
|
|
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,7 +41,7 @@ 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,
|
|
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]
|
|
@@ -7,6 +7,7 @@ require "updateable_views_inheritance"
|
|
|
7
7
|
|
|
8
8
|
module Dummy
|
|
9
9
|
class Application < Rails::Application
|
|
10
|
+
config.load_defaults 8.1
|
|
10
11
|
# Settings in config/environments/* take precedence over those specified here.
|
|
11
12
|
# Application configuration should go into files in config/initializers
|
|
12
13
|
# -- all .rb files in that directory are automatically loaded.
|
|
@@ -42,12 +43,6 @@ module Dummy
|
|
|
42
43
|
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
|
43
44
|
# like if you have constraints or database-specific column types
|
|
44
45
|
# 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
46
|
end
|
|
52
47
|
end
|
|
53
48
|
|
data/test/instantiation_test.rb
CHANGED
|
@@ -2,8 +2,7 @@ require_relative 'test_helper'
|
|
|
2
2
|
|
|
3
3
|
class InstantiationTest < ActiveSupport::TestCase
|
|
4
4
|
def setup
|
|
5
|
-
ActiveRecord::
|
|
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|
|
data/test/migration_test.rb
CHANGED
|
@@ -7,20 +7,20 @@ class UpdateableViewsInheritanceMigrationTest < ActiveSupport::TestCase
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def test_create_child_default
|
|
10
|
-
ActiveRecord::
|
|
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::
|
|
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::
|
|
23
|
-
ActiveRecord::
|
|
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::
|
|
5
|
+
ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(5)
|
|
6
6
|
@connection = ActiveRecord::Base.connection
|
|
7
7
|
end
|
|
8
8
|
|
|
@@ -273,7 +273,7 @@ class SchemaTest < ActiveSupport::TestCase
|
|
|
273
273
|
end
|
|
274
274
|
|
|
275
275
|
def test_rebuild_all_parent_and_children_views
|
|
276
|
-
ActiveRecord::
|
|
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
278
|
ChangeTablesInTwoInheritanceChains.new.up
|
|
279
279
|
|
|
@@ -2,7 +2,7 @@ require_relative 'test_helper'
|
|
|
2
2
|
|
|
3
3
|
class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
|
|
4
4
|
def setup
|
|
5
|
-
ActiveRecord::
|
|
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)
|
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,13 @@ 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",
|
|
21
|
+
s.add_dependency "activerecord", '>= 8', '< 9'
|
|
22
22
|
s.add_dependency "pg"
|
|
23
23
|
|
|
24
|
-
s.add_development_dependency 'bigdecimal', '1.3.5'
|
|
25
24
|
s.add_development_dependency "bundler"
|
|
26
25
|
s.add_development_dependency "minitest"
|
|
27
26
|
s.add_development_dependency "minitest-reporters"
|
|
28
|
-
s.add_development_dependency "rails"
|
|
27
|
+
s.add_development_dependency "rails"
|
|
29
28
|
s.add_development_dependency "rake"
|
|
30
29
|
s.add_development_dependency "simplecov"
|
|
31
30
|
s.add_development_dependency "simplecov_json_formatter"
|
metadata
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: updateable_views_inheritance
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sava Chankov
|
|
8
8
|
- Denitsa Belogusheva
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: activerecord
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
16
|
requirements:
|
|
18
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '8'
|
|
20
|
+
- - "<"
|
|
19
21
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
22
|
+
version: '9'
|
|
21
23
|
type: :runtime
|
|
22
24
|
prerelease: false
|
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
26
|
requirements:
|
|
25
|
-
- - "
|
|
27
|
+
- - ">="
|
|
26
28
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
29
|
+
version: '8'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '9'
|
|
28
33
|
- !ruby/object:Gem::Dependency
|
|
29
34
|
name: pg
|
|
30
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -39,20 +44,6 @@ dependencies:
|
|
|
39
44
|
- - ">="
|
|
40
45
|
- !ruby/object:Gem::Version
|
|
41
46
|
version: '0'
|
|
42
|
-
- !ruby/object:Gem::Dependency
|
|
43
|
-
name: bigdecimal
|
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
|
45
|
-
requirements:
|
|
46
|
-
- - '='
|
|
47
|
-
- !ruby/object:Gem::Version
|
|
48
|
-
version: 1.3.5
|
|
49
|
-
type: :development
|
|
50
|
-
prerelease: false
|
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
-
requirements:
|
|
53
|
-
- - '='
|
|
54
|
-
- !ruby/object:Gem::Version
|
|
55
|
-
version: 1.3.5
|
|
56
47
|
- !ruby/object:Gem::Dependency
|
|
57
48
|
name: bundler
|
|
58
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -99,16 +90,16 @@ dependencies:
|
|
|
99
90
|
name: rails
|
|
100
91
|
requirement: !ruby/object:Gem::Requirement
|
|
101
92
|
requirements:
|
|
102
|
-
- - "
|
|
93
|
+
- - ">="
|
|
103
94
|
- !ruby/object:Gem::Version
|
|
104
|
-
version:
|
|
95
|
+
version: '0'
|
|
105
96
|
type: :development
|
|
106
97
|
prerelease: false
|
|
107
98
|
version_requirements: !ruby/object:Gem::Requirement
|
|
108
99
|
requirements:
|
|
109
|
-
- - "
|
|
100
|
+
- - ">="
|
|
110
101
|
- !ruby/object:Gem::Version
|
|
111
|
-
version:
|
|
102
|
+
version: '0'
|
|
112
103
|
- !ruby/object:Gem::Dependency
|
|
113
104
|
name: rake
|
|
114
105
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -270,7 +261,6 @@ homepage: http://github.com/tutuf/updateable_views_inheritance
|
|
|
270
261
|
licenses:
|
|
271
262
|
- MIT
|
|
272
263
|
metadata: {}
|
|
273
|
-
post_install_message:
|
|
274
264
|
rdoc_options: []
|
|
275
265
|
require_paths:
|
|
276
266
|
- lib
|
|
@@ -285,8 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
285
275
|
- !ruby/object:Gem::Version
|
|
286
276
|
version: '0'
|
|
287
277
|
requirements: []
|
|
288
|
-
rubygems_version: 3.
|
|
289
|
-
signing_key:
|
|
278
|
+
rubygems_version: 3.6.9
|
|
290
279
|
specification_version: 4
|
|
291
280
|
summary: Class table inheritance for ActiveRecord
|
|
292
281
|
test_files:
|