ar_schema_functions 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/ar_schema_functions.gemspec +24 -0
- data/lib/ar_schema_functions/extensions.rb +57 -0
- data/lib/ar_schema_functions/railtie.rb +20 -0
- data/lib/ar_schema_functions/version.rb +5 -0
- data/lib/ar_schema_functions.rb +4 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6cea6bd061b0022cd749cbaed3924dc53e6c10957ec03f0a58e59dd5ab352414
|
4
|
+
data.tar.gz: '09e0c07f709115d6b8e75f092ce0d281b3a488e970837d4a693a6671f5c042f3'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12ac604674a76566f4dde3286ab352df2626df7b1f27597d340c648049087cd87a2e255a30e6adff73656f8892a4fa5fc59f89d9f7ef77556e6234502d9822c8
|
7
|
+
data.tar.gz: c812aaceadfe1b99e1c7901735b72727ec446589be3a74d0f88533060c6eef5c08ab86e7361694940dbd00d806968a755a9a7faa51e338a42cbb76b1e9c501cf
|
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/ar_schema_functions/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'ar_schema_functions'
|
7
|
+
spec.version = ArSchemaFunctions::VERSION
|
8
|
+
spec.authors = ['Dave Allie']
|
9
|
+
spec.email = ['dave@visibuild.com.au']
|
10
|
+
|
11
|
+
spec.summary = 'Populate schema.rb with stored SQL functions'
|
12
|
+
spec.homepage = 'https://github.com/visibuild/ar_schema_functions'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/visibuild/ar_schema_functions'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/visibuild/ar_schema_functions/blob/master/CHANGELOG.md'
|
19
|
+
|
20
|
+
spec.files = Dir['lib/**/*'] + %w[Gemfile ar_schema_functions.gemspec]
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'activerecord', '>= 4.0.0', '< 7.0.0'
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ArSchemaFunctions
|
4
|
+
module Extensions
|
5
|
+
module SchemaDumper
|
6
|
+
def dump(stream)
|
7
|
+
header(stream)
|
8
|
+
extensions(stream)
|
9
|
+
functions(stream)
|
10
|
+
tables(stream)
|
11
|
+
trailer(stream)
|
12
|
+
stream
|
13
|
+
end
|
14
|
+
|
15
|
+
# Defined by SQL engine specific adapters (if supported)
|
16
|
+
def functions(stream); end
|
17
|
+
end
|
18
|
+
|
19
|
+
module PostgreSQLSchemaDumper
|
20
|
+
def functions(stream)
|
21
|
+
functions = @connection.functions
|
22
|
+
|
23
|
+
return unless functions.any?
|
24
|
+
|
25
|
+
functions.each do |function|
|
26
|
+
indented_function = function.lines.map { |line| " #{line}" }.join
|
27
|
+
stream.puts " connection.execute(<<~SQL)\n#{indented_function} SQL"
|
28
|
+
stream.puts
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module AbstractAdapter
|
34
|
+
# Defined by SQL engine specific adapters (if supported)
|
35
|
+
def functions
|
36
|
+
[]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module PostgreSQLAdapter
|
41
|
+
def functions
|
42
|
+
# From https://dataedo.com/kb/query/postgresql/list-user-defined-functions
|
43
|
+
exec_query(<<~SQL.squish, 'SCHEMA').cast_values
|
44
|
+
select case when l.lanname = 'internal' then p.prosrc
|
45
|
+
else pg_get_functiondef(p.oid)
|
46
|
+
end as definition
|
47
|
+
from pg_proc p
|
48
|
+
left join pg_namespace n on p.pronamespace = n.oid
|
49
|
+
left join pg_language l on p.prolang = l.oid
|
50
|
+
where n.nspname not in ('pg_catalog', 'information_schema')#{' '}
|
51
|
+
and l.lanname != 'c'
|
52
|
+
order by definition;
|
53
|
+
SQL
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'extensions'
|
4
|
+
|
5
|
+
module ArSchemaFunctions
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer 'ar_schema_functions.active_record' do
|
8
|
+
ActiveSupport.on_load :active_record do
|
9
|
+
ActiveRecord::SchemaDumper.prepend(ArSchemaFunctions::Extensions::SchemaDumper)
|
10
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ArSchemaFunctions::Extensions::AbstractAdapter)
|
11
|
+
|
12
|
+
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
13
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(ArSchemaFunctions::Extensions::PostgreSQLAdapter)
|
14
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper
|
15
|
+
.prepend(ArSchemaFunctions::Extensions::PostgreSQLSchemaDumper)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar_schema_functions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Allie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 7.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 7.0.0
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- dave@visibuild.com.au
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- Gemfile
|
41
|
+
- ar_schema_functions.gemspec
|
42
|
+
- lib/ar_schema_functions.rb
|
43
|
+
- lib/ar_schema_functions/extensions.rb
|
44
|
+
- lib/ar_schema_functions/railtie.rb
|
45
|
+
- lib/ar_schema_functions/version.rb
|
46
|
+
homepage: https://github.com/visibuild/ar_schema_functions
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata:
|
50
|
+
homepage_uri: https://github.com/visibuild/ar_schema_functions
|
51
|
+
source_code_uri: https://github.com/visibuild/ar_schema_functions
|
52
|
+
changelog_uri: https://github.com/visibuild/ar_schema_functions/blob/master/CHANGELOG.md
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.5.0
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.2.15
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Populate schema.rb with stored SQL functions
|
72
|
+
test_files: []
|