fx 0.8.0 → 0.9.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/.github/workflows/ci.yml +2 -7
- data/CHANGELOG.md +124 -0
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +12 -1
- data/README.md +2 -0
- data/bin/standardrb +27 -0
- data/fx.gemspec +10 -15
- data/lib/fx/adapters/postgres/connection.rb +12 -0
- data/lib/fx/adapters/postgres/functions.rb +3 -3
- data/lib/fx/adapters/postgres/triggers.rb +3 -3
- data/lib/fx/adapters/postgres.rb +6 -14
- data/lib/fx/command_recorder.rb +87 -6
- data/lib/fx/configuration.rb +0 -25
- data/lib/fx/definition.rb +16 -6
- data/lib/fx/function.rb +3 -3
- data/lib/fx/schema_dumper.rb +45 -5
- data/lib/fx/statements.rb +228 -6
- data/lib/fx/trigger.rb +3 -3
- data/lib/fx/version.rb +1 -1
- data/lib/fx.rb +30 -12
- data/lib/generators/fx/function/function_generator.rb +2 -2
- data/lib/generators/fx/trigger/trigger_generator.rb +1 -5
- data/spec/acceptance/user_manages_functions_spec.rb +4 -4
- data/spec/acceptance/user_manages_triggers_spec.rb +6 -6
- data/spec/acceptance_helper.rb +2 -2
- data/spec/dummy/config/application.rb +5 -1
- data/spec/features/functions/migrations_spec.rb +3 -3
- data/spec/features/functions/revert_spec.rb +3 -3
- data/spec/features/triggers/migrations_spec.rb +4 -4
- data/spec/features/triggers/revert_spec.rb +5 -5
- data/spec/fx/adapters/postgres/functions_spec.rb +26 -30
- data/spec/fx/adapters/postgres/triggers_spec.rb +34 -38
- data/spec/fx/adapters/postgres_spec.rb +107 -109
- data/spec/fx/command_recorder_spec.rb +27 -25
- data/spec/fx/configuration_spec.rb +20 -9
- data/spec/fx/definition_spec.rb +27 -35
- data/spec/fx/function_spec.rb +45 -48
- data/spec/fx/schema_dumper_spec.rb +123 -0
- data/spec/fx/statements_spec.rb +217 -0
- data/spec/fx/trigger_spec.rb +37 -40
- data/spec/fx_spec.rb +28 -0
- data/spec/generators/fx/function/function_generator_spec.rb +3 -3
- data/spec/generators/fx/trigger/trigger_generator_spec.rb +10 -10
- data/spec/spec_helper.rb +5 -0
- data/spec/support/definition_helpers.rb +2 -6
- data/spec/support/warning_helper.rb +5 -0
- metadata +21 -163
- data/lib/fx/command_recorder/arguments.rb +0 -43
- data/lib/fx/command_recorder/function.rb +0 -30
- data/lib/fx/command_recorder/trigger.rb +0 -30
- data/lib/fx/schema_dumper/function.rb +0 -38
- data/lib/fx/schema_dumper/trigger.rb +0 -29
- data/lib/fx/statements/function.rb +0 -113
- data/lib/fx/statements/trigger.rb +0 -144
- data/spec/fx/command_recorder/arguments_spec.rb +0 -41
- data/spec/fx/schema_dumper/function_spec.rb +0 -78
- data/spec/fx/schema_dumper/trigger_spec.rb +0 -40
- data/spec/fx/statements/function_spec.rb +0 -103
- data/spec/fx/statements/trigger_spec.rb +0 -132
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1eaca24d4bb2262d766c845df89e92051c4824b6cf621714d4786a6b1f2eaaf
|
|
4
|
+
data.tar.gz: 32b2aaf58fbb8844adf514d5b3e15bf924bcc47d69f048135579cb002c15581b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0fffacf063521bd38e8f4343c4879b8872b9a750a50d278b90fc08434ca6fe6bfdaad7d79f96349b042d1fa0145f5254294d44b38cc0ca72d5516c8a08c023e7
|
|
7
|
+
data.tar.gz: 41c966c110817c920c4280f7a83ebfac59687cb98f0603bdf11fecd368332172441f6c1e428f364b1dfc7b7552fa896b82489979a1e2f5744b6b20c9c8e406ee
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -14,14 +14,9 @@ jobs:
|
|
|
14
14
|
strategy:
|
|
15
15
|
fail-fast: false
|
|
16
16
|
matrix:
|
|
17
|
-
ruby: ["
|
|
18
|
-
rails: ["
|
|
17
|
+
ruby: ["3.0", "3.1", "3.2", "3.3", "3.4.0-preview2"]
|
|
18
|
+
rails: ["7.0", "7.1", "7.2", "8.0.0"]
|
|
19
19
|
continue-on-error: [false]
|
|
20
|
-
exclude:
|
|
21
|
-
- ruby: "3.2"
|
|
22
|
-
rails: "6.0"
|
|
23
|
-
- ruby: "3.2"
|
|
24
|
-
rails: "6.1"
|
|
25
20
|
|
|
26
21
|
services:
|
|
27
22
|
postgres:
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
The noteworthy changes for each version are included here. For a complete
|
|
4
|
+
changelog, see the [commits] for each version via the version links.
|
|
5
|
+
|
|
6
|
+
[commits]: https://github.com/teoljungberg/fx/commits/master
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
[Unreleased]: https://github.com/teoljungberg/fx/compare/v0.8.0..HEAD
|
|
11
|
+
|
|
12
|
+
## [0.9.0]
|
|
13
|
+
|
|
14
|
+
[0.9.0]: https://github.com/teoljungberg/fx/compare/v0.8.0...v0.9.0
|
|
15
|
+
|
|
16
|
+
- Drop EOL Rails versions (6.2)
|
|
17
|
+
- Add Ruby 3.4.0 preview's to the test matrix (#152)
|
|
18
|
+
- Add Rails 8.0.0 to the test matrix (#152)
|
|
19
|
+
- Add Rails 7.2 to the test matrix (#150)
|
|
20
|
+
- Fix deprecation warnings in Rails (#148)
|
|
21
|
+
- Mark `Fx::CommandRecorder::Arguments` as private.
|
|
22
|
+
- Add Ruby 3.3 to the test matrix (#144)
|
|
23
|
+
- Internal refactorings:
|
|
24
|
+
- Move development dependencies to Gemfile (#145)
|
|
25
|
+
- Inline `Fx::CommandRecorder::Arguments`
|
|
26
|
+
- Inline `Fx::{CommandRecorder,SchemaDumper,Statements}::{Function,Trigger}`
|
|
27
|
+
- Move configuration methods to `Fx`
|
|
28
|
+
- Add `Fx::Definition.{function,trigger}` (#119)
|
|
29
|
+
- Add Rails 7.1 to the test matrix (#136)
|
|
30
|
+
- Add Rubygems metadata to gemspec (#132)
|
|
31
|
+
- Disable RSpec's monkey patching (#121)
|
|
32
|
+
- Raise on warnings (#124)
|
|
33
|
+
- Require Ruby >= 3.0 (#128)
|
|
34
|
+
- Require Rails >= 6.1 (#127)
|
|
35
|
+
|
|
36
|
+
## [0.8.0]
|
|
37
|
+
|
|
38
|
+
[0.8.0]: https://github.com/teoljungberg/fx/compare/v0.7.0...v0.8.0
|
|
39
|
+
|
|
40
|
+
- Replace Travis CI with GitHub Actions.
|
|
41
|
+
- Bump minimum Ruby version to 2.7.
|
|
42
|
+
- Ruby 2.7 will be dropped in end of March 2023, so a release to drop it will
|
|
43
|
+
happen afterwards.
|
|
44
|
+
- Bump minimum Rails version to 6.0.0
|
|
45
|
+
- Rails 6.0 will be dropped in June 2023, so a release to drop it will happen
|
|
46
|
+
afterwards
|
|
47
|
+
- Adopt standard.rb
|
|
48
|
+
- Contributing improvements
|
|
49
|
+
- Test-suite improvements
|
|
50
|
+
|
|
51
|
+
## [0.7.0]
|
|
52
|
+
|
|
53
|
+
[0.7.0]: https://github.com/teoljungberg/fx/compare/v0.6.2...v0.7.0
|
|
54
|
+
|
|
55
|
+
- Support Ruby 3 (#76)
|
|
56
|
+
- Preserve backslashes when dumping the schema (#71)
|
|
57
|
+
- Add a link to F(x) SqlServer Adapter in the README (#80)
|
|
58
|
+
|
|
59
|
+
## [0.6.2]
|
|
60
|
+
|
|
61
|
+
[0.6.2]: https://github.com/teoljungberg/fx/compare/v0.6.1...v0.6.2
|
|
62
|
+
|
|
63
|
+
- Add support for Ruby 3
|
|
64
|
+
|
|
65
|
+
## [0.6.1]
|
|
66
|
+
|
|
67
|
+
[0.6.1]: https://github.com/teoljungberg/fx/compare/v0.6.0...v0.6.1
|
|
68
|
+
|
|
69
|
+
- Fix: Support --no-migration generator flag (#62)
|
|
70
|
+
|
|
71
|
+
## [0.6.0]
|
|
72
|
+
|
|
73
|
+
[0.6.0]: https://github.com/teoljungberg/fx/compare/v0.5.0...v0.6.0
|
|
74
|
+
|
|
75
|
+
- Support unique functions with parameters (#27)
|
|
76
|
+
- Use db connection provided by Rails (#49)
|
|
77
|
+
- Support `--no-migration` generator flag (#60)
|
|
78
|
+
- Use current ActiveRecord version in migrations (#59)
|
|
79
|
+
- Does not include aggregates when dumping schema (#50)
|
|
80
|
+
- Dump functions in the beginning of the schema (#53)
|
|
81
|
+
|
|
82
|
+
## [0.5.0]
|
|
83
|
+
|
|
84
|
+
[0.5.0]: https://github.com/teoljungberg/fx/compare/v0.4.0...v0.5.0
|
|
85
|
+
|
|
86
|
+
- Drop EOL Ruby versions.
|
|
87
|
+
- Drop EOL Rails versions.
|
|
88
|
+
|
|
89
|
+
## [0.4.0]
|
|
90
|
+
|
|
91
|
+
[0.4.0]: https://github.com/teoljungberg/fx/compare/v0.3.1...v0.4.0
|
|
92
|
+
|
|
93
|
+
- Add table_name to README (#15)
|
|
94
|
+
- Reverse function/trigger order in README (#17)
|
|
95
|
+
- Split up Trigger#definition test (#19)
|
|
96
|
+
- Find definitions in engines (#18)
|
|
97
|
+
|
|
98
|
+
## [0.3.1]
|
|
99
|
+
|
|
100
|
+
[0.3.1]: https://github.com/teoljungberg/fx/compare/v0.3.0...v0.3.1
|
|
101
|
+
|
|
102
|
+
- Strip shared leading whitespace from sql_definitions (#13)
|
|
103
|
+
- Update documentation for `drop_function`
|
|
104
|
+
- Document `Fx::Adapters::Postgres#initialize`
|
|
105
|
+
- Fix test suite issues:
|
|
106
|
+
- Add unit test coverage for `Fx::Adapters::Triggers`
|
|
107
|
+
- Add unit test coverage for `Fx::Adapters::Functions`
|
|
108
|
+
- Add unit test coverage for `Fx::Trigger`
|
|
109
|
+
- Add unit test coverage for `Fx::Function`
|
|
110
|
+
|
|
111
|
+
## [0.3.0]
|
|
112
|
+
|
|
113
|
+
[0.3.0]: https://github.com/teoljungberg/fx/compare/v0.2.0...v0.3.0
|
|
114
|
+
|
|
115
|
+
## [0.2.0]
|
|
116
|
+
|
|
117
|
+
[0.2.0]: https://github.com/teoljungberg/fx/compare/v0.1.0...v0.2.0
|
|
118
|
+
|
|
119
|
+
## [0.1.0]
|
|
120
|
+
|
|
121
|
+
F(x) adds methods to `ActiveRecord::Migration` to create and manage database
|
|
122
|
+
functions and triggers in Rails.
|
|
123
|
+
|
|
124
|
+
[0.1.0]: https://github.com/teoljungberg/fx/compare/4ccf986643d9de82038977eff8c6b1a4a716d698...v0.1.0
|
data/CONTRIBUTING.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Contributing
|
|
2
2
|
|
|
3
|
-
We love contributions from everyone.
|
|
3
|
+
We love contributions from everyone. By participating in this project, you
|
|
4
4
|
agree to abide by our [code of conduct].
|
|
5
5
|
|
|
6
|
-
[code of conduct]:
|
|
6
|
+
[code of conduct]: https://thoughtbot.com/open-source-code-of-conduct
|
|
7
7
|
|
|
8
8
|
## Contributing Code
|
|
9
9
|
|
|
@@ -19,6 +19,6 @@ agree to abide by our [code of conduct].
|
|
|
19
19
|
|
|
20
20
|
[good commit message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
|
21
21
|
|
|
22
|
-
Others will give constructive feedback.
|
|
22
|
+
Others will give constructive feedback. This is a time for discussion and
|
|
23
23
|
improvements, and making the necessary changes will be required before we can
|
|
24
24
|
merge the contribution.
|
data/Gemfile
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
source "https://rubygems.org"
|
|
2
2
|
|
|
3
|
-
# Specify your gem's dependencies in fx.gemspec
|
|
4
3
|
gemspec
|
|
4
|
+
|
|
5
|
+
gem "ammeter", ">= 1.1.3"
|
|
6
|
+
gem "bundler", ">= 1.5"
|
|
7
|
+
gem "database_cleaner"
|
|
8
|
+
gem "pg"
|
|
9
|
+
gem "pry"
|
|
10
|
+
gem "rake"
|
|
11
|
+
gem "redcarpet"
|
|
12
|
+
gem "rspec", ">= 3.3"
|
|
13
|
+
gem "standardrb"
|
|
14
|
+
gem "yard"
|
|
15
|
+
gem "warning"
|
data/README.md
CHANGED
|
@@ -110,6 +110,8 @@ column value instead of a plain string.
|
|
|
110
110
|
|
|
111
111
|
## Plugins/Adapters
|
|
112
112
|
|
|
113
|
+
- [MySQL](https://github.com/f-mer/fx-adapters-mysql/)
|
|
114
|
+
- [Oracle](https://github.com/zygotecnologia/fx-oracle-adapter)
|
|
113
115
|
- [SQLserver](https://github.com/tarellel/fx-sqlserver-adapter)
|
|
114
116
|
|
|
115
117
|
## Contributing
|
data/bin/standardrb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'standardrb' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
12
|
+
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
14
|
+
|
|
15
|
+
if File.file?(bundle_binstub)
|
|
16
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
17
|
+
load(bundle_binstub)
|
|
18
|
+
else
|
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
require "rubygems"
|
|
25
|
+
require "bundler/setup"
|
|
26
|
+
|
|
27
|
+
load Gem.bin_path("standard", "standardrb")
|
data/fx.gemspec
CHANGED
|
@@ -8,29 +8,24 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.authors = ["Teo Ljungberg"]
|
|
9
9
|
spec.email = ["teo@teoljungberg.com"]
|
|
10
10
|
spec.summary = "Support for database functions and triggers in Rails migrations"
|
|
11
|
-
spec.description =
|
|
11
|
+
spec.description = <<~DESCRIPTION
|
|
12
12
|
Adds methods to ActiveRecord::Migration to create and manage database functions
|
|
13
13
|
and triggers in Rails
|
|
14
14
|
DESCRIPTION
|
|
15
15
|
spec.homepage = "https://github.com/teoljungberg/fx"
|
|
16
16
|
spec.license = "MIT"
|
|
17
|
+
spec.metadata = {
|
|
18
|
+
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
|
19
|
+
"changelog_uri" => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
|
|
20
|
+
"homepage_uri" => spec.homepage,
|
|
21
|
+
"source_code_uri" => spec.homepage
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
spec.files = `git ls-files -z`.split("\x0")
|
|
19
25
|
spec.require_paths = ["lib"]
|
|
20
26
|
|
|
21
|
-
spec.
|
|
22
|
-
spec.
|
|
23
|
-
spec.add_development_dependency "database_cleaner"
|
|
24
|
-
spec.add_development_dependency "pg"
|
|
25
|
-
spec.add_development_dependency "pry"
|
|
26
|
-
spec.add_development_dependency "rake"
|
|
27
|
-
spec.add_development_dependency "redcarpet"
|
|
28
|
-
spec.add_development_dependency "rspec", ">= 3.3"
|
|
29
|
-
spec.add_development_dependency "standardrb"
|
|
30
|
-
spec.add_development_dependency "yard"
|
|
27
|
+
spec.add_dependency "activerecord", ">= 7.0"
|
|
28
|
+
spec.add_dependency "railties", ">= 7.0"
|
|
31
29
|
|
|
32
|
-
spec.
|
|
33
|
-
spec.add_dependency "railties", ">= 6.0.0"
|
|
34
|
-
|
|
35
|
-
spec.required_ruby_version = ">= 2.7"
|
|
30
|
+
spec.required_ruby_version = ">= 3.0"
|
|
36
31
|
end
|
|
@@ -10,6 +10,18 @@ module Fx
|
|
|
10
10
|
#
|
|
11
11
|
# @api private
|
|
12
12
|
class Connection < SimpleDelegator
|
|
13
|
+
# https://www.postgresql.org/docs/9.6/sql-dropfunction.html
|
|
14
|
+
# https://www.postgresql.org/docs/10/sql-dropfunction.html
|
|
15
|
+
def support_drop_function_without_args
|
|
16
|
+
pg_connection = undecorated_connection.raw_connection
|
|
17
|
+
pg_connection.server_version >= 10_00_00
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def undecorated_connection
|
|
23
|
+
__getobj__
|
|
24
|
+
end
|
|
13
25
|
end
|
|
14
26
|
end
|
|
15
27
|
end
|
|
@@ -8,7 +8,7 @@ module Fx
|
|
|
8
8
|
class Functions
|
|
9
9
|
# The SQL query used by F(x) to retrieve the functions considered
|
|
10
10
|
# dumpable into `db/schema.rb`.
|
|
11
|
-
FUNCTIONS_WITH_DEFINITIONS_QUERY =
|
|
11
|
+
FUNCTIONS_WITH_DEFINITIONS_QUERY = <<~EOS.freeze
|
|
12
12
|
SELECT
|
|
13
13
|
pp.proname AS name,
|
|
14
14
|
pg_get_functiondef(pp.oid) AS definition
|
|
@@ -27,8 +27,8 @@ module Fx
|
|
|
27
27
|
# Wraps #all as a static facade.
|
|
28
28
|
#
|
|
29
29
|
# @return [Array<Fx::Function>]
|
|
30
|
-
def self.all(
|
|
31
|
-
new(
|
|
30
|
+
def self.all(...)
|
|
31
|
+
new(...).all
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def initialize(connection)
|
|
@@ -8,7 +8,7 @@ module Fx
|
|
|
8
8
|
class Triggers
|
|
9
9
|
# The SQL query used by F(x) to retrieve the triggers considered
|
|
10
10
|
# dumpable into `db/schema.rb`.
|
|
11
|
-
TRIGGERS_WITH_DEFINITIONS_QUERY =
|
|
11
|
+
TRIGGERS_WITH_DEFINITIONS_QUERY = <<~EOS.freeze
|
|
12
12
|
SELECT
|
|
13
13
|
pt.tgname AS name,
|
|
14
14
|
pg_get_triggerdef(pt.oid) AS definition
|
|
@@ -25,8 +25,8 @@ module Fx
|
|
|
25
25
|
# Wraps #all as a static facade.
|
|
26
26
|
#
|
|
27
27
|
# @return [Array<Fx::Trigger>]
|
|
28
|
-
def self.all(
|
|
29
|
-
new(
|
|
28
|
+
def self.all(...)
|
|
29
|
+
new(...).all
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def initialize(connection)
|
data/lib/fx/adapters/postgres.rb
CHANGED
|
@@ -69,7 +69,7 @@ module Fx
|
|
|
69
69
|
#
|
|
70
70
|
# @return [void]
|
|
71
71
|
def create_function(sql_definition)
|
|
72
|
-
execute
|
|
72
|
+
execute(sql_definition)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
# Creates a trigger in the database.
|
|
@@ -81,7 +81,7 @@ module Fx
|
|
|
81
81
|
#
|
|
82
82
|
# @return [void]
|
|
83
83
|
def create_trigger(sql_definition)
|
|
84
|
-
execute
|
|
84
|
+
execute(sql_definition)
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
# Updates a function in the database.
|
|
@@ -125,10 +125,10 @@ module Fx
|
|
|
125
125
|
#
|
|
126
126
|
# @return [void]
|
|
127
127
|
def drop_function(name)
|
|
128
|
-
if support_drop_function_without_args
|
|
129
|
-
execute
|
|
128
|
+
if connection.support_drop_function_without_args
|
|
129
|
+
execute("DROP FUNCTION #{name};")
|
|
130
130
|
else
|
|
131
|
-
execute
|
|
131
|
+
execute("DROP FUNCTION #{name}();")
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
|
|
@@ -142,7 +142,7 @@ module Fx
|
|
|
142
142
|
#
|
|
143
143
|
# @return [void]
|
|
144
144
|
def drop_trigger(name, on:)
|
|
145
|
-
execute
|
|
145
|
+
execute("DROP TRIGGER #{name} ON #{on};")
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
private
|
|
@@ -154,14 +154,6 @@ module Fx
|
|
|
154
154
|
def connection
|
|
155
155
|
Connection.new(connectable.connection)
|
|
156
156
|
end
|
|
157
|
-
|
|
158
|
-
def support_drop_function_without_args
|
|
159
|
-
# https://www.postgresql.org/docs/9.6/sql-dropfunction.html
|
|
160
|
-
# https://www.postgresql.org/docs/10/sql-dropfunction.html
|
|
161
|
-
|
|
162
|
-
pg_connection = connectable.connection.raw_connection
|
|
163
|
-
pg_connection.server_version >= 10_00_00
|
|
164
|
-
end
|
|
165
157
|
end
|
|
166
158
|
end
|
|
167
159
|
end
|
data/lib/fx/command_recorder.rb
CHANGED
|
@@ -1,12 +1,53 @@
|
|
|
1
|
-
require "fx/command_recorder/arguments"
|
|
2
|
-
require "fx/command_recorder/function"
|
|
3
|
-
require "fx/command_recorder/trigger"
|
|
4
|
-
|
|
5
1
|
module Fx
|
|
6
2
|
# @api private
|
|
7
3
|
module CommandRecorder
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
def create_function(*args)
|
|
5
|
+
record(:create_function, args)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def drop_function(*args)
|
|
9
|
+
record(:drop_function, args)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def update_function(*args)
|
|
13
|
+
record(:update_function, args)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def invert_create_function(args)
|
|
17
|
+
[:drop_function, args]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def invert_drop_function(args)
|
|
21
|
+
perform_inversion(:create_function, args)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def invert_update_function(args)
|
|
25
|
+
perform_inversion(:update_function, args)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def create_trigger(*args)
|
|
29
|
+
record(:create_trigger, args)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def drop_trigger(*args)
|
|
33
|
+
record(:drop_trigger, args)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def update_trigger(*args)
|
|
37
|
+
record(:update_trigger, args)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def invert_create_trigger(args)
|
|
41
|
+
[:drop_trigger, args]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def invert_drop_trigger(args)
|
|
45
|
+
perform_inversion(:create_trigger, args)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def invert_update_trigger(args)
|
|
49
|
+
perform_inversion(:update_trigger, args)
|
|
50
|
+
end
|
|
10
51
|
|
|
11
52
|
private
|
|
12
53
|
|
|
@@ -20,5 +61,45 @@ module Fx
|
|
|
20
61
|
|
|
21
62
|
[method, arguments.invert_version.to_a]
|
|
22
63
|
end
|
|
64
|
+
|
|
65
|
+
class Arguments
|
|
66
|
+
def initialize(args)
|
|
67
|
+
@args = args.freeze
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def function
|
|
71
|
+
@args[0]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def version
|
|
75
|
+
options[:version]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def revert_to_version
|
|
79
|
+
options[:revert_to_version]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def invert_version
|
|
83
|
+
Arguments.new([function, options_for_revert])
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def to_a
|
|
87
|
+
@args.to_a
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def options
|
|
93
|
+
@options ||= @args[1] || {}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def options_for_revert
|
|
97
|
+
options.clone.tap do |revert_options|
|
|
98
|
+
revert_options[:version] = revert_to_version
|
|
99
|
+
revert_options.delete(:revert_to_version)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
private_constant :Arguments
|
|
23
104
|
end
|
|
24
105
|
end
|
data/lib/fx/configuration.rb
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
1
|
module Fx
|
|
2
|
-
# @return [Fx::Configuration] F(x)'s current configuration
|
|
3
|
-
def self.configuration
|
|
4
|
-
@_configuration ||= Configuration.new
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
# Set F(x)'s configuration
|
|
8
|
-
#
|
|
9
|
-
# @param config [Fx::Configuration]
|
|
10
|
-
def self.configuration=(config)
|
|
11
|
-
@_configuration = config
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Modify F(x)'s current configuration
|
|
15
|
-
#
|
|
16
|
-
# @yieldparam [Fx::Configuration] config current F(x) config
|
|
17
|
-
# ```
|
|
18
|
-
# Fx.configure do |config|
|
|
19
|
-
# config.database = Fx::Adapters::Postgres
|
|
20
|
-
# config.dump_functions_at_beginning_of_schema = true
|
|
21
|
-
# end
|
|
22
|
-
# ```
|
|
23
|
-
def self.configure
|
|
24
|
-
yield configuration
|
|
25
|
-
end
|
|
26
|
-
|
|
27
2
|
# F(x)'s configuration object.
|
|
28
3
|
class Configuration
|
|
29
4
|
# The F(x) database adapter instance to use when executing SQL.
|
data/lib/fx/definition.rb
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
module Fx
|
|
2
2
|
# @api private
|
|
3
3
|
class Definition
|
|
4
|
-
|
|
4
|
+
FUNCTION = "function".freeze
|
|
5
|
+
TRIGGER = "trigger".freeze
|
|
6
|
+
|
|
7
|
+
def self.function(name:, version:)
|
|
8
|
+
new(name: name, version: version, type: FUNCTION)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.trigger(name:, version:)
|
|
12
|
+
new(name: name, version: version, type: TRIGGER)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def initialize(name:, version:, type:)
|
|
5
16
|
@name = name
|
|
6
17
|
@version = version.to_i
|
|
7
18
|
@type = type
|
|
8
19
|
end
|
|
9
20
|
|
|
10
21
|
def to_sql
|
|
11
|
-
File.read(find_file || full_path)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end
|
|
22
|
+
content = File.read(find_file || full_path)
|
|
23
|
+
raise "Define #{@type} in #{path} before migrating." if content.empty?
|
|
24
|
+
|
|
25
|
+
content
|
|
16
26
|
end
|
|
17
27
|
|
|
18
28
|
def full_path
|
data/lib/fx/function.rb
CHANGED
|
@@ -6,9 +6,9 @@ module Fx
|
|
|
6
6
|
attr_reader :name, :definition
|
|
7
7
|
delegate :<=>, to: :name
|
|
8
8
|
|
|
9
|
-
def initialize(
|
|
10
|
-
@name =
|
|
11
|
-
@definition =
|
|
9
|
+
def initialize(row)
|
|
10
|
+
@name = row.fetch("name")
|
|
11
|
+
@definition = row.fetch("definition")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def ==(other)
|
data/lib/fx/schema_dumper.rb
CHANGED
|
@@ -1,10 +1,50 @@
|
|
|
1
|
-
require "fx/schema_dumper/function"
|
|
2
|
-
require "fx/schema_dumper/trigger"
|
|
3
|
-
|
|
4
1
|
module Fx
|
|
5
2
|
# @api private
|
|
6
3
|
module SchemaDumper
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
def tables(stream)
|
|
5
|
+
if Fx.configuration.dump_functions_at_beginning_of_schema
|
|
6
|
+
functions(stream)
|
|
7
|
+
empty_line(stream)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
super
|
|
11
|
+
|
|
12
|
+
unless Fx.configuration.dump_functions_at_beginning_of_schema
|
|
13
|
+
functions(stream)
|
|
14
|
+
empty_line(stream)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
triggers(stream)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def empty_line(stream)
|
|
23
|
+
stream.puts if dumpable_functions_in_database.any?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def functions(stream)
|
|
27
|
+
dumpable_functions_in_database.each do |function|
|
|
28
|
+
stream.puts(function.to_schema)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def triggers(stream)
|
|
33
|
+
if dumpable_triggers_in_database.any?
|
|
34
|
+
stream.puts
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
dumpable_triggers_in_database.each do |trigger|
|
|
38
|
+
stream.puts(trigger.to_schema)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def dumpable_functions_in_database
|
|
43
|
+
@_dumpable_functions_in_database ||= Fx.database.functions
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def dumpable_triggers_in_database
|
|
47
|
+
@_dumpable_triggers_in_database ||= Fx.database.triggers
|
|
48
|
+
end
|
|
9
49
|
end
|
|
10
50
|
end
|