torque-postgresql 2.4.1 → 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
|
@@ -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,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
|
@@ -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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|