fx 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +27 -0
  6. data/.yardopts +4 -0
  7. data/Appraisals +21 -0
  8. data/CONTRIBUTING.md +15 -0
  9. data/Gemfile +4 -0
  10. data/README.md +81 -0
  11. data/Rakefile +23 -0
  12. data/bin/appraisal +17 -0
  13. data/bin/console +14 -0
  14. data/bin/rake +17 -0
  15. data/bin/rspec +17 -0
  16. data/bin/setup +12 -0
  17. data/bin/yard +17 -0
  18. data/fx.gemspec +38 -0
  19. data/gemfiles/rails40.gemfile +8 -0
  20. data/gemfiles/rails40.gemfile.lock +111 -0
  21. data/gemfiles/rails41.gemfile +8 -0
  22. data/gemfiles/rails41.gemfile.lock +113 -0
  23. data/gemfiles/rails42.gemfile +8 -0
  24. data/gemfiles/rails42.gemfile.lock +130 -0
  25. data/gemfiles/rails50.gemfile +8 -0
  26. data/gemfiles/rails50.gemfile.lock +126 -0
  27. data/lib/fx.rb +21 -0
  28. data/lib/fx/adapters/postgres.rb +142 -0
  29. data/lib/fx/adapters/postgres/connection.rb +16 -0
  30. data/lib/fx/adapters/postgres/functions.rb +55 -0
  31. data/lib/fx/adapters/postgres/triggers.rb +56 -0
  32. data/lib/fx/command_recorder.rb +29 -0
  33. data/lib/fx/command_recorder/arguments.rb +43 -0
  34. data/lib/fx/command_recorder/function.rb +30 -0
  35. data/lib/fx/command_recorder/trigger.rb +30 -0
  36. data/lib/fx/configuration.rb +38 -0
  37. data/lib/fx/definition.rb +36 -0
  38. data/lib/fx/function.rb +24 -0
  39. data/lib/fx/schema_dumper.rb +15 -0
  40. data/lib/fx/schema_dumper/function.rb +29 -0
  41. data/lib/fx/schema_dumper/trigger.rb +29 -0
  42. data/lib/fx/statements.rb +16 -0
  43. data/lib/fx/statements/function.rb +105 -0
  44. data/lib/fx/statements/trigger.rb +133 -0
  45. data/lib/fx/trigger.rb +24 -0
  46. data/lib/fx/version.rb +4 -0
  47. data/lib/generators.rb +11 -0
  48. data/lib/generators/fx/function/USAGE +9 -0
  49. data/lib/generators/fx/function/function_generator.rb +98 -0
  50. data/lib/generators/fx/function/templates/db/migrate/create_function.erb +5 -0
  51. data/lib/generators/fx/function/templates/db/migrate/update_function.erb +5 -0
  52. data/lib/generators/fx/trigger/USAGE +18 -0
  53. data/lib/generators/fx/trigger/templates/db/migrate/create_trigger.erb +5 -0
  54. data/lib/generators/fx/trigger/templates/db/migrate/update_trigger.erb +5 -0
  55. data/lib/generators/fx/trigger/trigger_generator.rb +108 -0
  56. data/spec/acceptance/user_manages_functions_spec.rb +37 -0
  57. data/spec/acceptance/user_manages_triggers_spec.rb +51 -0
  58. data/spec/acceptance_helper.rb +61 -0
  59. data/spec/dummy/.gitignore +16 -0
  60. data/spec/dummy/Rakefile +6 -0
  61. data/spec/dummy/bin/bundle +3 -0
  62. data/spec/dummy/bin/rails +4 -0
  63. data/spec/dummy/bin/rake +4 -0
  64. data/spec/dummy/config.ru +4 -0
  65. data/spec/dummy/config/application.rb +15 -0
  66. data/spec/dummy/config/boot.rb +5 -0
  67. data/spec/dummy/config/database.yml +9 -0
  68. data/spec/dummy/config/environment.rb +5 -0
  69. data/spec/dummy/db/migrate/.keep +0 -0
  70. data/spec/features/functions/migrations_spec.rb +65 -0
  71. data/spec/features/functions/revert_spec.rb +75 -0
  72. data/spec/features/triggers/migrations_spec.rb +56 -0
  73. data/spec/features/triggers/revert_spec.rb +95 -0
  74. data/spec/fx/adapters/postgres_spec.rb +149 -0
  75. data/spec/fx/command_recorder/arguments_spec.rb +41 -0
  76. data/spec/fx/command_recorder_spec.rb +171 -0
  77. data/spec/fx/configuration_spec.rb +21 -0
  78. data/spec/fx/definition_spec.rb +111 -0
  79. data/spec/fx/schema_dumper/function_spec.rb +22 -0
  80. data/spec/fx/schema_dumper/trigger_spec.rb +40 -0
  81. data/spec/fx/statements/function_spec.rb +103 -0
  82. data/spec/fx/statements/trigger_spec.rb +132 -0
  83. data/spec/generators/fx/function/function_generator_spec.rb +34 -0
  84. data/spec/generators/fx/trigger/trigger_generator_spec.rb +47 -0
  85. data/spec/spec_helper.rb +21 -0
  86. data/spec/support/definition_helpers.rb +37 -0
  87. data/spec/support/generator_setup.rb +11 -0
  88. data/spec/support/migration_helpers.rb +17 -0
  89. metadata +334 -0
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.1.0"
6
+ gem "railties", "~> 4.1.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,113 @@
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.1.15)
12
+ actionview (= 4.1.15)
13
+ activesupport (= 4.1.15)
14
+ rack (~> 1.5.2)
15
+ rack-test (~> 0.6.2)
16
+ actionview (4.1.15)
17
+ activesupport (= 4.1.15)
18
+ builder (~> 3.1)
19
+ erubis (~> 2.7.0)
20
+ activemodel (4.1.15)
21
+ activesupport (= 4.1.15)
22
+ builder (~> 3.1)
23
+ activerecord (4.1.15)
24
+ activemodel (= 4.1.15)
25
+ activesupport (= 4.1.15)
26
+ arel (~> 5.0.0)
27
+ activesupport (4.1.15)
28
+ i18n (~> 0.6, >= 0.6.9)
29
+ json (~> 1.7, >= 1.7.7)
30
+ minitest (~> 5.1)
31
+ thread_safe (~> 0.1)
32
+ tzinfo (~> 1.1)
33
+ ammeter (1.1.3)
34
+ activesupport (>= 3.0)
35
+ railties (>= 3.0)
36
+ rspec-rails (>= 2.2)
37
+ appraisal (2.1.0)
38
+ bundler
39
+ rake
40
+ thor (>= 0.14.0)
41
+ arel (5.0.1.20140414130214)
42
+ builder (3.2.2)
43
+ coderay (1.1.1)
44
+ database_cleaner (1.5.3)
45
+ diff-lcs (1.2.5)
46
+ erubis (2.7.0)
47
+ i18n (0.7.0)
48
+ json (1.8.3)
49
+ method_source (0.8.2)
50
+ minitest (5.9.0)
51
+ pg (0.18.4)
52
+ pry (0.10.3)
53
+ coderay (~> 1.1.0)
54
+ method_source (~> 0.8.1)
55
+ slop (~> 3.4)
56
+ rack (1.5.5)
57
+ rack-test (0.6.3)
58
+ rack (>= 1.0)
59
+ railties (4.1.15)
60
+ actionpack (= 4.1.15)
61
+ activesupport (= 4.1.15)
62
+ rake (>= 0.8.7)
63
+ thor (>= 0.18.1, < 2.0)
64
+ rake (11.1.2)
65
+ redcarpet (3.3.4)
66
+ rspec (3.4.0)
67
+ rspec-core (~> 3.4.0)
68
+ rspec-expectations (~> 3.4.0)
69
+ rspec-mocks (~> 3.4.0)
70
+ rspec-core (3.4.4)
71
+ rspec-support (~> 3.4.0)
72
+ rspec-expectations (3.4.0)
73
+ diff-lcs (>= 1.2.0, < 2.0)
74
+ rspec-support (~> 3.4.0)
75
+ rspec-mocks (3.4.1)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.4.0)
78
+ rspec-rails (3.4.2)
79
+ actionpack (>= 3.0, < 4.3)
80
+ activesupport (>= 3.0, < 4.3)
81
+ railties (>= 3.0, < 4.3)
82
+ rspec-core (~> 3.4.0)
83
+ rspec-expectations (~> 3.4.0)
84
+ rspec-mocks (~> 3.4.0)
85
+ rspec-support (~> 3.4.0)
86
+ rspec-support (3.4.1)
87
+ slop (3.6.0)
88
+ thor (0.19.1)
89
+ thread_safe (0.3.5)
90
+ tzinfo (1.2.2)
91
+ thread_safe (~> 0.1)
92
+ yard (0.8.7.6)
93
+
94
+ PLATFORMS
95
+ ruby
96
+
97
+ DEPENDENCIES
98
+ activerecord (~> 4.1.0)
99
+ ammeter (>= 1.1.3)
100
+ appraisal
101
+ bundler (>= 1.5)
102
+ database_cleaner
103
+ fx!
104
+ pg
105
+ pry
106
+ railties (~> 4.1.0)
107
+ rake
108
+ redcarpet
109
+ rspec (>= 3.3)
110
+ yard
111
+
112
+ BUNDLED WITH
113
+ 1.12.4
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.0"
6
+ gem "railties", "~> 4.2.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,130 @@
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
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.0"
6
+ gem "railties", "~> 5.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,126 @@
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
@@ -0,0 +1,21 @@
1
+ require "fx/version"
2
+ require "fx/adapters/postgres"
3
+ require "fx/command_recorder"
4
+ require "fx/configuration"
5
+ require "fx/definition"
6
+ require "fx/function"
7
+ require "fx/statements"
8
+ require "fx/schema_dumper"
9
+ require "fx/trigger"
10
+
11
+ # F(x) adds methods `ActiveRecord::Migration` to create and manage database
12
+ # triggers and functions in Rails applications.
13
+ module Fx
14
+ # The current database adapter used by F(x).
15
+ #
16
+ # This defaults to {Fx::Adapters::Postgres} but can be overridden
17
+ # via {Configuration}.
18
+ def self.database
19
+ configuration.database
20
+ end
21
+ end
@@ -0,0 +1,142 @@
1
+ require "fx/adapters/postgres/connection"
2
+ require "fx/adapters/postgres/functions"
3
+ require "fx/adapters/postgres/triggers"
4
+
5
+ module Fx
6
+ # F(x) database adapters.
7
+ #
8
+ # F(x) ships with a Postgres adapter only but can be extended with
9
+ # additional adapters. The {Fx::Adapters::Postgres} adapter provides the
10
+ # interface.
11
+ module Adapters
12
+ # Creates an instance of the F(x) Postgres adapter.
13
+ #
14
+ # This is the default adapter for F(x). Configuring it via
15
+ # {Fx.configure} is not required, but the example below shows how one
16
+ # would explicitly set it.
17
+ #
18
+ # @param [#connection] connectable An object that returns the connection
19
+ # for F(x) to use. Defaults to `ActiveRecord::Base`.
20
+ #
21
+ # @example
22
+ # Fx.configure do |config|
23
+ # config.adapter = Fx::Adapters::Postgres.new
24
+ # end
25
+ class Postgres
26
+ def initialize(connectable = ActiveRecord::Base)
27
+ @connectable = connectable
28
+ end
29
+
30
+ # Returns an array of functions in the database.
31
+ #
32
+ # This collection of functions is used by the [Fx::SchemaDumper] to
33
+ # populate the `schema.rb` file.
34
+ #
35
+ # @return [Array<Fx::Function>]
36
+ def functions
37
+ Functions.all(connection)
38
+ end
39
+
40
+ # Returns an array of triggers in the database.
41
+ #
42
+ # This collection of triggers is used by the [Fx::SchemaDumper] to
43
+ # populate the `schema.rb` file.
44
+ #
45
+ # @return [Array<Fx::Trigger>]
46
+ def triggers
47
+ Triggers.all(connection)
48
+ end
49
+
50
+ # Creates a function in the database.
51
+ #
52
+ # This is typically called in a migration via
53
+ # {Fx::Statements::Function#create_function}.
54
+ #
55
+ # @param sql_definition The SQL schema for the function.
56
+ #
57
+ # @return [void]
58
+ def create_function(sql_definition)
59
+ execute sql_definition
60
+ end
61
+
62
+ # Creates a trigger in the database.
63
+ #
64
+ # This is typically called in a migration via
65
+ # {Fx::Statements::Trigger#create_trigger}.
66
+ #
67
+ # @param sql_definition The SQL schema for the trigger.
68
+ #
69
+ # @return [void]
70
+ def create_trigger(sql_definition)
71
+ execute sql_definition
72
+ end
73
+
74
+ # Updates a function in the database.
75
+ #
76
+ # This is typically called in a migration via
77
+ # {Fx::Statements::Function#update_function}.
78
+ #
79
+ # @param name The name of the function.
80
+ # @param sql_definition The SQL schema for the function.
81
+ #
82
+ # @return [void]
83
+ def update_function(name, sql_definition)
84
+ drop_function(name)
85
+ create_function(sql_definition)
86
+ end
87
+
88
+ # Updates a trigger in the database.
89
+ #
90
+ # The existing trigger is dropped and recreated using the supplied `on`
91
+ # and `version` parameter.
92
+ #
93
+ # This is typically called in a migration via
94
+ # {Fx::Statements::Function#update_trigger}.
95
+ #
96
+ # @param name The name of the trigger.
97
+ # @param on The associated table for the trigger to drop
98
+ # @param sql_definition The SQL schema for the function.
99
+ #
100
+ # @return [void]
101
+ def update_trigger(name, on:, sql_definition:)
102
+ drop_trigger(name, on: on)
103
+ create_trigger(sql_definition)
104
+ end
105
+
106
+ # Drops the function from the database
107
+ #
108
+ # This is typically called in a migration via
109
+ # {Fx::Statements::Function#drop_function}.
110
+ #
111
+ # @param name The name of the function to drop
112
+ #
113
+ # @return [void]
114
+ def drop_function(name)
115
+ execute "DROP FUNCTION #{name}();"
116
+ end
117
+
118
+ # Drops the trigger from the database
119
+ #
120
+ # This is typically called in a migration via
121
+ # {Fx::Statements::Trigger#drop_trigger}.
122
+ #
123
+ # @param name The name of the trigger to drop
124
+ # @param on The associated table for the trigger to drop
125
+ #
126
+ # @return [void]
127
+ def drop_trigger(name, on:)
128
+ execute "DROP TRIGGER #{name} ON #{on};"
129
+ end
130
+
131
+ private
132
+
133
+ attr_reader :connectable
134
+
135
+ delegate :execute, to: :connection
136
+
137
+ def connection
138
+ Connection.new(connectable.connection)
139
+ end
140
+ end
141
+ end
142
+ end