torque-postgresql 3.2.0 → 3.2.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 +4 -4
- data/lib/torque/postgresql/adapter/database_statements.rb +13 -15
- data/lib/torque/postgresql/adapter/schema_statements.rb +19 -2
- data/lib/torque/postgresql/config.rb +2 -2
- data/lib/torque/postgresql/table_name.rb +2 -2
- data/lib/torque/postgresql/version.rb +1 -1
- data/spec/tests/schema_spec.rb +42 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1948838632756aeab31c22f59995a8a41ce1900671e3cc9e1f8d802d898a4fe6
|
4
|
+
data.tar.gz: ca24eb91ead1a52927d1b0069e8408419600ba7884744a31de3909f45b59bb4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41071ecb22d7730bdb0debe558cf4b14db7ca648637d8f59cc43de31d0ca847b0ce7df2447b2e75be507b7ccd03f668c0dc7fa7232a38217889f5172f923a243
|
7
|
+
data.tar.gz: 74be2a0828976d3f521e3c9ff0c49708cc767dd019c8a22b6e98080bbda036da4297675c8852f124d01de3588f04b390ae7f5138549a3e85a6f6ce0ad1e50ccb
|
@@ -194,23 +194,21 @@ module Torque
|
|
194
194
|
|
195
195
|
# Get the list of columns, and their definition, but only from the
|
196
196
|
# actual table, does not include columns that comes from inherited table
|
197
|
-
def column_definitions(table_name)
|
198
|
-
|
199
|
-
local_condition = 'AND a.attislocal IS TRUE' if @_dump_mode
|
197
|
+
def column_definitions(table_name)
|
198
|
+
local = 'AND a.attislocal' if @_dump_mode
|
200
199
|
|
201
200
|
query(<<-SQL, 'SCHEMA')
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
ORDER BY a.attnum
|
201
|
+
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
|
202
|
+
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
|
203
|
+
c.collname, col_description(a.attrelid, a.attnum) AS comment,
|
204
|
+
#{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated
|
205
|
+
FROM pg_attribute a
|
206
|
+
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
|
207
|
+
LEFT JOIN pg_type t ON a.atttypid = t.oid
|
208
|
+
LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
|
209
|
+
WHERE a.attrelid = #{quote(quote_table_name(table_name))}::regclass
|
210
|
+
AND a.attnum > 0 AND NOT a.attisdropped #{local}
|
211
|
+
ORDER BY a.attnum
|
214
212
|
SQL
|
215
213
|
end
|
216
214
|
|
@@ -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
|
@@ -87,6 +87,18 @@ module Torque
|
|
87
87
|
super table_name, **options, &block
|
88
88
|
end
|
89
89
|
|
90
|
+
# Simply add the schema to the table name when changing a table
|
91
|
+
def change_table(table_name, **options)
|
92
|
+
table_name = "#{options[:schema]}.#{table_name}" if options[:schema].present?
|
93
|
+
super table_name, **options
|
94
|
+
end
|
95
|
+
|
96
|
+
# Simply add the schema to the table name when dropping a table
|
97
|
+
def drop_table(table_name, **options)
|
98
|
+
table_name = "#{options[:schema]}.#{table_name}" if options[:schema].present?
|
99
|
+
super table_name, **options
|
100
|
+
end
|
101
|
+
|
90
102
|
# Add the schema option when extracting table options
|
91
103
|
def table_options(table_name)
|
92
104
|
parts = table_name.split('.').reverse
|
@@ -112,6 +124,11 @@ module Torque
|
|
112
124
|
|
113
125
|
private
|
114
126
|
|
127
|
+
# Remove the schema from the sequence name
|
128
|
+
def sequence_name_from_parts(table_name, column_name, suffix)
|
129
|
+
super(table_name.split('.').last, column_name, suffix)
|
130
|
+
end
|
131
|
+
|
115
132
|
def quote_enum_values(name, values, options)
|
116
133
|
prefix = options[:prefix]
|
117
134
|
prefix = name if prefix === true
|
@@ -59,11 +59,11 @@ module Torque
|
|
59
59
|
# arguments to format string or send on a proc
|
60
60
|
cte.send_arguments_key = :args
|
61
61
|
|
62
|
-
# Estipulate a class name (which may contain namespace) that
|
62
|
+
# Estipulate a class name (which may contain namespace) that exposes the
|
63
63
|
# auxiliary statement in order to perform detached CTEs
|
64
64
|
cte.exposed_class = 'TorqueCTE'
|
65
65
|
|
66
|
-
# Estipulate a class name (which may contain namespace) that
|
66
|
+
# Estipulate a class name (which may contain namespace) that exposes the
|
67
67
|
# recursive auxiliary statement in order to perform detached CTEs
|
68
68
|
cte.exposed_recursive_class = 'TorqueRecursiveCTE'
|
69
69
|
|
@@ -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: 3.2.
|
4
|
+
version: 3.2.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:
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|