torque-postgresql 2.4.1 → 2.4.3
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/lib/torque/postgresql/adapter/schema_statements.rb +14 -2
- data/lib/torque/postgresql/associations/belongs_to_many_association.rb +2 -2
- data/lib/torque/postgresql/table_name.rb +2 -2
- data/lib/torque/postgresql/version.rb +1 -1
- data/spec/schema.rb +9 -9
- data/spec/tests/belongs_to_many_spec.rb +41 -0
- data/spec/tests/distinct_on_spec.rb +1 -1
- data/spec/tests/relation_spec.rb +1 -1
- data/spec/tests/schema_spec.rb +33 -0
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19cfac9293a2758ae928a2d1a8ab7aaf37b8d7ba1943f24c89b37eae28c04fa8
|
4
|
+
data.tar.gz: 213df2558e23565ab99f4a36feb7733e59437ddfe36b01f44d2603570f92f39f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34df30f7080d5b44a59b59011a1f1751c122fa8aa9df50facfadb2b3a051547f922d03dfdb374b027c004dc5c757b84d655938f34ece4f48423556cccd7c5485
|
7
|
+
data.tar.gz: b63f3250fc36a88b39a66750e577eda7b734a621f8176dabde7eacbb2cf50d00b1db7fe451286210fefc3c5f43fb624f447290a55cd286611f9cc08e98e1ea35
|
@@ -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
|
@@ -12,9 +12,9 @@ module Torque
|
|
12
12
|
## CUSTOM
|
13
13
|
def ids_reader
|
14
14
|
if loaded?
|
15
|
-
target.pluck(reflection.
|
15
|
+
target.pluck(reflection.active_record_primary_key)
|
16
16
|
elsif !target.empty?
|
17
|
-
load_target.pluck(reflection.
|
17
|
+
load_target.pluck(reflection.active_record_primary_key)
|
18
18
|
else
|
19
19
|
stale_state || column_default_value
|
20
20
|
end
|
@@ -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/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
version =
|
13
|
+
version = 3
|
14
14
|
|
15
15
|
return if ActiveRecord::Migrator.current_version == version
|
16
16
|
ActiveRecord::Schema.define(version: version) do
|
@@ -77,14 +77,14 @@ ActiveRecord::Schema.define(version: version) do
|
|
77
77
|
create_table "texts", force: :cascade do |t|
|
78
78
|
t.integer "user_id"
|
79
79
|
t.string "content"
|
80
|
-
t.enum "conflict",
|
80
|
+
t.enum "conflict", enum_type: :conflicts
|
81
81
|
end
|
82
82
|
|
83
83
|
create_table "comments", force: :cascade do |t|
|
84
|
-
t.integer "user_id",
|
84
|
+
t.integer "user_id", null: false
|
85
85
|
t.integer "comment_id"
|
86
86
|
t.integer "video_id"
|
87
|
-
t.text "content",
|
87
|
+
t.text "content", null: false
|
88
88
|
t.string "kind"
|
89
89
|
t.index ["user_id"], name: "index_comments_on_user_id", using: :btree
|
90
90
|
t.index ["comment_id"], name: "index_comments_on_comment_id", using: :btree
|
@@ -92,7 +92,7 @@ ActiveRecord::Schema.define(version: version) do
|
|
92
92
|
|
93
93
|
create_table "courses", force: :cascade do |t|
|
94
94
|
t.integer "category_id"
|
95
|
-
t.string "title",
|
95
|
+
t.string "title", null: false
|
96
96
|
t.interval "duration"
|
97
97
|
t.enum "types", enum_type: :types, array: true
|
98
98
|
t.datetime "created_at", null: false
|
@@ -108,7 +108,7 @@ ActiveRecord::Schema.define(version: version) do
|
|
108
108
|
t.integer "activity_id"
|
109
109
|
t.string "title"
|
110
110
|
t.text "content"
|
111
|
-
t.enum "status",
|
111
|
+
t.enum "status", enum_type: :content_status
|
112
112
|
t.index ["author_id"], name: "index_posts_on_author_id", using: :btree
|
113
113
|
end
|
114
114
|
|
@@ -120,8 +120,8 @@ ActiveRecord::Schema.define(version: version) do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
create_table "users", force: :cascade do |t|
|
123
|
-
t.string "name",
|
124
|
-
t.enum "role",
|
123
|
+
t.string "name", null: false
|
124
|
+
t.enum "role", enum_type: :roles, default: :visitor
|
125
125
|
t.datetime "created_at", null: false
|
126
126
|
t.datetime "updated_at", null: false
|
127
127
|
end
|
@@ -137,7 +137,7 @@ ActiveRecord::Schema.define(version: version) do
|
|
137
137
|
t.integer "author_id"
|
138
138
|
t.string "title"
|
139
139
|
t.boolean "active"
|
140
|
-
t.enum "kind",
|
140
|
+
t.enum "kind", enum_type: :types
|
141
141
|
t.datetime "created_at", null: false
|
142
142
|
t.datetime "updated_at", null: false
|
143
143
|
end
|
@@ -441,4 +441,45 @@ RSpec.describe 'BelongsToMany' do
|
|
441
441
|
expect { query.load }.not_to raise_error
|
442
442
|
end
|
443
443
|
end
|
444
|
+
|
445
|
+
context 'using custom keys' do
|
446
|
+
let(:connection) { ActiveRecord::Base.connection }
|
447
|
+
let(:post) { Post }
|
448
|
+
let(:tag) { Tag }
|
449
|
+
let(:tags) { %w[a b c].map { |id| create(:tag, friendly_id: id) } }
|
450
|
+
|
451
|
+
subject { create(:post) }
|
452
|
+
|
453
|
+
before do
|
454
|
+
connection.add_column(:tags, :friendly_id, :string)
|
455
|
+
connection.add_column(:posts, :friendly_tag_ids, :string, array: true)
|
456
|
+
post.belongs_to_many(:tags, foreign_key: :friendly_tag_ids, primary_key: :friendly_id)
|
457
|
+
post.reset_column_information
|
458
|
+
tag.reset_column_information
|
459
|
+
end
|
460
|
+
|
461
|
+
after do
|
462
|
+
tag.reset_column_information
|
463
|
+
post.reset_column_information
|
464
|
+
post._reflections.delete(:tags)
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'loads associated records' do
|
468
|
+
subject.update(friendly_tag_ids: tags.pluck(:friendly_id))
|
469
|
+
|
470
|
+
expect(subject.tags.to_sql).to be_eql(<<-SQL.squish)
|
471
|
+
SELECT "tags".* FROM "tags" WHERE "tags"."friendly_id" IN ('a', 'b', 'c')
|
472
|
+
SQL
|
473
|
+
|
474
|
+
expect(subject.tags.load).to be_a(ActiveRecord::Associations::CollectionProxy)
|
475
|
+
expect(subject.tags.to_a).to be_eql(tags)
|
476
|
+
end
|
477
|
+
|
478
|
+
it 'can properly assign tags' do
|
479
|
+
expect(subject.friendly_tag_ids).to be_blank
|
480
|
+
|
481
|
+
subject.tags = tags
|
482
|
+
expect(subject.friendly_tag_ids).to be_eql(%w[a b c])
|
483
|
+
end
|
484
|
+
end
|
444
485
|
end
|
@@ -40,7 +40,7 @@ RSpec.describe 'DistinctOn' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'raises with invalid relation' do
|
43
|
-
expect { subject.distinct_on(
|
43
|
+
expect { subject.distinct_on(supervisors: :name).to_sql }.to \
|
44
44
|
raise_error(ArgumentError, /Relation for/)
|
45
45
|
end
|
46
46
|
|
data/spec/tests/relation_spec.rb
CHANGED
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
|
@@ -86,8 +106,11 @@ RSpec.describe 'Schema' do
|
|
86
106
|
|
87
107
|
context 'on relation' do
|
88
108
|
let(:model) { Internal::User }
|
109
|
+
let(:table_name) { Torque::PostgreSQL::TableName.new(model, 'users') }
|
89
110
|
|
90
111
|
it 'adds the schema to the query' do
|
112
|
+
model.reset_table_name
|
113
|
+
expect(table_name.to_s).to eq('internal.users')
|
91
114
|
expect(model.all.to_sql).to match(/FROM "internal"."users"/)
|
92
115
|
end
|
93
116
|
|
@@ -95,7 +118,17 @@ RSpec.describe 'Schema' do
|
|
95
118
|
allow(Internal).to receive(:schema).and_return('internal')
|
96
119
|
allow(model).to receive(:schema).and_return(nil)
|
97
120
|
|
121
|
+
model.reset_table_name
|
122
|
+
expect(table_name.to_s).to eq('internal.users')
|
98
123
|
expect(model.all.to_sql).to match(/FROM "internal"."users"/)
|
99
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
|
100
133
|
end
|
101
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.3
|
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: 2024-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -134,6 +134,9 @@ dependencies:
|
|
134
134
|
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: 6.2.1
|
137
|
+
- - "<"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '6.4'
|
137
140
|
type: :development
|
138
141
|
prerelease: false
|
139
142
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -144,6 +147,9 @@ dependencies:
|
|
144
147
|
- - ">="
|
145
148
|
- !ruby/object:Gem::Version
|
146
149
|
version: 6.2.1
|
150
|
+
- - "<"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '6.4'
|
147
153
|
- !ruby/object:Gem::Dependency
|
148
154
|
name: faker
|
149
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -299,7 +305,7 @@ licenses:
|
|
299
305
|
metadata:
|
300
306
|
source_code_uri: https://github.com/crashtech/torque-postgresql
|
301
307
|
bug_tracker_uri: https://github.com/crashtech/torque-postgresql/issues
|
302
|
-
post_install_message:
|
308
|
+
post_install_message:
|
303
309
|
rdoc_options:
|
304
310
|
- "--title"
|
305
311
|
- Torque PostgreSQL
|
@@ -317,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
317
323
|
version: 1.8.11
|
318
324
|
requirements: []
|
319
325
|
rubygems_version: 3.2.15
|
320
|
-
signing_key:
|
326
|
+
signing_key:
|
321
327
|
specification_version: 4
|
322
328
|
summary: ActiveRecord extension to access PostgreSQL advanced resources
|
323
329
|
test_files:
|