updateable_views_inheritance 1.4.7 → 1.4.8

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: 661b8ded59885a6e482cac9d0dfec5f9e1ab10050e3944b5f176e543958f8a33
4
- data.tar.gz: fa8e6f63a74a28f9a09d1574ec6e3ae788df2ebdf3eead5789ef691c40337aed
3
+ metadata.gz: a7b78d1ecf36dad960f1b6ffccb8a640cbb9e1f06a8a8c1719f25f022e040aff
4
+ data.tar.gz: 2a3f41c5bb02ca8b2907c1a563cac2c4ed06429f712fed5f3b5f6ffcd988f34c
5
5
  SHA512:
6
- metadata.gz: 1aec9cfeeb1aab4761e2efffc73219d7d9db7b605a8575fa470b5491783882415e51afdb8d7d48536242f0df4d2a448e8e3777c00ef9a65ec089001fb3e5a9e3
7
- data.tar.gz: 46fb1b1a91344c01d55a48f47ef96e02f0d058a7f7781462c22cda18fa7d2a6eaa90f1e8cb94e7c1a03523c6d83d2aa500b43d4a83d011db0549bc65cfa4d9b6
6
+ metadata.gz: 33bbf8b1caf17c212f5f8f2712476f212cea3fd09c5d8ada27c6ee235bd1e8e65792afff98606daeb2c462756f21331f76597bc2f27dae17ecbcc90cfaa41ecc
7
+ data.tar.gz: b26957b4721cffcae777c4e9e7e7280f2a5ab2d1a008c00f551bb6c0db39fe7c6f19616570efde7d8cc8e18802d36814ce1fca80c6add8401571bc73a6e880bb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.4.8 (17 December 2024)
2
+ Bugfixes:
3
+ - Fix pk_and_sequence_for to be interoperable with other AR methods
4
+
1
5
  ## 1.4.7 (06 November 2024)
2
6
 
3
7
  Bugfixes:
@@ -126,13 +126,23 @@ module ActiveRecord #:nodoc:
126
126
  AND cons.contype = 'p'
127
127
  AND attr.attnum = ANY(cons.conkey)
128
128
  SQL
129
- if result.blank? #result.empty?
129
+
130
+ if result.nil? or result.empty?
130
131
  parent = parent_table(relation)
131
132
  pk_and_sequence_for(parent) if parent
132
133
  else
133
- # log(result[0], "PK for #{relation}") {}
134
- [result[0], query("SELECT pg_get_serial_sequence('#{relation}', '#{result[0]}') ")[0][0]]
134
+ pk = result[0]
135
+ sequence = query("SELECT pg_get_serial_sequence('#{relation}', '#{result[0]}') ")[0][0]
136
+ if sequence
137
+ # ActiveRecord expects PostgreSQL::Name object as sequence, not a string
138
+ sequence_with_schema = Utils.extract_schema_qualified_name(sequence)
139
+ [pk, sequence_with_schema]
140
+ else
141
+ [pk, nil]
142
+ end
135
143
  end
144
+ rescue
145
+ nil
136
146
  end
137
147
 
138
148
  # Drops a view from the database.
@@ -1,3 +1,3 @@
1
1
  module UpdateableViewsInheritance
2
- VERSION = "1.4.7"
2
+ VERSION = "1.4.8"
3
3
  end
data/test/schema_test.rb CHANGED
@@ -7,7 +7,48 @@ class SchemaTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  def test_pk_and_sequence_for
10
- assert_equal ['id', 'public.locomotives_id_seq'], @connection.pk_and_sequence_for(:maglev_locomotives), "Could not get pk and sequence for child aggregate view"
10
+ pk, seq = @connection.pk_and_sequence_for(:maglev_locomotives)
11
+ assert_equal 'id', pk
12
+ assert_equal 'public.locomotives_id_seq', seq.to_s
13
+ end
14
+
15
+ class CreateChildInSchemaWithPublicParent < ActiveRecord::Migration
16
+ def self.up
17
+ execute "CREATE SCHEMA interrail"
18
+ create_child('interrail.steam_locomotives', parent: 'locomotives') do |t|
19
+ t.decimal :interrail_water_consumption, precision: 6, scale: 2
20
+ t.decimal :interrail_coal_consumption, precision: 6, scale: 2
21
+ end
22
+ end
23
+ end
24
+
25
+ def test_pk_and_sequence_for_child_and_parent_in_different_schemas
26
+ CreateChildInSchemaWithPublicParent.up
27
+ pk, seq = @connection.pk_and_sequence_for('interrail.steam_locomotives')
28
+ assert_equal 'id', pk
29
+ assert_equal 'public.locomotives_id_seq', seq.to_s
30
+ end
31
+
32
+ class CreateChildInSchemaWithParentInSchema < ActiveRecord::Migration
33
+ def self.up
34
+ execute "CREATE SCHEMA interrail"
35
+ create_table 'interrail.locomotives' do |t|
36
+ t.column :interrail_name, :string
37
+ t.column :interrail_max_speed, :integer
38
+ t.column :type, :string
39
+ end
40
+ create_child('interrail.steam_locomotives', parent: 'interrail.locomotives') do |t|
41
+ t.decimal :interrail_water_consumption, precision: 6, scale: 2
42
+ t.decimal :interrail_coal_consumption, precision: 6, scale: 2
43
+ end
44
+ end
45
+ end
46
+
47
+ def test_pk_and_sequence_for_child_and_parent_in_same_nonpublic_schema
48
+ CreateChildInSchemaWithParentInSchema.up
49
+ pk, seq = @connection.pk_and_sequence_for('interrail.steam_locomotives')
50
+ assert_equal 'id', pk
51
+ assert_equal 'interrail.locomotives_id_seq', seq.to_s
11
52
  end
12
53
 
13
54
  def test_primary_key
data/test/test_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
+ require 'warning'
5
+ Warning.ignore(/.*in Ruby 3.*/)
6
+
4
7
  # test coverage
5
8
  require 'simplecov'
6
9
  require 'simplecov_json_formatter'
@@ -29,5 +29,6 @@ Gem::Specification.new do |s|
29
29
  s.add_development_dependency "rake"
30
30
  s.add_development_dependency "simplecov"
31
31
  s.add_development_dependency "simplecov_json_formatter"
32
- s.add_development_dependency "solargraph"
32
+ s.add_development_dependency "warning"
33
+
33
34
  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.4.7
4
+ version: 1.4.8
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-11-06 00:00:00.000000000 Z
12
+ date: 2024-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -152,7 +152,7 @@ dependencies:
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
- name: solargraph
155
+ name: warning
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="