torque-postgresql 2.4.0 → 2.4.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9185b34c8897975b296b43fe5585a1a62d61d02c30d204f5963bfb2b87cb74ca
|
4
|
+
data.tar.gz: ca9ec1fc2558f8d24296ac287b592e3d9b10ea41015f8c29b2c8f8a01536606c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2c30b52f8573c6745735d3625b64f9bebd052e47b51b7ceec3a297977cebcef945d0428dc55830932e3ee6c7cd7b78c8309e090c16b7b66ed7d9559ab753a20
|
7
|
+
data.tar.gz: cbd8559012bfb7cd112e67f52e9e6fad96528bfb66bdc6e17244e8771f033cde0530a5fb51679ce264eaa7c37cc4b4db36807a93eff53cab45bab0038c20fe11
|
@@ -185,21 +185,20 @@ module Torque
|
|
185
185
|
|
186
186
|
# Get the list of columns, and their definition, but only from the
|
187
187
|
# actual table, does not include columns that comes from inherited table
|
188
|
-
def column_definitions(table_name)
|
189
|
-
|
188
|
+
def column_definitions(table_name)
|
189
|
+
local = 'AND a.attislocal' if @_dump_mode
|
190
|
+
|
190
191
|
query(<<-SQL, 'SCHEMA')
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
#{local_condition}
|
202
|
-
ORDER BY a.attnum
|
192
|
+
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
|
193
|
+
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
|
194
|
+
c.collname, col_description(a.attrelid, a.attnum) AS comment
|
195
|
+
FROM pg_attribute a
|
196
|
+
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
|
197
|
+
LEFT JOIN pg_type t ON a.atttypid = t.oid
|
198
|
+
LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
|
199
|
+
WHERE a.attrelid = #{quote(quote_table_name(table_name))}::regclass
|
200
|
+
AND a.attnum > 0 AND NOT a.attisdropped #{local}
|
201
|
+
ORDER BY a.attnum
|
203
202
|
SQL
|
204
203
|
end
|
205
204
|
|
@@ -33,9 +33,9 @@ module Torque
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# Renames a type.
|
36
|
-
def rename_type(type_name, new_name)
|
36
|
+
def rename_type(type_name, new_name, options = {})
|
37
37
|
execute <<-SQL.squish
|
38
|
-
ALTER TYPE #{quote_type_name(type_name)}
|
38
|
+
ALTER TYPE #{quote_type_name(type_name, options[:schema])}
|
39
39
|
RENAME TO #{Quoting::Name.new(nil, new_name.to_s).quoted}
|
40
40
|
SQL
|
41
41
|
end
|
@@ -102,6 +102,18 @@ module Torque
|
|
102
102
|
super table_name, **options, &block
|
103
103
|
end
|
104
104
|
|
105
|
+
# Simply add the schema to the table name when changing a table
|
106
|
+
def change_table(table_name, **options)
|
107
|
+
table_name = "#{options[:schema]}.#{table_name}" if options[:schema].present?
|
108
|
+
super table_name, **options
|
109
|
+
end
|
110
|
+
|
111
|
+
# Simply add the schema to the table name when dropping a table
|
112
|
+
def drop_table(table_name, **options)
|
113
|
+
table_name = "#{options[:schema]}.#{table_name}" if options[:schema].present?
|
114
|
+
super table_name, **options
|
115
|
+
end
|
116
|
+
|
105
117
|
# Add the schema option when extracting table options
|
106
118
|
def table_options(table_name)
|
107
119
|
parts = table_name.split('.').reverse
|
@@ -127,6 +139,11 @@ module Torque
|
|
127
139
|
|
128
140
|
private
|
129
141
|
|
142
|
+
# Remove the schema from the sequence name
|
143
|
+
def sequence_name_from_parts(table_name, column_name, suffix)
|
144
|
+
super(table_name.split('.').last, column_name, suffix)
|
145
|
+
end
|
146
|
+
|
130
147
|
def quote_enum_values(name, values, options)
|
131
148
|
prefix = options[:prefix]
|
132
149
|
prefix = name if prefix === true
|
@@ -12,8 +12,8 @@ module Torque
|
|
12
12
|
return @schema if defined?(@schema)
|
13
13
|
|
14
14
|
@schema = ([@klass] + @klass.module_parents[0..-2]).find do |klass|
|
15
|
-
next unless klass.respond_to?(:schema)
|
16
|
-
break
|
15
|
+
next unless klass.respond_to?(:schema) && !(value = klass.schema).nil?
|
16
|
+
break value
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/spec/tests/schema_spec.rb
CHANGED
@@ -40,6 +40,26 @@ RSpec.describe 'Schema' do
|
|
40
40
|
connection.schemas_whitelist.push('legacy')
|
41
41
|
expect(connection.schema_exists?(:legacy)).to be_truthy
|
42
42
|
end
|
43
|
+
|
44
|
+
context 'reverting' do
|
45
|
+
let(:migration) { ActiveRecord::Migration::Current.new('Testing') }
|
46
|
+
|
47
|
+
before { connection.create_schema(:legacy) }
|
48
|
+
|
49
|
+
it 'reverts the creation of a schema' do
|
50
|
+
expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy
|
51
|
+
migration.revert { migration.connection.create_schema(:legacy) }
|
52
|
+
expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'reverts the creation of a table' do
|
56
|
+
connection.create_table(:users, schema: :legacy) { |t| t.string(:name) }
|
57
|
+
|
58
|
+
expect(connection.table_exists?('legacy.users')).to be_truthy
|
59
|
+
migration.revert { migration.connection.create_table(:users, schema: :legacy) }
|
60
|
+
expect(connection.table_exists?('legacy.users')).to be_falsey
|
61
|
+
end
|
62
|
+
end
|
43
63
|
end
|
44
64
|
|
45
65
|
context 'on schema' do
|
@@ -73,12 +93,24 @@ RSpec.describe 'Schema' do
|
|
73
93
|
expect(dump_result).to match /create_table \"users\",.*schema: +"internal"/
|
74
94
|
end
|
75
95
|
end
|
96
|
+
|
97
|
+
it 'does not affect serial ids' do
|
98
|
+
connection.create_table(:primary_keys, id: :serial) do |t|
|
99
|
+
t.string :title
|
100
|
+
end
|
101
|
+
|
102
|
+
parts = '"primary_keys", id: :serial, force: :cascade'
|
103
|
+
expect(dump_result).to match(/create_table #{parts} do /)
|
104
|
+
end
|
76
105
|
end
|
77
106
|
|
78
107
|
context 'on relation' do
|
79
108
|
let(:model) { Internal::User }
|
109
|
+
let(:table_name) { Torque::PostgreSQL::TableName.new(model, 'users') }
|
80
110
|
|
81
111
|
it 'adds the schema to the query' do
|
112
|
+
model.reset_table_name
|
113
|
+
expect(table_name.to_s).to eq('internal.users')
|
82
114
|
expect(model.all.to_sql).to match(/FROM "internal"."users"/)
|
83
115
|
end
|
84
116
|
|
@@ -86,7 +118,17 @@ RSpec.describe 'Schema' do
|
|
86
118
|
allow(Internal).to receive(:schema).and_return('internal')
|
87
119
|
allow(model).to receive(:schema).and_return(nil)
|
88
120
|
|
121
|
+
model.reset_table_name
|
122
|
+
expect(table_name.to_s).to eq('internal.users')
|
89
123
|
expect(model.all.to_sql).to match(/FROM "internal"."users"/)
|
90
124
|
end
|
125
|
+
|
126
|
+
it 'does not change anything if the model has not configured a schema' do
|
127
|
+
allow(model).to receive(:schema).and_return(nil)
|
128
|
+
|
129
|
+
model.reset_table_name
|
130
|
+
expect(table_name.to_s).to eq('users')
|
131
|
+
expect(model.all.to_sql).to match(/FROM "users"/)
|
132
|
+
end
|
91
133
|
end
|
92
134
|
end
|
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: 2.4.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -108,22 +108,22 @@ dependencies:
|
|
108
108
|
name: rspec
|
109
109
|
requirement: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- - ">="
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
version: 3.5.0
|
114
111
|
- - "~>"
|
115
112
|
- !ruby/object:Gem::Version
|
116
113
|
version: '3.5'
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 3.5.0
|
117
117
|
type: :development
|
118
118
|
prerelease: false
|
119
119
|
version_requirements: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- - ">="
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: 3.5.0
|
124
121
|
- - "~>"
|
125
122
|
- !ruby/object:Gem::Version
|
126
123
|
version: '3.5'
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 3.5.0
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: factory_bot
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -299,7 +299,7 @@ licenses:
|
|
299
299
|
metadata:
|
300
300
|
source_code_uri: https://github.com/crashtech/torque-postgresql
|
301
301
|
bug_tracker_uri: https://github.com/crashtech/torque-postgresql/issues
|
302
|
-
post_install_message:
|
302
|
+
post_install_message:
|
303
303
|
rdoc_options:
|
304
304
|
- "--title"
|
305
305
|
- Torque PostgreSQL
|
@@ -316,60 +316,60 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
316
|
- !ruby/object:Gem::Version
|
317
317
|
version: 1.8.11
|
318
318
|
requirements: []
|
319
|
-
rubygems_version: 3.
|
320
|
-
signing_key:
|
319
|
+
rubygems_version: 3.2.15
|
320
|
+
signing_key:
|
321
321
|
specification_version: 4
|
322
322
|
summary: ActiveRecord extension to access PostgreSQL advanced resources
|
323
323
|
test_files:
|
324
324
|
- spec/en.yml
|
325
325
|
- spec/factories/authors.rb
|
326
326
|
- spec/factories/comments.rb
|
327
|
+
- spec/factories/item.rb
|
327
328
|
- spec/factories/posts.rb
|
328
329
|
- spec/factories/tags.rb
|
329
330
|
- spec/factories/texts.rb
|
330
331
|
- spec/factories/users.rb
|
331
332
|
- spec/factories/videos.rb
|
332
|
-
- spec/factories/item.rb
|
333
333
|
- spec/mocks/cache_query.rb
|
334
334
|
- spec/mocks/create_table.rb
|
335
335
|
- spec/models/activity.rb
|
336
336
|
- spec/models/activity_book.rb
|
337
|
-
- spec/models/activity_post.rb
|
338
337
|
- spec/models/activity_post/sample.rb
|
338
|
+
- spec/models/activity_post.rb
|
339
339
|
- spec/models/author.rb
|
340
340
|
- spec/models/author_journalist.rb
|
341
|
+
- spec/models/category.rb
|
341
342
|
- spec/models/comment.rb
|
342
343
|
- spec/models/course.rb
|
343
344
|
- spec/models/geometry.rb
|
344
345
|
- spec/models/guest_comment.rb
|
346
|
+
- spec/models/internal/user.rb
|
347
|
+
- spec/models/item.rb
|
345
348
|
- spec/models/post.rb
|
349
|
+
- spec/models/question.rb
|
350
|
+
- spec/models/question_select.rb
|
346
351
|
- spec/models/tag.rb
|
347
352
|
- spec/models/text.rb
|
348
353
|
- spec/models/time_keeper.rb
|
349
354
|
- spec/models/user.rb
|
350
355
|
- spec/models/video.rb
|
351
|
-
- spec/
|
352
|
-
- spec/
|
353
|
-
- spec/
|
354
|
-
- spec/
|
355
|
-
- spec/
|
356
|
+
- spec/schema.rb
|
357
|
+
- spec/spec_helper.rb
|
358
|
+
- spec/tests/arel_spec.rb
|
359
|
+
- spec/tests/auxiliary_statement_spec.rb
|
360
|
+
- spec/tests/belongs_to_many_spec.rb
|
356
361
|
- spec/tests/collector_spec.rb
|
357
362
|
- spec/tests/distinct_on_spec.rb
|
363
|
+
- spec/tests/enum_set_spec.rb
|
364
|
+
- spec/tests/enum_spec.rb
|
358
365
|
- spec/tests/geometric_builder_spec.rb
|
359
|
-
- spec/tests/
|
360
|
-
- spec/tests/quoting_spec.rb
|
361
|
-
- spec/tests/relation_spec.rb
|
362
|
-
- spec/tests/belongs_to_many_spec.rb
|
363
|
-
- spec/tests/range_spec.rb
|
366
|
+
- spec/tests/has_many_spec.rb
|
364
367
|
- spec/tests/insert_all_spec.rb
|
365
|
-
- spec/tests/enum_set_spec.rb
|
366
|
-
- spec/tests/auxiliary_statement_spec.rb
|
367
368
|
- spec/tests/interval_spec.rb
|
369
|
+
- spec/tests/lazy_spec.rb
|
368
370
|
- spec/tests/period_spec.rb
|
371
|
+
- spec/tests/quoting_spec.rb
|
372
|
+
- spec/tests/range_spec.rb
|
373
|
+
- spec/tests/relation_spec.rb
|
369
374
|
- spec/tests/schema_spec.rb
|
370
375
|
- spec/tests/table_inheritance_spec.rb
|
371
|
-
- spec/tests/arel_spec.rb
|
372
|
-
- spec/tests/enum_spec.rb
|
373
|
-
- spec/tests/has_many_spec.rb
|
374
|
-
- spec/spec_helper.rb
|
375
|
-
- spec/schema.rb
|