torque-postgresql 3.0.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +17 -0
- data/lib/torque/postgresql/adapter/database_statements.rb +61 -7
- data/lib/torque/postgresql/adapter/schema_creation.rb +3 -9
- data/lib/torque/postgresql/adapter/schema_dumper.rb +39 -7
- data/lib/torque/postgresql/adapter/schema_statements.rb +40 -0
- data/lib/torque/postgresql/adapter.rb +2 -2
- data/lib/torque/postgresql/associations/preloader/loader_query.rb +1 -1
- data/lib/torque/postgresql/auxiliary_statement/recursive.rb +149 -0
- data/lib/torque/postgresql/auxiliary_statement/settings.rb +74 -22
- data/lib/torque/postgresql/auxiliary_statement.rb +39 -40
- data/lib/torque/postgresql/base.rb +29 -25
- data/lib/torque/postgresql/config.rb +17 -0
- data/lib/torque/postgresql/inheritance.rb +3 -1
- data/lib/torque/postgresql/migration/command_recorder.rb +8 -8
- data/lib/torque/postgresql/railtie.rb +5 -1
- data/lib/torque/postgresql/relation/auxiliary_statement.rb +28 -15
- data/lib/torque/postgresql/schema_cache.rb +6 -1
- data/lib/torque/postgresql/table_name.rb +41 -0
- data/lib/torque/postgresql/version.rb +1 -1
- data/lib/torque/postgresql.rb +2 -1
- data/spec/models/category.rb +2 -0
- data/spec/models/internal/user.rb +5 -0
- data/spec/schema.rb +16 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/tests/auxiliary_statement_spec.rb +374 -35
- data/spec/tests/enum_set_spec.rb +7 -6
- data/spec/tests/schema_spec.rb +92 -0
- data/spec/tests/table_inheritance_spec.rb +11 -15
- metadata +17 -5
data/spec/tests/enum_set_spec.rb
CHANGED
@@ -43,18 +43,19 @@ RSpec.describe 'Enum' do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'on schema' do
|
46
|
+
let(:dump_result) do
|
47
|
+
ActiveRecord::SchemaDumper.dump(connection, (dump_result = StringIO.new))
|
48
|
+
dump_result.string
|
49
|
+
end
|
50
|
+
|
46
51
|
it 'can be used on tables' do
|
47
|
-
dump_io = StringIO.new
|
48
52
|
checker = /t\.enum +"conflicts", +array: true, +enum_type: "conflicts"/
|
49
|
-
|
50
|
-
expect(dump_io.string).to match checker
|
53
|
+
expect(dump_result).to match checker
|
51
54
|
end
|
52
55
|
|
53
56
|
xit 'can have a default value as an array of symbols' do
|
54
|
-
dump_io = StringIO.new
|
55
57
|
checker = /t\.enum +"types", +default: \[:A, :B\], +array: true, +enum_type: "types"/
|
56
|
-
|
57
|
-
expect(dump_io.string).to match checker
|
58
|
+
expect(dump_result).to match checker
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Schema' do
|
4
|
+
let(:connection) { ActiveRecord::Base.connection }
|
5
|
+
|
6
|
+
before do
|
7
|
+
connection.instance_variable_set(:@schmeas_blacklist, nil)
|
8
|
+
connection.instance_variable_set(:@schmeas_whitelist, nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'on migration' do
|
12
|
+
it 'can check for existance' do
|
13
|
+
expect(connection.schema_exists?(:information_schema)).to be_falsey
|
14
|
+
expect(connection.schema_exists?(:information_schema, filtered: false)).to be_truthy
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can be created' do
|
18
|
+
expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey
|
19
|
+
connection.create_schema(:legacy)
|
20
|
+
expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'can be deleted' do
|
24
|
+
expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey
|
25
|
+
|
26
|
+
connection.create_schema(:legacy)
|
27
|
+
expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy
|
28
|
+
|
29
|
+
connection.drop_schema(:legacy)
|
30
|
+
expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'works with whitelist' do
|
34
|
+
expect(connection.schema_exists?(:legacy)).to be_falsey
|
35
|
+
connection.create_schema(:legacy)
|
36
|
+
|
37
|
+
expect(connection.schema_exists?(:legacy)).to be_falsey
|
38
|
+
expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy
|
39
|
+
|
40
|
+
connection.schemas_whitelist.push('legacy')
|
41
|
+
expect(connection.schema_exists?(:legacy)).to be_truthy
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'on schema' do
|
46
|
+
let(:dump_result) do
|
47
|
+
ActiveRecord::SchemaDumper.dump(connection, (dump_result = StringIO.new))
|
48
|
+
dump_result.string
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'does not add when there is no extra schemas' do
|
52
|
+
connection.drop_schema(:internal, force: :cascade)
|
53
|
+
expect(dump_result).not_to match /Custom schemas defined in this database/
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'does not include tables from blacklisted schemas' do
|
57
|
+
connection.schemas_blacklist.push('internal')
|
58
|
+
expect(dump_result).not_to match /create_table \"users\",.*schema: +"internal"/
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with internal schema whitelisted' do
|
62
|
+
before { connection.schemas_whitelist.push('internal') }
|
63
|
+
|
64
|
+
it 'dumps the schemas' do
|
65
|
+
expect(dump_result).to match /create_schema \"internal\"/
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'shows the internal users table in the connection tables list' do
|
69
|
+
expect(connection.tables).to include('internal.users')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'dumps tables on whitelisted schemas' do
|
73
|
+
expect(dump_result).to match /create_table \"users\",.*schema: +"internal"/
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'on relation' do
|
79
|
+
let(:model) { Internal::User }
|
80
|
+
|
81
|
+
it 'adds the schema to the query' do
|
82
|
+
expect(model.all.to_sql).to match(/FROM "internal"."users"/)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'can load the schema from the module' do
|
86
|
+
allow(Internal).to receive(:schema).and_return('internal')
|
87
|
+
allow(model).to receive(:schema).and_return(nil)
|
88
|
+
|
89
|
+
expect(model.all.to_sql).to match(/FROM "internal"."users"/)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -73,37 +73,33 @@ RSpec.describe 'TableInheritance' do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
context 'on schema' do
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
let(:dump_result) do
|
77
|
+
ActiveRecord::SchemaDumper.dump(connection, (dump_result = StringIO.new))
|
78
|
+
dump_result.string
|
79
|
+
end
|
79
80
|
|
81
|
+
it 'dumps single inheritance with body' do
|
80
82
|
parts = '"activity_books"'
|
81
83
|
parts << ', id: false'
|
82
84
|
parts << ', force: :cascade'
|
83
|
-
parts << ', inherits:
|
84
|
-
expect(
|
85
|
+
parts << ', inherits: "activities"'
|
86
|
+
expect(dump_result).to match(/create_table #{parts} do /)
|
85
87
|
end
|
86
88
|
|
87
89
|
it 'dumps single inheritance without body' do
|
88
|
-
dump_io = StringIO.new
|
89
|
-
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
90
|
-
|
91
90
|
parts = '"activity_post_samples"'
|
92
91
|
parts << ', id: false'
|
93
92
|
parts << ', force: :cascade'
|
94
|
-
parts << ', inherits:
|
95
|
-
expect(
|
93
|
+
parts << ', inherits: "activity_posts"'
|
94
|
+
expect(dump_result).to match(/create_table #{parts}(?! do \|t\|)/)
|
96
95
|
end
|
97
96
|
|
98
97
|
it 'dumps multiple inheritance' do
|
99
|
-
dump_io = StringIO.new
|
100
|
-
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
101
|
-
|
102
98
|
parts = '"activity_posts"'
|
103
99
|
parts << ', id: false'
|
104
100
|
parts << ', force: :cascade'
|
105
|
-
parts << ', inherits: (\[
|
106
|
-
expect(
|
101
|
+
parts << ', inherits: (\["images", "activities"\]|\["activities", "images"\])'
|
102
|
+
expect(dump_result).to match(/create_table #{parts}/)
|
107
103
|
end
|
108
104
|
end
|
109
105
|
|
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: 3.0
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -155,7 +155,7 @@ dependencies:
|
|
155
155
|
description: Add support to complex resources of PostgreSQL, like data types, array
|
156
156
|
associations, and auxiliary statements (CTE)
|
157
157
|
email:
|
158
|
-
-
|
158
|
+
- me@carlosfsilva.com
|
159
159
|
executables: []
|
160
160
|
extensions: []
|
161
161
|
extra_rdoc_files: []
|
@@ -208,6 +208,7 @@ files:
|
|
208
208
|
- lib/torque/postgresql/attributes/period.rb
|
209
209
|
- lib/torque/postgresql/autosave_association.rb
|
210
210
|
- lib/torque/postgresql/auxiliary_statement.rb
|
211
|
+
- lib/torque/postgresql/auxiliary_statement/recursive.rb
|
211
212
|
- lib/torque/postgresql/auxiliary_statement/settings.rb
|
212
213
|
- lib/torque/postgresql/base.rb
|
213
214
|
- lib/torque/postgresql/collector.rb
|
@@ -232,6 +233,7 @@ files:
|
|
232
233
|
- lib/torque/postgresql/relation/inheritance.rb
|
233
234
|
- lib/torque/postgresql/relation/merger.rb
|
234
235
|
- lib/torque/postgresql/schema_cache.rb
|
236
|
+
- lib/torque/postgresql/table_name.rb
|
235
237
|
- lib/torque/postgresql/version.rb
|
236
238
|
- spec/en.yml
|
237
239
|
- spec/factories/authors.rb
|
@@ -250,10 +252,12 @@ files:
|
|
250
252
|
- spec/models/activity_post/sample.rb
|
251
253
|
- spec/models/author.rb
|
252
254
|
- spec/models/author_journalist.rb
|
255
|
+
- spec/models/category.rb
|
253
256
|
- spec/models/comment.rb
|
254
257
|
- spec/models/course.rb
|
255
258
|
- spec/models/geometry.rb
|
256
259
|
- spec/models/guest_comment.rb
|
260
|
+
- spec/models/internal/user.rb
|
257
261
|
- spec/models/item.rb
|
258
262
|
- spec/models/post.rb
|
259
263
|
- spec/models/question.rb
|
@@ -280,13 +284,18 @@ files:
|
|
280
284
|
- spec/tests/period_spec.rb
|
281
285
|
- spec/tests/quoting_spec.rb
|
282
286
|
- spec/tests/relation_spec.rb
|
287
|
+
- spec/tests/schema_spec.rb
|
283
288
|
- spec/tests/table_inheritance_spec.rb
|
284
289
|
homepage: https://github.com/crashtech/torque-postgresql
|
285
290
|
licenses:
|
286
291
|
- MIT
|
287
|
-
metadata:
|
292
|
+
metadata:
|
293
|
+
source_code_uri: https://github.com/crashtech/torque-postgresql
|
294
|
+
bug_tracker_uri: https://github.com/crashtech/torque-postgresql/issues
|
288
295
|
post_install_message:
|
289
|
-
rdoc_options:
|
296
|
+
rdoc_options:
|
297
|
+
- "--title"
|
298
|
+
- Torque PostgreSQL
|
290
299
|
require_paths:
|
291
300
|
- lib
|
292
301
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -322,10 +331,12 @@ test_files:
|
|
322
331
|
- spec/models/activity_post.rb
|
323
332
|
- spec/models/author.rb
|
324
333
|
- spec/models/author_journalist.rb
|
334
|
+
- spec/models/category.rb
|
325
335
|
- spec/models/comment.rb
|
326
336
|
- spec/models/course.rb
|
327
337
|
- spec/models/geometry.rb
|
328
338
|
- spec/models/guest_comment.rb
|
339
|
+
- spec/models/internal/user.rb
|
329
340
|
- spec/models/item.rb
|
330
341
|
- spec/models/post.rb
|
331
342
|
- spec/models/question.rb
|
@@ -352,4 +363,5 @@ test_files:
|
|
352
363
|
- spec/tests/period_spec.rb
|
353
364
|
- spec/tests/quoting_spec.rb
|
354
365
|
- spec/tests/relation_spec.rb
|
366
|
+
- spec/tests/schema_spec.rb
|
355
367
|
- spec/tests/table_inheritance_spec.rb
|