fx 0.1.0 → 0.11.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 +5 -5
- data/.github/scripts/check-eol +95 -0
- data/.github/workflows/ci.yml +61 -0
- data/.github/workflows/eol-check.yml +30 -0
- data/.rspec +1 -1
- data/.standard.yml +3 -0
- data/CHANGELOG.md +186 -0
- data/CONTRIBUTING.md +13 -4
- data/Gemfile +21 -2
- data/LICENSE +18 -0
- data/README.md +99 -14
- data/Rakefile +11 -1
- data/bin/rake +2 -3
- data/bin/rspec +13 -3
- data/bin/setup +1 -4
- data/bin/standardrb +27 -0
- data/bin/yard +13 -3
- data/fx.gemspec +20 -27
- data/lib/fx/adapters/postgres/connection.rb +6 -0
- data/lib/fx/adapters/postgres/functions.rb +16 -28
- data/lib/fx/adapters/postgres/query_executor.rb +34 -0
- data/lib/fx/adapters/postgres/triggers.rb +14 -28
- data/lib/fx/adapters/postgres.rb +30 -17
- data/lib/fx/command_recorder.rb +104 -13
- data/lib/fx/configuration.rb +10 -25
- data/lib/fx/definition.rb +32 -10
- data/lib/fx/function.rb +23 -9
- data/lib/fx/railtie.rb +15 -0
- data/lib/fx/schema_dumper.rb +33 -10
- data/lib/fx/statements.rb +213 -11
- data/lib/fx/trigger.rb +5 -3
- data/lib/fx/version.rb +1 -1
- data/lib/fx.rb +40 -0
- data/lib/generators/fx/function/USAGE +2 -0
- data/lib/generators/fx/function/function_generator.rb +54 -39
- data/lib/generators/fx/function/templates/db/migrate/create_function.erb +1 -1
- data/lib/generators/fx/function/templates/db/migrate/update_function.erb +1 -1
- data/lib/generators/fx/migration_helper.rb +45 -0
- data/lib/generators/fx/name_helper.rb +33 -0
- data/lib/generators/fx/trigger/USAGE +2 -0
- data/lib/generators/fx/trigger/templates/db/migrate/create_trigger.erb +1 -1
- data/lib/generators/fx/trigger/templates/db/migrate/update_trigger.erb +1 -1
- data/lib/generators/fx/trigger/trigger_generator.rb +46 -51
- data/lib/generators/fx/version_helper.rb +55 -0
- data/spec/acceptance/user_manages_functions_spec.rb +26 -6
- data/spec/acceptance/user_manages_triggers_spec.rb +11 -11
- data/spec/acceptance_helper.rb +17 -11
- data/spec/dummy/Rakefile +8 -1
- data/spec/dummy/bin/bundle +2 -2
- data/spec/dummy/bin/rails +3 -3
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/database.yml +2 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/features/functions/migrations_spec.rb +9 -9
- data/spec/features/functions/revert_spec.rb +13 -13
- data/spec/features/triggers/migrations_spec.rb +11 -11
- data/spec/features/triggers/revert_spec.rb +21 -21
- data/spec/fx/adapters/postgres/functions_spec.rb +40 -0
- data/spec/fx/adapters/postgres/query_executor_spec.rb +75 -0
- data/spec/fx/adapters/postgres/triggers_spec.rb +48 -0
- data/spec/fx/adapters/postgres_spec.rb +115 -111
- data/spec/fx/command_recorder_spec.rb +39 -53
- data/spec/fx/configuration_spec.rb +20 -9
- data/spec/fx/definition_spec.rb +53 -38
- data/spec/fx/function_spec.rb +143 -0
- data/spec/fx/schema_dumper_spec.rb +241 -0
- data/spec/fx/statements_spec.rb +219 -0
- data/spec/fx/trigger_spec.rb +52 -0
- data/spec/fx_spec.rb +28 -0
- data/spec/generators/fx/function/function_generator_spec.rb +22 -10
- data/spec/generators/fx/migration_helper_spec.rb +108 -0
- data/spec/generators/fx/name_helper_spec.rb +114 -0
- data/spec/generators/fx/trigger/trigger_generator_spec.rb +55 -20
- data/spec/generators/fx/version_helper_spec.rb +157 -0
- data/spec/spec_helper.rb +16 -4
- data/spec/support/database_reset.rb +24 -0
- data/spec/support/definition_helpers.rb +5 -9
- data/spec/support/generator_setup.rb +46 -5
- data/spec/support/migration_helpers.rb +9 -1
- data/spec/support/warning_helper.rb +5 -0
- metadata +43 -215
- data/.ruby-version +0 -1
- data/.travis.yml +0 -27
- data/Appraisals +0 -21
- data/bin/appraisal +0 -17
- data/gemfiles/rails40.gemfile +0 -8
- data/gemfiles/rails40.gemfile.lock +0 -111
- data/gemfiles/rails41.gemfile +0 -8
- data/gemfiles/rails41.gemfile.lock +0 -113
- data/gemfiles/rails42.gemfile +0 -8
- data/gemfiles/rails42.gemfile.lock +0 -130
- data/gemfiles/rails50.gemfile +0 -8
- data/gemfiles/rails50.gemfile.lock +0 -126
- 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 -29
- data/lib/fx/schema_dumper/trigger.rb +0 -29
- data/lib/fx/statements/function.rb +0 -105
- data/lib/fx/statements/trigger.rb +0 -133
- data/spec/fx/command_recorder/arguments_spec.rb +0 -41
- data/spec/fx/schema_dumper/function_spec.rb +0 -22
- 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
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: ../
|
|
3
|
-
specs:
|
|
4
|
-
fx (0.1.0)
|
|
5
|
-
activerecord (>= 4.0.0)
|
|
6
|
-
railties (>= 4.0.0)
|
|
7
|
-
|
|
8
|
-
GEM
|
|
9
|
-
remote: https://rubygems.org/
|
|
10
|
-
specs:
|
|
11
|
-
actionpack (4.2.6)
|
|
12
|
-
actionview (= 4.2.6)
|
|
13
|
-
activesupport (= 4.2.6)
|
|
14
|
-
rack (~> 1.6)
|
|
15
|
-
rack-test (~> 0.6.2)
|
|
16
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
17
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
18
|
-
actionview (4.2.6)
|
|
19
|
-
activesupport (= 4.2.6)
|
|
20
|
-
builder (~> 3.1)
|
|
21
|
-
erubis (~> 2.7.0)
|
|
22
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
23
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
24
|
-
activemodel (4.2.6)
|
|
25
|
-
activesupport (= 4.2.6)
|
|
26
|
-
builder (~> 3.1)
|
|
27
|
-
activerecord (4.2.6)
|
|
28
|
-
activemodel (= 4.2.6)
|
|
29
|
-
activesupport (= 4.2.6)
|
|
30
|
-
arel (~> 6.0)
|
|
31
|
-
activesupport (4.2.6)
|
|
32
|
-
i18n (~> 0.7)
|
|
33
|
-
json (~> 1.7, >= 1.7.7)
|
|
34
|
-
minitest (~> 5.1)
|
|
35
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
|
36
|
-
tzinfo (~> 1.1)
|
|
37
|
-
ammeter (1.1.3)
|
|
38
|
-
activesupport (>= 3.0)
|
|
39
|
-
railties (>= 3.0)
|
|
40
|
-
rspec-rails (>= 2.2)
|
|
41
|
-
appraisal (2.1.0)
|
|
42
|
-
bundler
|
|
43
|
-
rake
|
|
44
|
-
thor (>= 0.14.0)
|
|
45
|
-
arel (6.0.3)
|
|
46
|
-
builder (3.2.2)
|
|
47
|
-
coderay (1.1.1)
|
|
48
|
-
database_cleaner (1.5.3)
|
|
49
|
-
diff-lcs (1.2.5)
|
|
50
|
-
erubis (2.7.0)
|
|
51
|
-
i18n (0.7.0)
|
|
52
|
-
json (1.8.3)
|
|
53
|
-
loofah (2.0.3)
|
|
54
|
-
nokogiri (>= 1.5.9)
|
|
55
|
-
method_source (0.8.2)
|
|
56
|
-
mini_portile2 (2.0.0)
|
|
57
|
-
minitest (5.9.0)
|
|
58
|
-
nokogiri (1.6.7.2)
|
|
59
|
-
mini_portile2 (~> 2.0.0.rc2)
|
|
60
|
-
pg (0.18.4)
|
|
61
|
-
pry (0.10.3)
|
|
62
|
-
coderay (~> 1.1.0)
|
|
63
|
-
method_source (~> 0.8.1)
|
|
64
|
-
slop (~> 3.4)
|
|
65
|
-
rack (1.6.4)
|
|
66
|
-
rack-test (0.6.3)
|
|
67
|
-
rack (>= 1.0)
|
|
68
|
-
rails-deprecated_sanitizer (1.0.3)
|
|
69
|
-
activesupport (>= 4.2.0.alpha)
|
|
70
|
-
rails-dom-testing (1.0.7)
|
|
71
|
-
activesupport (>= 4.2.0.beta, < 5.0)
|
|
72
|
-
nokogiri (~> 1.6.0)
|
|
73
|
-
rails-deprecated_sanitizer (>= 1.0.1)
|
|
74
|
-
rails-html-sanitizer (1.0.3)
|
|
75
|
-
loofah (~> 2.0)
|
|
76
|
-
railties (4.2.6)
|
|
77
|
-
actionpack (= 4.2.6)
|
|
78
|
-
activesupport (= 4.2.6)
|
|
79
|
-
rake (>= 0.8.7)
|
|
80
|
-
thor (>= 0.18.1, < 2.0)
|
|
81
|
-
rake (11.1.2)
|
|
82
|
-
redcarpet (3.3.4)
|
|
83
|
-
rspec (3.4.0)
|
|
84
|
-
rspec-core (~> 3.4.0)
|
|
85
|
-
rspec-expectations (~> 3.4.0)
|
|
86
|
-
rspec-mocks (~> 3.4.0)
|
|
87
|
-
rspec-core (3.4.4)
|
|
88
|
-
rspec-support (~> 3.4.0)
|
|
89
|
-
rspec-expectations (3.4.0)
|
|
90
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
91
|
-
rspec-support (~> 3.4.0)
|
|
92
|
-
rspec-mocks (3.4.1)
|
|
93
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
94
|
-
rspec-support (~> 3.4.0)
|
|
95
|
-
rspec-rails (3.4.2)
|
|
96
|
-
actionpack (>= 3.0, < 4.3)
|
|
97
|
-
activesupport (>= 3.0, < 4.3)
|
|
98
|
-
railties (>= 3.0, < 4.3)
|
|
99
|
-
rspec-core (~> 3.4.0)
|
|
100
|
-
rspec-expectations (~> 3.4.0)
|
|
101
|
-
rspec-mocks (~> 3.4.0)
|
|
102
|
-
rspec-support (~> 3.4.0)
|
|
103
|
-
rspec-support (3.4.1)
|
|
104
|
-
slop (3.6.0)
|
|
105
|
-
thor (0.19.1)
|
|
106
|
-
thread_safe (0.3.5)
|
|
107
|
-
tzinfo (1.2.2)
|
|
108
|
-
thread_safe (~> 0.1)
|
|
109
|
-
yard (0.8.7.6)
|
|
110
|
-
|
|
111
|
-
PLATFORMS
|
|
112
|
-
ruby
|
|
113
|
-
|
|
114
|
-
DEPENDENCIES
|
|
115
|
-
activerecord (~> 4.2.0)
|
|
116
|
-
ammeter (>= 1.1.3)
|
|
117
|
-
appraisal
|
|
118
|
-
bundler (>= 1.5)
|
|
119
|
-
database_cleaner
|
|
120
|
-
fx!
|
|
121
|
-
pg
|
|
122
|
-
pry
|
|
123
|
-
railties (~> 4.2.0)
|
|
124
|
-
rake
|
|
125
|
-
redcarpet
|
|
126
|
-
rspec (>= 3.3)
|
|
127
|
-
yard
|
|
128
|
-
|
|
129
|
-
BUNDLED WITH
|
|
130
|
-
1.12.4
|
data/gemfiles/rails50.gemfile
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: ../
|
|
3
|
-
specs:
|
|
4
|
-
fx (0.1.0)
|
|
5
|
-
activerecord (>= 4.0.0)
|
|
6
|
-
railties (>= 4.0.0)
|
|
7
|
-
|
|
8
|
-
GEM
|
|
9
|
-
remote: https://rubygems.org/
|
|
10
|
-
specs:
|
|
11
|
-
actionpack (5.0.0.1)
|
|
12
|
-
actionview (= 5.0.0.1)
|
|
13
|
-
activesupport (= 5.0.0.1)
|
|
14
|
-
rack (~> 2.0)
|
|
15
|
-
rack-test (~> 0.6.3)
|
|
16
|
-
rails-dom-testing (~> 2.0)
|
|
17
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
18
|
-
actionview (5.0.0.1)
|
|
19
|
-
activesupport (= 5.0.0.1)
|
|
20
|
-
builder (~> 3.1)
|
|
21
|
-
erubis (~> 2.7.0)
|
|
22
|
-
rails-dom-testing (~> 2.0)
|
|
23
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
24
|
-
activemodel (5.0.0.1)
|
|
25
|
-
activesupport (= 5.0.0.1)
|
|
26
|
-
activerecord (5.0.0.1)
|
|
27
|
-
activemodel (= 5.0.0.1)
|
|
28
|
-
activesupport (= 5.0.0.1)
|
|
29
|
-
arel (~> 7.0)
|
|
30
|
-
activesupport (5.0.0.1)
|
|
31
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
32
|
-
i18n (~> 0.7)
|
|
33
|
-
minitest (~> 5.1)
|
|
34
|
-
tzinfo (~> 1.1)
|
|
35
|
-
ammeter (1.1.3)
|
|
36
|
-
activesupport (>= 3.0)
|
|
37
|
-
railties (>= 3.0)
|
|
38
|
-
rspec-rails (>= 2.2)
|
|
39
|
-
appraisal (2.1.0)
|
|
40
|
-
bundler
|
|
41
|
-
rake
|
|
42
|
-
thor (>= 0.14.0)
|
|
43
|
-
arel (7.1.4)
|
|
44
|
-
builder (3.2.2)
|
|
45
|
-
coderay (1.1.1)
|
|
46
|
-
concurrent-ruby (1.0.2)
|
|
47
|
-
database_cleaner (1.5.3)
|
|
48
|
-
diff-lcs (1.2.5)
|
|
49
|
-
erubis (2.7.0)
|
|
50
|
-
i18n (0.7.0)
|
|
51
|
-
loofah (2.0.3)
|
|
52
|
-
nokogiri (>= 1.5.9)
|
|
53
|
-
method_source (0.8.2)
|
|
54
|
-
mini_portile2 (2.1.0)
|
|
55
|
-
minitest (5.9.1)
|
|
56
|
-
nokogiri (1.6.8.1)
|
|
57
|
-
mini_portile2 (~> 2.1.0)
|
|
58
|
-
pg (0.18.4)
|
|
59
|
-
pry (0.10.3)
|
|
60
|
-
coderay (~> 1.1.0)
|
|
61
|
-
method_source (~> 0.8.1)
|
|
62
|
-
slop (~> 3.4)
|
|
63
|
-
rack (2.0.1)
|
|
64
|
-
rack-test (0.6.3)
|
|
65
|
-
rack (>= 1.0)
|
|
66
|
-
rails-dom-testing (2.0.1)
|
|
67
|
-
activesupport (>= 4.2.0, < 6.0)
|
|
68
|
-
nokogiri (~> 1.6.0)
|
|
69
|
-
rails-html-sanitizer (1.0.3)
|
|
70
|
-
loofah (~> 2.0)
|
|
71
|
-
railties (5.0.0.1)
|
|
72
|
-
actionpack (= 5.0.0.1)
|
|
73
|
-
activesupport (= 5.0.0.1)
|
|
74
|
-
method_source
|
|
75
|
-
rake (>= 0.8.7)
|
|
76
|
-
thor (>= 0.18.1, < 2.0)
|
|
77
|
-
rake (11.2.2)
|
|
78
|
-
redcarpet (3.3.4)
|
|
79
|
-
rspec (3.5.0)
|
|
80
|
-
rspec-core (~> 3.5.0)
|
|
81
|
-
rspec-expectations (~> 3.5.0)
|
|
82
|
-
rspec-mocks (~> 3.5.0)
|
|
83
|
-
rspec-core (3.5.4)
|
|
84
|
-
rspec-support (~> 3.5.0)
|
|
85
|
-
rspec-expectations (3.5.0)
|
|
86
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
87
|
-
rspec-support (~> 3.5.0)
|
|
88
|
-
rspec-mocks (3.5.0)
|
|
89
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
90
|
-
rspec-support (~> 3.5.0)
|
|
91
|
-
rspec-rails (3.5.2)
|
|
92
|
-
actionpack (>= 3.0)
|
|
93
|
-
activesupport (>= 3.0)
|
|
94
|
-
railties (>= 3.0)
|
|
95
|
-
rspec-core (~> 3.5.0)
|
|
96
|
-
rspec-expectations (~> 3.5.0)
|
|
97
|
-
rspec-mocks (~> 3.5.0)
|
|
98
|
-
rspec-support (~> 3.5.0)
|
|
99
|
-
rspec-support (3.5.0)
|
|
100
|
-
slop (3.6.0)
|
|
101
|
-
thor (0.19.1)
|
|
102
|
-
thread_safe (0.3.5)
|
|
103
|
-
tzinfo (1.2.2)
|
|
104
|
-
thread_safe (~> 0.1)
|
|
105
|
-
yard (0.8.7.6)
|
|
106
|
-
|
|
107
|
-
PLATFORMS
|
|
108
|
-
ruby
|
|
109
|
-
|
|
110
|
-
DEPENDENCIES
|
|
111
|
-
activerecord (~> 5.0)
|
|
112
|
-
ammeter (>= 1.1.3)
|
|
113
|
-
appraisal
|
|
114
|
-
bundler (>= 1.5)
|
|
115
|
-
database_cleaner
|
|
116
|
-
fx!
|
|
117
|
-
pg
|
|
118
|
-
pry
|
|
119
|
-
railties (~> 5.0)
|
|
120
|
-
rake
|
|
121
|
-
redcarpet
|
|
122
|
-
rspec (>= 3.3)
|
|
123
|
-
yard
|
|
124
|
-
|
|
125
|
-
BUNDLED WITH
|
|
126
|
-
1.13.3
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module Fx
|
|
2
|
-
module CommandRecorder
|
|
3
|
-
# @api private
|
|
4
|
-
class Arguments
|
|
5
|
-
def initialize(args)
|
|
6
|
-
@args = args.freeze
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def function
|
|
10
|
-
@args[0]
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def version
|
|
14
|
-
options[:version]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def revert_to_version
|
|
18
|
-
options[:revert_to_version]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def invert_version
|
|
22
|
-
Arguments.new([function, options_for_revert])
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def to_a
|
|
26
|
-
@args.to_a
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
def options
|
|
32
|
-
@options ||= @args[1] || {}
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def options_for_revert
|
|
36
|
-
options.clone.tap do |revert_options|
|
|
37
|
-
revert_options[:version] = revert_to_version
|
|
38
|
-
revert_options.delete(:revert_to_version)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module Fx
|
|
2
|
-
module CommandRecorder
|
|
3
|
-
# @api private
|
|
4
|
-
module Function
|
|
5
|
-
def create_function(*args)
|
|
6
|
-
record(:create_function, args)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def drop_function(*args)
|
|
10
|
-
record(:drop_function, args)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def update_function(*args)
|
|
14
|
-
record(:update_function, args)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def invert_create_function(args)
|
|
18
|
-
[:drop_function, args]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def invert_drop_function(args)
|
|
22
|
-
perform_inversion(:create_function, args)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def invert_update_function(args)
|
|
26
|
-
perform_inversion(:update_function, args)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module Fx
|
|
2
|
-
module CommandRecorder
|
|
3
|
-
# @api private
|
|
4
|
-
module Trigger
|
|
5
|
-
def create_trigger(*args)
|
|
6
|
-
record(:create_trigger, args)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def drop_trigger(*args)
|
|
10
|
-
record(:drop_trigger, args)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def update_trigger(*args)
|
|
14
|
-
record(:update_trigger, args)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def invert_create_trigger(args)
|
|
18
|
-
[:drop_trigger, args]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def invert_drop_trigger(args)
|
|
22
|
-
perform_inversion(:create_trigger, args)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def invert_update_trigger(args)
|
|
26
|
-
perform_inversion(:update_trigger, args)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
require "rails"
|
|
2
|
-
|
|
3
|
-
module Fx
|
|
4
|
-
module SchemaDumper
|
|
5
|
-
# @api private
|
|
6
|
-
module Function
|
|
7
|
-
def tables(stream)
|
|
8
|
-
super
|
|
9
|
-
functions(stream)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def functions(stream)
|
|
13
|
-
if dumpable_functions_in_database.any?
|
|
14
|
-
stream.puts
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
dumpable_functions_in_database.each do |function|
|
|
18
|
-
stream.puts(function.to_schema)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def dumpable_functions_in_database
|
|
25
|
-
@_dumpable_functions_in_database ||= Fx.database.functions
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
require "rails"
|
|
2
|
-
|
|
3
|
-
module Fx
|
|
4
|
-
module SchemaDumper
|
|
5
|
-
# @api private
|
|
6
|
-
module Trigger
|
|
7
|
-
def tables(stream)
|
|
8
|
-
super
|
|
9
|
-
triggers(stream)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def triggers(stream)
|
|
13
|
-
if dumpable_triggers_in_database.any?
|
|
14
|
-
stream.puts
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
dumpable_triggers_in_database.each do |trigger|
|
|
18
|
-
stream.puts(trigger.to_schema)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def dumpable_triggers_in_database
|
|
25
|
-
@_dumpable_triggers_in_database ||= Fx.database.triggers
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
require "rails"
|
|
2
|
-
|
|
3
|
-
module Fx
|
|
4
|
-
module Statements
|
|
5
|
-
# Methods that are made available in migrations for managing Fx functions.
|
|
6
|
-
module Function
|
|
7
|
-
# Create a new database function.
|
|
8
|
-
#
|
|
9
|
-
# @param name [String, Symbol] The name of the database function.
|
|
10
|
-
# @param version [Fixnum] The version number of the function, used to
|
|
11
|
-
# find the definition file in `db/functions`. This defaults to `1` if
|
|
12
|
-
# not provided.
|
|
13
|
-
# @param sql_definition [String] The SQL query for the function schema.
|
|
14
|
-
# If both `sql_defintion` and `version` are provided,
|
|
15
|
-
# `sql_definition` takes prescedence.
|
|
16
|
-
# @return The database response from executing the create statement.
|
|
17
|
-
#
|
|
18
|
-
# @example Create from `db/functions/uppercase_users_name_v02.sql`
|
|
19
|
-
# create_function(:uppercase_users_name, version: 2)
|
|
20
|
-
#
|
|
21
|
-
# @example Create from provided SQL string
|
|
22
|
-
# create_function(:uppercase_users_name, sql_definition: <<-SQL)
|
|
23
|
-
# CREATE OR REPLACE FUNCTION uppercase_users_name()
|
|
24
|
-
# RETURNS trigger AS $$
|
|
25
|
-
# BEGIN
|
|
26
|
-
# NEW.upper_name = UPPER(NEW.name);
|
|
27
|
-
# RETURN NEW;
|
|
28
|
-
# END;
|
|
29
|
-
# $$ LANGUAGE plpgsql;
|
|
30
|
-
# SQL
|
|
31
|
-
#
|
|
32
|
-
def create_function(name, version: 1, sql_definition: nil)
|
|
33
|
-
if version.nil? && sql_definition.nil?
|
|
34
|
-
raise(
|
|
35
|
-
ArgumentError,
|
|
36
|
-
"version or sql_definition must be specified",
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
sql_definition ||= Fx::Definition.new(name: name, version: version).to_sql
|
|
40
|
-
|
|
41
|
-
Fx.database.create_function(sql_definition)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Drop a database function by name.
|
|
45
|
-
#
|
|
46
|
-
# @param name [String, Symbol] The name of the database function.
|
|
47
|
-
# @param revert_to_version [Fixnum] Used to reverse the `drop_function`
|
|
48
|
-
# command on `rake db:rollback`. The provided version will be passed as
|
|
49
|
-
# the `version` argument to {#create_function}.
|
|
50
|
-
# @return The database response from executing the drop statement.
|
|
51
|
-
#
|
|
52
|
-
# @example Drop a function, rolling back to version 3 on rollback
|
|
53
|
-
# drop_function(:uppercase_users_name, on: :users, revert_to_version: 3)
|
|
54
|
-
#
|
|
55
|
-
def drop_function(name, revert_to_version: nil)
|
|
56
|
-
Fx.database.drop_function(name)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# Update a database function.
|
|
60
|
-
#
|
|
61
|
-
# @param name [String, Symbol] The name of the database function.
|
|
62
|
-
# @param version [Fixnum] The version number of the function, used to
|
|
63
|
-
# find the definition file in `db/functions`. This defaults to `1` if
|
|
64
|
-
# not provided.
|
|
65
|
-
# @param sql_definition [String] The SQL query for the function schema.
|
|
66
|
-
# If both `sql_defintion` and `version` are provided,
|
|
67
|
-
# `sql_definition` takes prescedence.
|
|
68
|
-
# @return The database response from executing the create statement.
|
|
69
|
-
#
|
|
70
|
-
# @example Update function to a given version
|
|
71
|
-
# update_function(
|
|
72
|
-
# :uppercase_users_name,
|
|
73
|
-
# version: 3,
|
|
74
|
-
# revert_to_version: 2,
|
|
75
|
-
# )
|
|
76
|
-
#
|
|
77
|
-
# @example Update function from provided SQL string
|
|
78
|
-
# update_function(:uppercase_users_name, sql_definition: <<-SQL)
|
|
79
|
-
# CREATE OR REPLACE FUNCTION uppercase_users_name()
|
|
80
|
-
# RETURNS trigger AS $$
|
|
81
|
-
# BEGIN
|
|
82
|
-
# NEW.upper_name = UPPER(NEW.name);
|
|
83
|
-
# RETURN NEW;
|
|
84
|
-
# END;
|
|
85
|
-
# $$ LANGUAGE plpgsql;
|
|
86
|
-
# SQL
|
|
87
|
-
#
|
|
88
|
-
def update_function(name, version: nil, sql_definition: nil, revert_to_version: nil)
|
|
89
|
-
if version.nil? && sql_definition.nil?
|
|
90
|
-
raise(
|
|
91
|
-
ArgumentError,
|
|
92
|
-
"version or sql_definition must be specified",
|
|
93
|
-
)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
sql_definition ||= Fx::Definition.new(
|
|
97
|
-
name: name,
|
|
98
|
-
version: version,
|
|
99
|
-
).to_sql
|
|
100
|
-
|
|
101
|
-
Fx.database.update_function(name, sql_definition)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
module Fx
|
|
2
|
-
module Statements
|
|
3
|
-
# Methods that are made available in migrations for managing Fx triggers.
|
|
4
|
-
module Trigger
|
|
5
|
-
# @api private
|
|
6
|
-
DEFINTION_TYPE = "trigger".freeze
|
|
7
|
-
|
|
8
|
-
# Create a new database trigger.
|
|
9
|
-
#
|
|
10
|
-
# @param name [String, Symbol] The name of the database trigger.
|
|
11
|
-
# @param version [Fixnum] The version number of the trigger, used to
|
|
12
|
-
# find the definition file in `db/triggers`. This defaults to `1` if
|
|
13
|
-
# not provided.
|
|
14
|
-
# @param sql_definition [String] The SQL query for the function. An error
|
|
15
|
-
# will be raised if `sql_definition` and `version` are both set,
|
|
16
|
-
# as they are mutually exclusive.
|
|
17
|
-
# @return The database response from executing the create statement.
|
|
18
|
-
#
|
|
19
|
-
# @example Create trigger from `db/triggers/uppercase_users_name_v01.sql`
|
|
20
|
-
# create_trigger(:uppercase_users_name, version: 1)
|
|
21
|
-
#
|
|
22
|
-
# @example Create trigger from provided SQL string
|
|
23
|
-
# create_trigger(:uppercase_users_name, sql_definition: <<-SQL)
|
|
24
|
-
# CREATE TRIGGER uppercase_users_name
|
|
25
|
-
# BEFORE INSERT ON users
|
|
26
|
-
# FOR EACH ROW
|
|
27
|
-
# EXECUTE PROCEDURE uppercase_users_name();
|
|
28
|
-
# SQL
|
|
29
|
-
#
|
|
30
|
-
def create_trigger(name, version: nil, on: nil, sql_definition: nil)
|
|
31
|
-
if version.present? && sql_definition.present?
|
|
32
|
-
raise(
|
|
33
|
-
ArgumentError,
|
|
34
|
-
"sql_definition and version cannot both be set",
|
|
35
|
-
)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
if version.nil?
|
|
39
|
-
version = 1
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
sql_definition ||= Fx::Definition.new(
|
|
43
|
-
name: name,
|
|
44
|
-
version: version,
|
|
45
|
-
type: DEFINTION_TYPE,
|
|
46
|
-
).to_sql
|
|
47
|
-
|
|
48
|
-
Fx.database.create_trigger(sql_definition)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Drop a database trigger by name.
|
|
52
|
-
#
|
|
53
|
-
# @param name [String, Symbol] The name of the database trigger.
|
|
54
|
-
# @param on [String, Symbol] The name of the table the database trigger
|
|
55
|
-
# is associated with.
|
|
56
|
-
# @param revert_to_version [Fixnum] Used to reverse the `drop_trigger`
|
|
57
|
-
# command on `rake db:rollback`. The provided version will be passed as
|
|
58
|
-
# the `version` argument to {#create_trigger}.
|
|
59
|
-
# @return The database response from executing the drop statement.
|
|
60
|
-
#
|
|
61
|
-
# @example Drop a trigger, rolling back to version 3 on rollback
|
|
62
|
-
# drop_trigger(:log_inserts, on: :users, revert_to_version: 3)
|
|
63
|
-
#
|
|
64
|
-
def drop_trigger(name, on:, revert_to_version: nil)
|
|
65
|
-
Fx.database.drop_trigger(name, on: on)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# Update a database trigger to a new version.
|
|
69
|
-
#
|
|
70
|
-
# The existing trigger is dropped and recreated using the supplied `on`
|
|
71
|
-
# and `version` parameter.
|
|
72
|
-
#
|
|
73
|
-
# @param name [String, Symbol] The name of the database trigger.
|
|
74
|
-
# @param version [Fixnum] The version number of the trigger.
|
|
75
|
-
# @param on [String, Symbol] The name of the table the database trigger
|
|
76
|
-
# is associated with.
|
|
77
|
-
# @param sql_definition [String] The SQL query for the function. An error
|
|
78
|
-
# will be raised if `sql_definition` and `version` are both set,
|
|
79
|
-
# as they are mutually exclusive.
|
|
80
|
-
# @param revert_to_version [Fixnum] The version number to rollback to on
|
|
81
|
-
# `rake db rollback`
|
|
82
|
-
# @return The database response from executing the create statement.
|
|
83
|
-
#
|
|
84
|
-
# @example Update trigger to a given version
|
|
85
|
-
# update_trigger(
|
|
86
|
-
# :log_inserts,
|
|
87
|
-
# on: :users,
|
|
88
|
-
# version: 3,
|
|
89
|
-
# revert_to_version: 2,
|
|
90
|
-
# )
|
|
91
|
-
#
|
|
92
|
-
# @example Update trigger from provided SQL string
|
|
93
|
-
# update_trigger(:uppercase_users_name, sql_definition: <<-SQL)
|
|
94
|
-
# CREATE TRIGGER uppercase_users_name
|
|
95
|
-
# BEFORE INSERT ON users
|
|
96
|
-
# FOR EACH ROW
|
|
97
|
-
# EXECUTE PROCEDURE uppercase_users_name();
|
|
98
|
-
# SQL
|
|
99
|
-
#
|
|
100
|
-
def update_trigger(name, version: nil, on: nil, sql_definition: nil, revert_to_version: nil)
|
|
101
|
-
if version.nil? && sql_definition.nil?
|
|
102
|
-
raise(
|
|
103
|
-
ArgumentError,
|
|
104
|
-
"version or sql_definition must be specified",
|
|
105
|
-
)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
if version.present? && sql_definition.present?
|
|
109
|
-
raise(
|
|
110
|
-
ArgumentError,
|
|
111
|
-
"sql_definition and version cannot both be set",
|
|
112
|
-
)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
if on.nil?
|
|
116
|
-
raise ArgumentError, "on is required"
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
sql_definition ||= Fx::Definition.new(
|
|
120
|
-
name: name,
|
|
121
|
-
version: version,
|
|
122
|
-
type: DEFINTION_TYPE,
|
|
123
|
-
).to_sql
|
|
124
|
-
|
|
125
|
-
Fx.database.update_trigger(
|
|
126
|
-
name,
|
|
127
|
-
on: on,
|
|
128
|
-
sql_definition: sql_definition,
|
|
129
|
-
)
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
module Fx::CommandRecorder
|
|
4
|
-
describe Arguments do
|
|
5
|
-
describe "#function" do
|
|
6
|
-
it "returns the function name" do
|
|
7
|
-
raw_args = [:spaceships, { foo: :bar }]
|
|
8
|
-
args = Arguments.new(raw_args)
|
|
9
|
-
|
|
10
|
-
expect(args.function).to eq :spaceships
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "#revert_to_version" do
|
|
15
|
-
it "is the revert_to_version from the keyword arguments" do
|
|
16
|
-
raw_args = [:spaceships, { revert_to_version: 42 }]
|
|
17
|
-
args = Arguments.new(raw_args)
|
|
18
|
-
|
|
19
|
-
expect(args.revert_to_version).to eq 42
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "is nil if the revert_to_version was not supplied" do
|
|
23
|
-
raw_args = [:spaceships, { foo: :bar }]
|
|
24
|
-
args = Arguments.new(raw_args)
|
|
25
|
-
|
|
26
|
-
expect(args.revert_to_version).to be nil
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe "#invert_version" do
|
|
31
|
-
it "returns object with version set to revert_to_version" do
|
|
32
|
-
raw_args = [:meatballs, { version: 42, revert_to_version: 15 }]
|
|
33
|
-
|
|
34
|
-
inverted_args = Arguments.new(raw_args).invert_version
|
|
35
|
-
|
|
36
|
-
expect(inverted_args.version).to eq 15
|
|
37
|
-
expect(inverted_args.revert_to_version).to be nil
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|