torque-postgresql 1.1.3 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/torque/postgresql/associations/association.rb +4 -0
- data/lib/torque/postgresql/associations/belongs_to_many_association.rb +14 -10
- data/lib/torque/postgresql/associations/preloader.rb +9 -1
- data/lib/torque/postgresql/associations/preloader/association.rb +1 -0
- data/lib/torque/postgresql/autosave_association.rb +4 -4
- data/lib/torque/postgresql/auxiliary_statement.rb +4 -0
- data/lib/torque/postgresql/config.rb +2 -0
- data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +38 -4
- data/lib/torque/postgresql/schema_dumper.rb +29 -16
- data/lib/torque/postgresql/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ba522771fa6306842ed61b6eb36b3de898398d186f9aa7a3ced33d5f2974708a
|
4
|
+
data.tar.gz: ac2f4da994afe5fbbe49bd8914bd01ee2404a18dbedb9e202c56012a24336aa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 715eabf972af8e33997af64888028c7c15625e124123fb890693ee8a48782f656c0fe8e944f9f49a7e6440babf53aacb5216e76b4d0a7b697e6825a964dd8ad6
|
7
|
+
data.tar.gz: 806ec5069889bd67ee3672035de94a0a6274919ff6aa45b78daf14185c78fb4682cc643531c7635dbc6e474c70ab6c217d0e0b6fe1d384ea00eda70e35f966b8
|
@@ -28,11 +28,11 @@ module Torque
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def ids_reader
|
31
|
-
owner[
|
31
|
+
owner[source_attr]
|
32
32
|
end
|
33
33
|
|
34
34
|
def ids_writer(new_ids)
|
35
|
-
column =
|
35
|
+
column = source_attr
|
36
36
|
owner.update_column(column, owner[column] = new_ids.presence)
|
37
37
|
@association_scope = nil
|
38
38
|
end
|
@@ -40,8 +40,8 @@ module Torque
|
|
40
40
|
def insert_record(record, *)
|
41
41
|
super
|
42
42
|
|
43
|
-
attribute = (ids_reader || owner[
|
44
|
-
attribute.push(record[
|
43
|
+
attribute = (ids_reader || owner[source_attr] = [])
|
44
|
+
attribute.push(record[klass_attr])
|
45
45
|
record
|
46
46
|
end
|
47
47
|
|
@@ -50,8 +50,8 @@ module Torque
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def include?(record)
|
53
|
-
list = owner[
|
54
|
-
ids_reader && ids_reader.include?(record[
|
53
|
+
list = owner[source_attr]
|
54
|
+
ids_reader && ids_reader.include?(record[klass_attr])
|
55
55
|
end
|
56
56
|
|
57
57
|
private
|
@@ -65,7 +65,7 @@ module Torque
|
|
65
65
|
# When the idea is to nulligy the association, then just set the owner
|
66
66
|
# +primary_key+ as empty
|
67
67
|
def delete_count(method, scope, ids = nil)
|
68
|
-
ids ||= scope.pluck(
|
68
|
+
ids ||= scope.pluck(klass_attr)
|
69
69
|
scope.delete_all if method == :delete_all
|
70
70
|
remove_stash_records(ids)
|
71
71
|
end
|
@@ -76,13 +76,13 @@ module Torque
|
|
76
76
|
|
77
77
|
# Deletes the records according to the <tt>:dependent</tt> option.
|
78
78
|
def delete_records(records, method)
|
79
|
-
ids = Array.wrap(records).each_with_object(
|
79
|
+
ids = Array.wrap(records).each_with_object(klass_attr).map(&:[])
|
80
80
|
|
81
81
|
if method == :destroy
|
82
82
|
records.each(&:destroy!)
|
83
83
|
remove_stash_records(ids)
|
84
84
|
else
|
85
|
-
scope = self.scope.where(
|
85
|
+
scope = self.scope.where(klass_attr => records)
|
86
86
|
delete_count(method, scope, ids)
|
87
87
|
end
|
88
88
|
end
|
@@ -98,10 +98,14 @@ module Torque
|
|
98
98
|
ids_writer(ids_reader - Array.wrap(ids))
|
99
99
|
end
|
100
100
|
|
101
|
-
def
|
101
|
+
def source_attr
|
102
102
|
reflection.foreign_key
|
103
103
|
end
|
104
104
|
|
105
|
+
def klass_attr
|
106
|
+
reflection.active_record_primary_key
|
107
|
+
end
|
108
|
+
|
105
109
|
def difference(a, b)
|
106
110
|
a - b
|
107
111
|
end
|
@@ -5,7 +5,15 @@ unless Torque::PostgreSQL::AR521
|
|
5
5
|
module PostgreSQL
|
6
6
|
module Associations
|
7
7
|
module Preloader
|
8
|
-
BelongsToMany
|
8
|
+
class BelongsToMany < ::ActiveRecord::Associations::Preloader::HasMany
|
9
|
+
def association_key_name
|
10
|
+
reflection.active_record_primary_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def owner_key_name
|
14
|
+
reflection.foreign_key
|
15
|
+
end
|
16
|
+
end
|
9
17
|
|
10
18
|
def preloader_for(reflection, owners, *)
|
11
19
|
return AlreadyLoaded \
|
@@ -25,11 +25,11 @@ module Torque
|
|
25
25
|
association = association_instance_get(reflection.name)
|
26
26
|
return unless association
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
klass_attr = reflection.active_record_primary_key
|
29
|
+
source_attr = reflection.foreign_key
|
30
30
|
|
31
|
-
records = association.target.each_with_object(
|
32
|
-
write_attribute(
|
31
|
+
records = association.target.each_with_object(klass_attr)
|
32
|
+
write_attribute(source_attr, records.map(&:read_attribute).compact)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -125,6 +125,10 @@ module Torque
|
|
125
125
|
|
126
126
|
# Build the statement on the given arel and return the WITH statement
|
127
127
|
def build(base)
|
128
|
+
@bound_attributes.clear
|
129
|
+
@join_sources.clear
|
130
|
+
|
131
|
+
# Prepare all the data for the statement
|
128
132
|
prepare(base)
|
129
133
|
|
130
134
|
# Add the join condition to the list
|
@@ -3,6 +3,8 @@ module Torque
|
|
3
3
|
include ActiveSupport::Configurable
|
4
4
|
|
5
5
|
# Stores a version check for compatibility purposes
|
6
|
+
AR510 = (ActiveRecord.gem_version >= Gem::Version.new('5.1.0'))
|
7
|
+
AR520 = (ActiveRecord.gem_version >= Gem::Version.new('5.2.0'))
|
6
8
|
AR521 = (ActiveRecord.gem_version >= Gem::Version.new('5.2.1'))
|
7
9
|
AR523 = (ActiveRecord.gem_version >= Gem::Version.new('5.2.3'))
|
8
10
|
|
@@ -10,6 +10,10 @@ module Torque
|
|
10
10
|
true
|
11
11
|
end
|
12
12
|
|
13
|
+
def belongs_to?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
13
17
|
def collection?
|
14
18
|
true
|
15
19
|
end
|
@@ -19,7 +23,7 @@ module Torque
|
|
19
23
|
end
|
20
24
|
|
21
25
|
def foreign_key
|
22
|
-
@foreign_key ||= options[:
|
26
|
+
@foreign_key ||= options[:foreign_key] || derive_foreign_key.freeze
|
23
27
|
end
|
24
28
|
|
25
29
|
def association_foreign_key
|
@@ -27,16 +31,46 @@ module Torque
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def active_record_primary_key
|
30
|
-
@active_record_primary_key ||= options[:
|
34
|
+
@active_record_primary_key ||= options[:primary_key] || derive_primary_key
|
35
|
+
end
|
36
|
+
|
37
|
+
unless PostgreSQL::AR510
|
38
|
+
def join_keys(*)
|
39
|
+
JoinKeys.new(join_pk, join_fk)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if PostgreSQL::AR520
|
44
|
+
def join_primary_key(*)
|
45
|
+
active_record_primary_key
|
46
|
+
end
|
47
|
+
|
48
|
+
def join_foreign_key
|
49
|
+
foreign_key
|
50
|
+
end
|
51
|
+
else
|
52
|
+
def join_id_for(owner)
|
53
|
+
owner[foreign_key]
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
57
|
private
|
34
58
|
|
35
|
-
|
36
|
-
|
59
|
+
unless PostgreSQL::AR520
|
60
|
+
def join_pk(*)
|
61
|
+
active_record_primary_key
|
62
|
+
end
|
63
|
+
|
64
|
+
def join_fk
|
65
|
+
foreign_key
|
66
|
+
end
|
37
67
|
end
|
38
68
|
|
39
69
|
def derive_primary_key
|
70
|
+
klass.primary_key
|
71
|
+
end
|
72
|
+
|
73
|
+
def derive_foreign_key
|
40
74
|
"#{name.to_s.singularize}_ids"
|
41
75
|
end
|
42
76
|
end
|
@@ -31,21 +31,21 @@ module Torque
|
|
31
31
|
if inherited_tables.present?
|
32
32
|
stream.puts " # These are tables that has inheritance"
|
33
33
|
inherited_tables.each do |table_name, inherits|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
34
|
+
next if ignored?(table_name)
|
35
|
+
|
36
|
+
sub_stream = StringIO.new
|
37
|
+
table(table_name, sub_stream)
|
38
|
+
|
39
|
+
# Add the inherits setting
|
40
|
+
sub_stream.rewind
|
41
|
+
inherits.map!(&:to_sym)
|
42
|
+
inherits = inherits.first if inherits.size === 1
|
43
|
+
inherits = ", inherits: #{inherits.inspect} do |t|"
|
44
|
+
table_dump = sub_stream.read.gsub(/ do \|t\|$/, inherits)
|
45
|
+
|
46
|
+
# Ensure bodyless definitions
|
47
|
+
table_dump.gsub!(/do \|t\|\n end/, '')
|
48
|
+
stream.print table_dump
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -55,6 +55,8 @@ module Torque
|
|
55
55
|
foreign_keys(tbl, stream) unless ignored?(tbl)
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
table_extensions(stream)
|
58
60
|
end
|
59
61
|
|
60
62
|
# Dump user defined types like enum
|
@@ -63,7 +65,7 @@ module Torque
|
|
63
65
|
return unless types.any?
|
64
66
|
|
65
67
|
stream.puts " # These are user-defined types used on this database"
|
66
|
-
types.each { |name, type| send(type.to_sym, name, stream) }
|
68
|
+
types.sort_by(&:first).each { |name, type| send(type.to_sym, name, stream) }
|
67
69
|
stream.puts
|
68
70
|
rescue => e
|
69
71
|
stream.puts "# Could not dump user-defined types because of following #{e.class}"
|
@@ -77,6 +79,17 @@ module Torque
|
|
77
79
|
stream.puts " create_enum \"#{name}\", [#{values.join(', ')}], force: :cascade"
|
78
80
|
end
|
79
81
|
|
82
|
+
# Add compatibility to other gems that uses +tables+ as base function
|
83
|
+
def table_extensions(stream)
|
84
|
+
# Scenic integration
|
85
|
+
views(stream) if defined?(::Scenic)
|
86
|
+
|
87
|
+
# FX integration
|
88
|
+
functions(stream) if defined?(::Fx::SchemaDumper::Function)
|
89
|
+
aggregates(stream) if defined?(::Fx::SchemaDumper::Aggregate)
|
90
|
+
triggers(stream) if defined?(::Fx::SchemaDumper::Trigger)
|
91
|
+
end
|
92
|
+
|
80
93
|
end
|
81
94
|
|
82
95
|
if Torque::PostgreSQL::AR521
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torque-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -260,8 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
260
260
|
- !ruby/object:Gem::Version
|
261
261
|
version: 1.8.11
|
262
262
|
requirements: []
|
263
|
-
|
264
|
-
rubygems_version: 2.6.14
|
263
|
+
rubygems_version: 3.2.14
|
265
264
|
signing_key:
|
266
265
|
specification_version: 4
|
267
266
|
summary: ActiveRecord extension to access PostgreSQL advanced resources
|