torque-postgresql 3.2.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f08898e4218d41dbcc6394500243760cdd29425ad77135a623bea043cfa8d3ae
4
- data.tar.gz: 93c5d71e1597364b7e434e6c88faf4cfd64dcbc930756398f7539dc525a21f05
3
+ metadata.gz: 1948838632756aeab31c22f59995a8a41ce1900671e3cc9e1f8d802d898a4fe6
4
+ data.tar.gz: ca24eb91ead1a52927d1b0069e8408419600ba7884744a31de3909f45b59bb4d
5
5
  SHA512:
6
- metadata.gz: c7f93afd26ff711ba03f5a5b1381a139690acf8d3a5621ddec1d26a94ae345c2a59e06cdd9805a5101b4d81f51c151ea0fd19bba7a66d080d05387b073cfd55a
7
- data.tar.gz: 5db371506b24fe1c5e28aee69054a83724af93642f44cd3646f6aa9ff9bd58b7a2d2632a186762dca570e2adb0ceea1c38cec5d0119b8f0e4e882b4089913895
6
+ metadata.gz: 41071ecb22d7730bdb0debe558cf4b14db7ca648637d8f59cc43de31d0ca847b0ce7df2447b2e75be507b7ccd03f668c0dc7fa7232a38217889f5172f923a243
7
+ data.tar.gz: 74be2a0828976d3f521e3c9ff0c49708cc767dd019c8a22b6e98080bbda036da4297675c8852f124d01de3588f04b390ae7f5138549a3e85a6f6ce0ad1e50ccb
@@ -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
@@ -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 klass.schema
15
+ next unless klass.respond_to?(:schema) && !(value = klass.schema).nil?
16
+ break value
17
17
  end
18
18
  end
19
19
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Torque
4
4
  module PostgreSQL
5
- VERSION = '3.2.1'
5
+ VERSION = '3.2.2'
6
6
  end
7
7
  end
@@ -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: 3.2.1
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: 2023-01-06 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails