pg_saurus 4.0.0 → 4.1.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/column.rb +19 -0
- data/lib/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb +15 -0
- data/lib/pg_saurus/connection_adapters/postgresql_adapter/extension_methods.rb +1 -2
- data/lib/pg_saurus/connection_adapters/postgresql_adapter/function_methods.rb +3 -2
- data/lib/pg_saurus/engine.rb +14 -1
- data/lib/pg_saurus/tools.rb +4 -2
- data/lib/pg_saurus/version.rb +1 -1
- metadata +8 -10
- data/bin/rails +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6752e3270a15b3c039999db06e47cef3a6cbb7bddc6b9c1a11e3a53b3e032932
|
4
|
+
data.tar.gz: bdcf9f4e1d30a30f84930595dba797e005e6e42e29e74cbd9eb0fad929d4f09b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26c0a9d9147f8a2af05eefc95f7f65d21ab048cec633b93875a652e8ae77815e248ffe6c09155f3318e8d81cb53ef957cb00a9562e37baeffaee6b6c8bdf542
|
7
|
+
data.tar.gz: 2867b714cf7599e686cce0f01f388f227874f00c641fb8b969fbf1a3316886c21c4a9e665d96fe0dbbd3fb3dc359157ae62ed1ed0e9c6eb7a735695ff14925ec
|
@@ -0,0 +1,19 @@
|
|
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
|
@@ -15,6 +15,21 @@ module ActiveRecord
|
|
15
15
|
# Regex to find where clause in index statements
|
16
16
|
INDEX_WHERE_EXPRESSION = /WHERE (.+)$/
|
17
17
|
|
18
|
+
# Returns the list of all tables in the schema search path or a specified schema.
|
19
|
+
#
|
20
|
+
# == Patch:
|
21
|
+
# If current user is not `postgres` original method return all tables from all schemas
|
22
|
+
# without schema prefix. This disables such behavior by querying only default schema.
|
23
|
+
# Tables with schemas will be queried later.
|
24
|
+
#
|
25
|
+
def tables(name = nil)
|
26
|
+
query(<<-SQL, 'SCHEMA').map { |row| row[0] }
|
27
|
+
SELECT tablename
|
28
|
+
FROM pg_tables
|
29
|
+
WHERE schemaname = ANY (ARRAY['public'])
|
30
|
+
SQL
|
31
|
+
end
|
32
|
+
|
18
33
|
# Returns an array of indexes for the given table.
|
19
34
|
#
|
20
35
|
# == Patch 1:
|
@@ -112,8 +112,7 @@ module PgSaurus::ConnectionAdapters::PostgreSQLAdapter::ExtensionMethods
|
|
112
112
|
# @return [Hash{String => Hash{Symbol => String}}] A list of loaded extensions with their options
|
113
113
|
def pg_extensions
|
114
114
|
# Check postgresql version to not break on Postgresql < 9.1 during schema dump
|
115
|
-
|
116
|
-
return {} unless pg_version_str =~ /^PostgreSQL (\d+\.\d+.\d+)/ && ($1 >= '9.1')
|
115
|
+
return {} if (::PgSaurus::Engine.pg_server_version <=> [9, 1]) < 0
|
117
116
|
|
118
117
|
sql = <<-SQL
|
119
118
|
SELECT pge.extname AS ext_name, pgn.nspname AS schema_name, pge.extversion AS ext_version
|
@@ -11,12 +11,13 @@ module PgSaurus::ConnectionAdapters::PostgreSQLAdapter::FunctionMethods
|
|
11
11
|
|
12
12
|
# Return a list of defined DB functions. Ignore function definitions that can't be parsed.
|
13
13
|
def functions
|
14
|
+
pg_major = ::PgSaurus::Engine.pg_server_version[0]
|
14
15
|
res = select_all <<-SQL
|
15
16
|
SELECT n.nspname AS "Schema",
|
16
17
|
p.proname AS "Name",
|
17
18
|
pg_catalog.pg_get_function_result(p.oid) AS "Returning",
|
18
19
|
CASE
|
19
|
-
WHEN p.proiswindow
|
20
|
+
WHEN #{pg_major >= 11 ? "p.prokind = 'w'" : "p.proiswindow"} THEN 'window'
|
20
21
|
WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger'
|
21
22
|
ELSE 'normal'
|
22
23
|
END AS "Type",
|
@@ -26,7 +27,7 @@ module PgSaurus::ConnectionAdapters::PostgreSQLAdapter::FunctionMethods
|
|
26
27
|
WHERE pg_catalog.pg_function_is_visible(p.oid)
|
27
28
|
AND n.nspname <> 'pg_catalog'
|
28
29
|
AND n.nspname <> 'information_schema'
|
29
|
-
AND p.proisagg <> TRUE
|
30
|
+
AND #{pg_major >= 11 ? "p.prokind <> 'a'" : "p.proisagg <> TRUE"}
|
30
31
|
ORDER BY 1, 2, 3, 4;
|
31
32
|
SQL
|
32
33
|
res.inject([]) do |buffer, row|
|
data/lib/pg_saurus/engine.rb
CHANGED
@@ -2,10 +2,23 @@ module PgSaurus
|
|
2
2
|
# :nodoc:
|
3
3
|
class Engine < Rails::Engine
|
4
4
|
|
5
|
+
# Postgres server version.
|
6
|
+
#
|
7
|
+
# @return [Array<Integer>]
|
8
|
+
def self.pg_server_version
|
9
|
+
@pg_server_version ||=
|
10
|
+
::ActiveRecord::Base.connection.
|
11
|
+
select_value('SHOW SERVER_VERSION').
|
12
|
+
split('.')[0..1].map(&:to_i)
|
13
|
+
end
|
14
|
+
|
5
15
|
initializer "pg_saurus" do
|
6
16
|
ActiveSupport.on_load(:active_record) do
|
7
17
|
# load monkey patches
|
8
|
-
%w(schema_dumper
|
18
|
+
%w(schema_dumper
|
19
|
+
errors
|
20
|
+
connection_adapters/postgresql/schema_statements
|
21
|
+
connection_adapters/postgresql/column).each do |path|
|
9
22
|
require ::PgSaurus::Engine.root + "lib/core_ext/active_record/" + path
|
10
23
|
end
|
11
24
|
|
data/lib/pg_saurus/tools.rb
CHANGED
@@ -19,8 +19,10 @@ module PgSaurus
|
|
19
19
|
#
|
20
20
|
# @return [void]
|
21
21
|
def create_schema_if_not_exists(schema_name)
|
22
|
-
|
23
|
-
|
22
|
+
unless schemas.include?(schema_name.to_s)
|
23
|
+
sql = %{CREATE SCHEMA "#{schema_name}"}
|
24
|
+
connection.execute sql
|
25
|
+
end
|
24
26
|
end
|
25
27
|
|
26
28
|
# Ensure schema does not exists.
|
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.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Potapov Sergey
|
@@ -10,10 +10,10 @@ authors:
|
|
10
10
|
- Matt Dressel
|
11
11
|
- Bruce Burdick
|
12
12
|
- HornsAndHooves
|
13
|
-
autorequire:
|
13
|
+
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date:
|
16
|
+
date: 2020-01-31 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: pg
|
@@ -205,15 +205,14 @@ email:
|
|
205
205
|
- cryo28@gmail.com
|
206
206
|
- matt.dressel@gmail.com
|
207
207
|
- rubygems.org@bruceburdick.com
|
208
|
-
executables:
|
209
|
-
- rails
|
208
|
+
executables: []
|
210
209
|
extensions: []
|
211
210
|
extra_rdoc_files:
|
212
211
|
- README.markdown
|
213
212
|
files:
|
214
213
|
- README.markdown
|
215
|
-
- bin/rails
|
216
214
|
- lib/colorized_text.rb
|
215
|
+
- lib/core_ext/active_record/connection_adapters/postgresql/column.rb
|
217
216
|
- lib/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb
|
218
217
|
- lib/core_ext/active_record/errors.rb
|
219
218
|
- lib/core_ext/active_record/schema_dumper.rb
|
@@ -271,7 +270,7 @@ homepage: https://github.com/HornsAndHooves/pg_saurus
|
|
271
270
|
licenses:
|
272
271
|
- MIT
|
273
272
|
metadata: {}
|
274
|
-
post_install_message:
|
273
|
+
post_install_message:
|
275
274
|
rdoc_options: []
|
276
275
|
require_paths:
|
277
276
|
- lib
|
@@ -286,9 +285,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
285
|
- !ruby/object:Gem::Version
|
287
286
|
version: '0'
|
288
287
|
requirements: []
|
289
|
-
|
290
|
-
|
291
|
-
signing_key:
|
288
|
+
rubygems_version: 3.0.9
|
289
|
+
signing_key:
|
292
290
|
specification_version: 4
|
293
291
|
summary: ActiveRecord extensions for PostgreSQL.
|
294
292
|
test_files: []
|
data/bin/rails
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
-
# installed from the root of your application.
|
4
|
-
|
5
|
-
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
-
ENGINE_PATH = File.expand_path('../lib/pg_saurus/engine', __dir__)
|
7
|
-
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
|
8
|
-
|
9
|
-
# Set up gems listed in the Gemfile.
|
10
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
11
|
-
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
-
|
13
|
-
require 'rails/all'
|
14
|
-
require 'rails/engine/commands'
|