pg_saurus 4.3.0 → 5.0.0
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/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb +36 -25
- data/lib/pg_saurus/connection_adapters/abstract_adapter/schema_methods.rb +6 -4
- data/lib/pg_saurus/connection_adapters/postgresql_adapter/translate_exception.rb +3 -2
- data/lib/pg_saurus/create_index_concurrently.rb +1 -1
- data/lib/pg_saurus/engine.rb +5 -4
- data/lib/pg_saurus/version.rb +1 -1
- metadata +11 -12
- data/lib/core_ext/active_record/connection_adapters/postgresql/column.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a6d057b35291dc622b20193e085fc52c5807fd8310b1d8925b9c0636d72d95b
|
4
|
+
data.tar.gz: 7f0257ad41a044c887519c844a54334172fa5e829f7c6e06c0aca6280f8f6625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab15973698f38c460f51ee4879913be9c6fc4d9b7c5fde71d4e597cb230b8097b1011330017da05d2b67d8fac6c7e852c21e2d2314602ecf0892a9c3ed7251e7
|
7
|
+
data.tar.gz: 680092950b8eeb8d1716edf301d14a94744ecdb352423b9550b5b84abbd59ffd323dcb226bac13707e1b4edbe4753808ccfe955cbb5f2f0890a168f1f0d3658c
|
@@ -135,13 +135,9 @@ module ActiveRecord
|
|
135
135
|
# the column is difficult to target for quoting.
|
136
136
|
skip_column_quoting = options.delete(:skip_column_quoting) or false
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
index_options,
|
142
|
-
index_algorithm,
|
143
|
-
index_using,
|
144
|
-
comment = add_index_options(table_name, column_name, options)
|
138
|
+
index, algorithm, if_not_exists = add_index_options(table_name, column_name, **options)
|
139
|
+
algorithm = creation_method || algorithm
|
140
|
+
create_index = CreateIndexDefinition.new(index, algorithm, if_not_exists)
|
145
141
|
|
146
142
|
# GOTCHA:
|
147
143
|
# It ensures that there is no existing index only for the case when the index
|
@@ -156,25 +152,11 @@ module ActiveRecord
|
|
156
152
|
# -- zekefast 2012-09-25
|
157
153
|
if creation_method.present? && index_exists?(table_name, column_name, options)
|
158
154
|
raise ::PgSaurus::IndexExistsError,
|
159
|
-
"Index #{
|
155
|
+
"Index #{index.name} for `#{table_name}.#{column_name}` " \
|
160
156
|
"column can not be created concurrently, because such index already exists."
|
161
157
|
end
|
162
158
|
|
163
|
-
|
164
|
-
statements << "CREATE #{index_type} INDEX"
|
165
|
-
statements << creation_method if creation_method.present?
|
166
|
-
statements << index_algorithm if index_algorithm.present?
|
167
|
-
statements << quote_column_name(index_name)
|
168
|
-
statements << "ON"
|
169
|
-
statements << quote_table_name(table_name)
|
170
|
-
statements << index_using if index_using.present?
|
171
|
-
statements << "(#{index_columns_and_opclasses})" if index_columns_and_opclasses.present? unless skip_column_quoting
|
172
|
-
statements << "(#{column_name})" if column_name.present? and skip_column_quoting
|
173
|
-
statements << index_options if index_options.present?
|
174
|
-
|
175
|
-
sql = statements.join(' ')
|
176
|
-
|
177
|
-
execute(sql)
|
159
|
+
execute schema_creation.accept(create_index)
|
178
160
|
end
|
179
161
|
|
180
162
|
# Check to see if an index exists on a table for a given index definition.
|
@@ -261,9 +243,8 @@ module ActiveRecord
|
|
261
243
|
end
|
262
244
|
]
|
263
245
|
|
264
|
-
add_options_for_index_columns(quoted_columns, options).values
|
246
|
+
add_options_for_index_columns(quoted_columns, **options).values.join(", ")
|
265
247
|
end
|
266
|
-
protected :quoted_columns_for_index
|
267
248
|
|
268
249
|
# Map an expression to a name appropriate for an index.
|
269
250
|
def expression_index_name(name)
|
@@ -281,6 +262,36 @@ module ActiveRecord
|
|
281
262
|
end
|
282
263
|
private :expression_index_name
|
283
264
|
|
265
|
+
|
266
|
+
# == Patch 1:
|
267
|
+
# Remove schema name part from table name when sequence name doesn't include it.
|
268
|
+
def new_column_from_field(table_name, field)
|
269
|
+
column_name, type, default, notnull, oid, fmod, collation, comment = field
|
270
|
+
type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
|
271
|
+
default_value = extract_value_from_default(default)
|
272
|
+
default_function = extract_default_function(default_value, default)
|
273
|
+
|
274
|
+
if match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/)
|
275
|
+
sequence_name = match[:sequence_name]
|
276
|
+
is_schema_name_included = sequence_name.split(".").size > 1
|
277
|
+
_table_name = is_schema_name_included ? table_name : table_name.split(".").last
|
278
|
+
|
279
|
+
serial = sequence_name_from_parts(_table_name, column_name, match[:suffix]) == sequence_name
|
280
|
+
end
|
281
|
+
|
282
|
+
PostgreSQL::Column.new(
|
283
|
+
column_name,
|
284
|
+
default_value,
|
285
|
+
type_metadata,
|
286
|
+
!notnull,
|
287
|
+
default_function,
|
288
|
+
collation: collation,
|
289
|
+
comment: comment.presence,
|
290
|
+
serial: serial
|
291
|
+
)
|
292
|
+
end
|
293
|
+
private :new_column_from_field
|
294
|
+
|
284
295
|
# Split column name to name and operator class if possible.
|
285
296
|
def split_column_name(name)
|
286
297
|
if name =~ OPERATOR_REGEXP
|
@@ -4,17 +4,19 @@ module PgSaurus::ConnectionAdapters::AbstractAdapter::SchemaMethods
|
|
4
4
|
|
5
5
|
# Provide :schema option to +create_table+ method.
|
6
6
|
def create_table(table_name, options = {}, &block)
|
7
|
-
options
|
8
|
-
schema_name = options.delete(:schema)
|
9
|
-
table_name = "#{schema_name}.#{table_name}" if schema_name
|
7
|
+
table_name, options = extract_table_options(table_name, options)
|
10
8
|
super(table_name, options, &block)
|
11
9
|
end
|
12
10
|
|
13
11
|
# Provide :schema option to +drop_table+ method.
|
14
12
|
def drop_table(table_name, options = {})
|
13
|
+
super(*extract_table_options(table_name, options))
|
14
|
+
end
|
15
|
+
|
16
|
+
def extract_table_options(table_name, options)
|
15
17
|
options = options.dup
|
16
18
|
schema_name = options.delete(:schema)
|
17
19
|
table_name = "#{schema_name}.#{table_name}" if schema_name
|
18
|
-
|
20
|
+
[table_name, options]
|
19
21
|
end
|
20
22
|
end
|
@@ -5,14 +5,15 @@ module PgSaurus::ConnectionAdapters::PostgreSQLAdapter::TranslateException
|
|
5
5
|
INSUFFICIENT_PRIVILEGE = "42501"
|
6
6
|
|
7
7
|
# Intercept insufficient privilege PG::Error and raise active_record wrapped database exception
|
8
|
-
def translate_exception(exception, message)
|
8
|
+
def translate_exception(exception, message:, sql:, binds:)
|
9
|
+
return exception unless exception.respond_to?(:result)
|
9
10
|
exception_result = exception.result
|
10
11
|
|
11
12
|
case exception_result.try(:error_field, PG::Result::PG_DIAG_SQLSTATE)
|
12
13
|
when INSUFFICIENT_PRIVILEGE
|
13
14
|
exc_message = exception_result.try(:error_field, PG::Result::PG_DIAG_MESSAGE_PRIMARY)
|
14
15
|
exc_message ||= message
|
15
|
-
::ActiveRecord::InsufficientPrivilege.new(exc_message)
|
16
|
+
::ActiveRecord::InsufficientPrivilege.new(exc_message, sql: sql, binds: binds)
|
16
17
|
else
|
17
18
|
super
|
18
19
|
end
|
@@ -72,7 +72,7 @@ module PgSaurus::CreateIndexConcurrently
|
|
72
72
|
def add_index(table_name, column_name, options = {}, &block)
|
73
73
|
table_name = proper_table_name(table_name)
|
74
74
|
# GOTCHA:
|
75
|
-
# checks if index should be created
|
75
|
+
# checks if index should be created concurrently then put it into
|
76
76
|
# the queue to wait till queue processing will be called (should be
|
77
77
|
# happended after closing transaction).
|
78
78
|
# Otherwise just delegate call to PgSaurus's `add_index`.
|
data/lib/pg_saurus/engine.rb
CHANGED
@@ -15,10 +15,11 @@ module PgSaurus
|
|
15
15
|
initializer "pg_saurus" do
|
16
16
|
ActiveSupport.on_load(:active_record) do
|
17
17
|
# load monkey patches
|
18
|
-
%w
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
%w[
|
19
|
+
schema_dumper
|
20
|
+
errors
|
21
|
+
connection_adapters/postgresql/schema_statements
|
22
|
+
].each do |path|
|
22
23
|
require ::PgSaurus::Engine.root + "lib/core_ext/active_record/" + path
|
23
24
|
end
|
24
25
|
|
data/lib/pg_saurus/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_saurus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Potapov Sergey
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date:
|
16
|
+
date: 2022-01-06 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: pg
|
@@ -49,56 +49,56 @@ dependencies:
|
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: '6.0'
|
53
53
|
type: :runtime
|
54
54
|
prerelease: false
|
55
55
|
version_requirements: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: '6.0'
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: activemodel
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
66
|
+
version: '6.0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
69
|
version_requirements: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
73
|
+
version: '6.0'
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
75
|
name: activerecord
|
76
76
|
requirement: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: '6.0'
|
81
81
|
type: :runtime
|
82
82
|
prerelease: false
|
83
83
|
version_requirements: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
85
|
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
version: '6.0'
|
88
88
|
- !ruby/object:Gem::Dependency
|
89
89
|
name: activesupport
|
90
90
|
requirement: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
94
|
+
version: '6.0'
|
95
95
|
type: :runtime
|
96
96
|
prerelease: false
|
97
97
|
version_requirements: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
99
|
- - "~>"
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: '6.0'
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rspec-rails
|
104
104
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,7 +226,6 @@ extra_rdoc_files:
|
|
226
226
|
files:
|
227
227
|
- README.markdown
|
228
228
|
- lib/colorized_text.rb
|
229
|
-
- lib/core_ext/active_record/connection_adapters/postgresql/column.rb
|
230
229
|
- lib/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb
|
231
230
|
- lib/core_ext/active_record/errors.rb
|
232
231
|
- lib/core_ext/active_record/schema_dumper.rb
|
@@ -299,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
299
298
|
- !ruby/object:Gem::Version
|
300
299
|
version: '0'
|
301
300
|
requirements: []
|
302
|
-
rubygems_version: 3.0.
|
301
|
+
rubygems_version: 3.0.8
|
303
302
|
signing_key:
|
304
303
|
specification_version: 4
|
305
304
|
summary: ActiveRecord extensions for PostgreSQL.
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
# PostgreSQL-specific extensions to column definitions in a table.
|
4
|
-
class PostgreSQLColumn < Column #:nodoc:
|
5
|
-
# == Patch 1:
|
6
|
-
# Remove schema name part from table name when sequence name doesn't include it.
|
7
|
-
def serial?
|
8
|
-
return unless default_function
|
9
|
-
|
10
|
-
if %r{\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z} =~ default_function
|
11
|
-
is_schema_name_included = sequence_name.split(".").size > 1
|
12
|
-
_table_name = is_schema_name_included ? table_name : table_name.split(".").last
|
13
|
-
|
14
|
-
sequence_name_from_parts(_table_name, name, suffix) == sequence_name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|