pg_trunk 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -15
- data/CHANGELOG.md +21 -0
- data/README.md +3 -1
- data/lib/pg_trunk/core/operation/attributes.rb +1 -1
- data/lib/pg_trunk/core/railtie/custom_types.rb +5 -6
- data/lib/pg_trunk/operations/check_constraints/add_check_constraint.rb +42 -33
- data/lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb +51 -40
- data/lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb +39 -30
- data/lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb +28 -21
- data/lib/pg_trunk/operations/composite_types/change_composite_type.rb +59 -50
- data/lib/pg_trunk/operations/composite_types/create_composite_type.rb +23 -19
- data/lib/pg_trunk/operations/composite_types/drop_composite_type.rb +48 -43
- data/lib/pg_trunk/operations/composite_types/rename_composite_type.rb +15 -12
- data/lib/pg_trunk/operations/domains/change_domain.rb +53 -47
- data/lib/pg_trunk/operations/domains/create_domain.rb +28 -25
- data/lib/pg_trunk/operations/domains/drop_domain.rb +50 -41
- data/lib/pg_trunk/operations/domains/rename_domain.rb +17 -12
- data/lib/pg_trunk/operations/enums/change_enum.rb +37 -32
- data/lib/pg_trunk/operations/enums/create_enum.rb +23 -20
- data/lib/pg_trunk/operations/enums/drop_enum.rb +50 -39
- data/lib/pg_trunk/operations/enums/rename_enum.rb +17 -12
- data/lib/pg_trunk/operations/foreign_keys/add_foreign_key.rb +58 -49
- data/lib/pg_trunk/operations/foreign_keys/drop_foreign_key.rb +57 -48
- data/lib/pg_trunk/operations/foreign_keys/rename_foreign_key.rb +38 -29
- data/lib/pg_trunk/operations/functions/change_function.rb +53 -47
- data/lib/pg_trunk/operations/functions/create_function.rb +75 -64
- data/lib/pg_trunk/operations/functions/drop_function.rb +78 -65
- data/lib/pg_trunk/operations/functions/rename_function.rb +29 -22
- data/lib/pg_trunk/operations/materialized_views/change_materialized_view.rb +65 -55
- data/lib/pg_trunk/operations/materialized_views/create_materialized_view.rb +82 -71
- data/lib/pg_trunk/operations/materialized_views/drop_materialized_view.rb +59 -46
- data/lib/pg_trunk/operations/materialized_views/refresh_materialized_view.rb +29 -24
- data/lib/pg_trunk/operations/materialized_views/rename_materialized_view.rb +29 -22
- data/lib/pg_trunk/operations/procedures/change_procedure.rb +53 -46
- data/lib/pg_trunk/operations/procedures/create_procedure.rb +63 -52
- data/lib/pg_trunk/operations/procedures/drop_procedure.rb +56 -45
- data/lib/pg_trunk/operations/procedures/rename_procedure.rb +29 -22
- data/lib/pg_trunk/operations/rules/base.rb +77 -0
- data/lib/pg_trunk/operations/rules/create_rule.rb +155 -0
- data/lib/pg_trunk/operations/rules/drop_rule.rb +94 -0
- data/lib/pg_trunk/operations/rules/rename_rule.rb +62 -0
- data/lib/pg_trunk/operations/rules.rb +13 -0
- data/lib/pg_trunk/operations/sequences/base.rb +79 -0
- data/lib/pg_trunk/operations/sequences/change_sequence.rb +142 -0
- data/lib/pg_trunk/operations/sequences/create_sequence.rb +180 -0
- data/lib/pg_trunk/operations/sequences/drop_sequence.rb +82 -0
- data/lib/pg_trunk/operations/sequences/rename_sequence.rb +64 -0
- data/lib/pg_trunk/operations/sequences.rb +14 -0
- data/lib/pg_trunk/operations/statistics/create_statistics.rb +67 -56
- data/lib/pg_trunk/operations/statistics/drop_statistics.rb +64 -53
- data/lib/pg_trunk/operations/statistics/rename_statistics.rb +18 -13
- data/lib/pg_trunk/operations/triggers/change_trigger.rb +23 -18
- data/lib/pg_trunk/operations/triggers/create_trigger.rb +63 -54
- data/lib/pg_trunk/operations/triggers/drop_trigger.rb +55 -46
- data/lib/pg_trunk/operations/triggers/rename_trigger.rb +51 -48
- data/lib/pg_trunk/operations/views/change_view.rb +47 -38
- data/lib/pg_trunk/operations/views/create_view.rb +56 -45
- data/lib/pg_trunk/operations/views/drop_view.rb +59 -46
- data/lib/pg_trunk/operations/views/rename_view.rb +27 -20
- data/lib/pg_trunk/operations.rb +2 -0
- data/lib/pg_trunk/version.rb +1 -1
- data/pg_trunk.gemspec +0 -1
- data/spec/operations/rules/create_rule_spec.rb +119 -0
- data/spec/operations/rules/drop_rule_spec.rb +117 -0
- data/spec/operations/rules/rename_rule_spec.rb +148 -0
- data/spec/operations/sequences/change_sequence_spec.rb +134 -0
- data/spec/operations/sequences/create_sequence_spec.rb +156 -0
- data/spec/operations/sequences/drop_sequence_spec.rb +102 -0
- data/spec/operations/sequences/rename_sequence_spec.rb +100 -0
- metadata +22 -68
@@ -1,58 +1,69 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @option [
|
9
|
-
# @option [
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# @
|
16
|
-
# @
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# s.
|
32
|
-
#
|
33
|
-
# SQL
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Drop a custom statistics
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] name (nil) The qualified name of the statistics
|
8
|
+
# # @option options [Boolean] :if_exists (false) Suppress the error when the statistics is absent
|
9
|
+
# # @option options [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
|
10
|
+
# # @option options [#to_s] table (nil)
|
11
|
+
# # The qualified name of the table whose statistics will be collected
|
12
|
+
# # @option options [Array<Symbol>] kinds ([:dependencies, :mcv, :ndistinct])
|
13
|
+
# # The kinds of statistics to be collected (all by default).
|
14
|
+
# # Supported values in the array: :dependencies, :mcv, :ndistinct
|
15
|
+
# # @option options [#to_s] :comment The description of the statistics
|
16
|
+
# # @yield [s] the block with the statistics' definition
|
17
|
+
# # @yieldparam Object receiver of methods specifying the statistics
|
18
|
+
# # @return [void]
|
19
|
+
# #
|
20
|
+
# # A statistics can be dropped by its name only:
|
21
|
+
# #
|
22
|
+
# # ```ruby
|
23
|
+
# # drop_statistics "my_stats"
|
24
|
+
# # ```
|
25
|
+
# #
|
26
|
+
# # Such operation is irreversible. To make it inverted
|
27
|
+
# # you have to provide a full definition:
|
28
|
+
# #
|
29
|
+
# # ```ruby
|
30
|
+
# # drop_statistics "users_stat" do |s|
|
31
|
+
# # s.table "users"
|
32
|
+
# # s.columns "firstname", "name"
|
33
|
+
# # s.expression <<~SQL
|
34
|
+
# # round(age, 10)
|
35
|
+
# # SQL
|
36
|
+
# # s.kinds :dependency, :mcv, :ndistinct
|
37
|
+
# # s.comment "Statistics for name, firstname, and rough age"
|
38
|
+
# # SQL
|
39
|
+
# # ```
|
40
|
+
# #
|
41
|
+
# # If the statistics was anonymous (used the generated name),
|
42
|
+
# # it can be dropped without defining the name as well:
|
43
|
+
# #
|
44
|
+
# # ```ruby
|
45
|
+
# # drop_statistics do |s|
|
46
|
+
# # s.table "users"
|
47
|
+
# # s.columns "firstname", "name"
|
48
|
+
# # s.expression <<~SQL
|
49
|
+
# # round(age, 10)
|
50
|
+
# # SQL
|
51
|
+
# # s.kinds :dependency, :mcv, :ndistinct
|
52
|
+
# # s.comment "Statistics for name, firstname, and rough age"
|
53
|
+
# # SQL
|
54
|
+
# # ```
|
55
|
+
# #
|
56
|
+
# # The operation can be called with `if_exists` option. In this case
|
57
|
+
# # it would do nothing when no statistics existed.
|
58
|
+
# #
|
59
|
+
# # ```ruby
|
60
|
+
# # drop_statistics "unknown_statistics", if_exists: true
|
61
|
+
# # ```
|
62
|
+
# #
|
63
|
+
# # Notice, that this option make the operation irreversible because of
|
64
|
+
# # uncertainty about the previous state of the database.
|
65
|
+
# def drop_statistics(name, **options, &block); end
|
66
|
+
# end
|
56
67
|
module PGTrunk::Operations::Statistics
|
57
68
|
# @private
|
58
69
|
class DropStatistics < Base
|
@@ -1,18 +1,23 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Change the name and/or schema of a statistics
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] :name (nil) The qualified name of the statistics
|
8
|
+
# # @option options [#to_s] :to (nil) The new qualified name for the statistics
|
9
|
+
# # @return [void]
|
10
|
+
# #
|
11
|
+
# # A custom statistics can be renamed by changing both the name
|
12
|
+
# # and the schema (namespace) it belongs to.
|
13
|
+
# #
|
14
|
+
# # ```ruby
|
15
|
+
# # rename_statistics "math.my_stat", to: "public.my_stats"
|
16
|
+
# # ```
|
17
|
+
# #
|
18
|
+
# # The operation is always reversible.
|
19
|
+
# def rename_statistics(name, to:); end
|
20
|
+
# end
|
16
21
|
module PGTrunk::Operations::Statistics
|
17
22
|
# @private
|
18
23
|
class RenameStatistics < Base
|
@@ -1,24 +1,29 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @
|
10
|
-
# @
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# t.
|
19
|
-
# t.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Create a trigger for a table
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] name (nil) The name of the trigger
|
9
|
+
# # @option options [Boolean] :if_exists (false) Suppress the error when the trigger is absent
|
10
|
+
# # @yield [t] the block with the trigger's definition
|
11
|
+
# # @yieldparam Object receiver of methods specifying the trigger
|
12
|
+
# # @return [void]
|
13
|
+
# #
|
14
|
+
# # The trigger can be changed using `CREATE OR REPLACE TRIGGER` command:
|
15
|
+
# #
|
16
|
+
# # ```ruby
|
17
|
+
# # change_trigger "users", "do_something" do |t|
|
18
|
+
# # t.function "do_something()", from: "do_something_different()"
|
19
|
+
# # t.for_each :row # from: :statement
|
20
|
+
# # t.type :after, from: :before
|
21
|
+
# # t.events %i[insert update], from: %i[insert]
|
22
|
+
# # t.comment "Does something useful", from: ""
|
23
|
+
# # end
|
24
|
+
# # ```
|
25
|
+
# def create_trigger(table, name = nil, **options, &block); end
|
20
26
|
# end
|
21
|
-
|
22
27
|
module PGTrunk::Operations::Triggers
|
23
28
|
# @private
|
24
29
|
class ChangeTrigger < Base
|
@@ -1,60 +1,69 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @option [
|
10
|
-
# @option [
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# @option [
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @option [
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @
|
22
|
-
# @
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# t
|
41
|
-
# t.
|
42
|
-
# t.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Create a trigger for a table
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] name (nil) The name of the trigger
|
9
|
+
# # @option options [Boolean] :replace_existing (false) If the trigger should overwrite an existing one
|
10
|
+
# # @option options [#to_s] :function (nil) The qualified name of the function to be called
|
11
|
+
# # @option options [Symbol] :type (nil) When the trigger should be run
|
12
|
+
# # Supported values: :before, :after, :instead_of
|
13
|
+
# # @option options [Array<Symbol>] :events List of events running the trigger
|
14
|
+
# # Supported values in the array: :insert, :update, :delete, :truncate
|
15
|
+
# # @option options [Boolean] :constraint (false) If the trigger is a constraint
|
16
|
+
# # @option options [Symbol] :initially (:immediate) If the constraint check should be deferred
|
17
|
+
# # Supported values: :immediate (default), :deferred
|
18
|
+
# # @option options [#to_s] :when (nil) The SQL snippet definiing a condition for the trigger
|
19
|
+
# # @option options [Symbol] :for_each (:statement) Define if a trigger should be run for every row
|
20
|
+
# # Supported values: :statement (default), :row
|
21
|
+
# # @option options [#to_s] :comment (nil) The commend describing the trigger
|
22
|
+
# # @yield [t] the block with the trigger's definition
|
23
|
+
# # @yieldparam Object receiver of methods specifying the trigger
|
24
|
+
# # @return [void]
|
25
|
+
# #
|
26
|
+
# # The trigger can be created either using inline syntax
|
27
|
+
# #
|
28
|
+
# # ```ruby
|
29
|
+
# # create_trigger "users", "do_something",
|
30
|
+
# # function: "do_something()",
|
31
|
+
# # for_each: :row,
|
32
|
+
# # type: :after,
|
33
|
+
# # events: %i[insert update],
|
34
|
+
# # comment: "Does something useful"
|
35
|
+
# # ```
|
36
|
+
# #
|
37
|
+
# # or using a block:
|
38
|
+
# #
|
39
|
+
# # ```ruby
|
40
|
+
# # create_trigger do |t|
|
41
|
+
# # t.table "users"
|
42
|
+
# # t.name "do_something"
|
43
|
+
# # t.function "do_something()"
|
44
|
+
# # t.for_each :row
|
45
|
+
# # t.type :after
|
46
|
+
# # t.events %i[insert update]
|
47
|
+
# # t.comment "Does something useful"
|
48
|
+
# # end
|
49
|
+
# # ```
|
50
|
+
# #
|
51
|
+
# # With a `replace_existing: true` option,
|
52
|
+
# # it will be created using the `CREATE OR REPLACE` clause.
|
53
|
+
# # (Available in PostgreSQL v14+).
|
54
|
+
# #
|
55
|
+
# # ```ruby
|
56
|
+
# # create_trigger "users", "do_something",
|
57
|
+
# # function: "do_something()",
|
58
|
+
# # type: :after,
|
59
|
+
# # events: %i[insert update],
|
60
|
+
# # replace_previous: true
|
61
|
+
# # ```
|
62
|
+
# #
|
63
|
+
# # In this case the migration is irreversible because we
|
64
|
+
# # don't know if and how to restore its previous definition.
|
65
|
+
# def create_trigger(table, name = nil, **options, &block); end
|
43
66
|
# end
|
44
|
-
#
|
45
|
-
# With a `replace_existing: true` option,
|
46
|
-
# it will be created using the `CREATE OR REPLACE` clause.
|
47
|
-
# (Available in PostgreSQL v14+).
|
48
|
-
#
|
49
|
-
# create_trigger "users", "do_something",
|
50
|
-
# function: "do_something()",
|
51
|
-
# type: :after,
|
52
|
-
# events: %i[insert update],
|
53
|
-
# replace_previous: true
|
54
|
-
#
|
55
|
-
# In this case the migration is irreversible because we
|
56
|
-
# don't know if and how to restore its previous definition.
|
57
|
-
|
58
67
|
module PGTrunk::Operations::Triggers
|
59
68
|
# @private
|
60
69
|
class CreateTrigger < Base
|
@@ -1,52 +1,61 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @option [
|
10
|
-
# @option [
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# @option [
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @option [
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @
|
22
|
-
# @
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# t.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Drop a trigger for a table
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] name (nil) The name of the trigger
|
9
|
+
# # @option options [Boolean] :if_exists (false) Suppress the error when the trigger is absent
|
10
|
+
# # @option options [#to_s] :function (nil) The qualified name of the function to be called
|
11
|
+
# # @option options [Symbol] :type (nil) When the trigger should be run
|
12
|
+
# # Supported values: :before, :after, :instead_of
|
13
|
+
# # @option options [Array<Symbol>] :events List of events running the trigger
|
14
|
+
# # Supported values in the array: :insert, :update, :delete, :truncate
|
15
|
+
# # @option options [Boolean] :constraint (false) If the trigger is a constraint
|
16
|
+
# # @option options [Symbol] :initially (:immediate) If the constraint check should be deferred
|
17
|
+
# # Supported values: :immediate (default), :deferred
|
18
|
+
# # @option options [#to_s] :when (nil) The SQL snippet definiing a condition for the trigger
|
19
|
+
# # @option options [Symbol] :for_each (:statement) Define if a trigger should be run for every row
|
20
|
+
# # Supported values: :statement (default), :row
|
21
|
+
# # @option options [#to_s] :comment (nil) The commend describing the trigger
|
22
|
+
# # @yield [t] the block with the trigger's definition
|
23
|
+
# # @yieldparam Object receiver of methods specifying the trigger
|
24
|
+
# # @return [void]
|
25
|
+
# #
|
26
|
+
# # A trigger can be dropped by a table and name:
|
27
|
+
# #
|
28
|
+
# # ```ruby
|
29
|
+
# # drop_trigger "users", "do_something"
|
30
|
+
# # ```
|
31
|
+
# #
|
32
|
+
# # the default name can be restored from its attributes as well.
|
33
|
+
# #
|
34
|
+
# # ```ruby
|
35
|
+
# # drop_trigger "users" do |t|
|
36
|
+
# # t.function "send_notifications()"
|
37
|
+
# # t.for_each :row
|
38
|
+
# # t.type :after
|
39
|
+
# # t.events %i[update]
|
40
|
+
# # t.columns %w[email phone]
|
41
|
+
# # t.comment "Does something"
|
42
|
+
# # end
|
43
|
+
# # ```
|
44
|
+
# #
|
45
|
+
# # Notice, that you have to specify all attributes to make
|
46
|
+
# # the operation reversible.
|
47
|
+
# #
|
48
|
+
# # The operation can be called with `if_exists` option. In this case
|
49
|
+
# # it would do nothing when no trigger existed.
|
50
|
+
# #
|
51
|
+
# # ```ruby
|
52
|
+
# # drop_trigger "users", "unknown_trigger", if_exists: true
|
53
|
+
# # ```
|
54
|
+
# #
|
55
|
+
# # This option, though, makes the operation irreversible because of
|
56
|
+
# # uncertainty of the previous state of the database.
|
57
|
+
# def drop_trigger(table, name = nil, **options, &block); end
|
37
58
|
# end
|
38
|
-
#
|
39
|
-
# Notice, that you have to specify all attributes to make
|
40
|
-
# the operation reversible.
|
41
|
-
#
|
42
|
-
# The operation can be called with `if_exists` option. In this case
|
43
|
-
# it would do nothing when no trigger existed.
|
44
|
-
#
|
45
|
-
# drop_trigger "users", "unknown_trigger", if_exists: true
|
46
|
-
#
|
47
|
-
# This option, though, makes the operation irreversible because of
|
48
|
-
# uncertainty of the previous state of the database.
|
49
|
-
|
50
59
|
module PGTrunk::Operations::Triggers
|
51
60
|
# @private
|
52
61
|
class DropTrigger < Base
|
@@ -1,54 +1,57 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @
|
10
|
-
# @param [#to_s]
|
11
|
-
# @
|
12
|
-
# @option [#to_s] :
|
13
|
-
# @option [
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# @
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# t.
|
38
|
-
# t.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Rename a trigger
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] name (nil) The name of the trigger
|
9
|
+
# # @option options [#to_s] :to (nil) The new name of the trigger
|
10
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
11
|
+
# # @param [#to_s] name (nil) The current name of the trigger
|
12
|
+
# # @option options [#to_s] :to (nil) The new name for the trigger
|
13
|
+
# # @option options [#to_s] :function (nil) The qualified name of the function to be called
|
14
|
+
# # @option options [Symbol] :type (nil) When the trigger should be run
|
15
|
+
# # Supported values: :before, :after, :instead_of
|
16
|
+
# # @option options [Array<Symbol>] :events List of events running the trigger
|
17
|
+
# # Supported values in the array: :insert, :update, :delete, :truncate
|
18
|
+
# # @option options [Symbol] :for_each (:statement) Define if a trigger should be run for every row
|
19
|
+
# # Supported values: :statement (default), :row
|
20
|
+
# # @yield [t] the block with the trigger's definition
|
21
|
+
# # @yieldparam Object receiver of methods specifying the trigger
|
22
|
+
# # @return [void]
|
23
|
+
# #
|
24
|
+
# # A trigger can be renamed by either setting a new name explicitly
|
25
|
+
# #
|
26
|
+
# # rename_trigger "users", "do_something", to: "do_something_different"
|
27
|
+
# #
|
28
|
+
# # or resetting it to the default (generated) value.
|
29
|
+
# #
|
30
|
+
# # rename_trigger "users", "do_something"
|
31
|
+
# #
|
32
|
+
# # The previously generated name of the trigger can be get
|
33
|
+
# # from its parameters. In this case all the essentials
|
34
|
+
# # parameters must be specified:
|
35
|
+
# #
|
36
|
+
# # rename_trigger "users", to: "do_something_different" do |t|
|
37
|
+
# # t.function "do_something()"
|
38
|
+
# # t.for_each :row
|
39
|
+
# # t.type :after
|
40
|
+
# # t.events %i[insert update]
|
41
|
+
# # end
|
42
|
+
# #
|
43
|
+
# # In the same way, when you reset the name to default,
|
44
|
+
# # all the essential parameters must be got to make the trigger
|
45
|
+
# # invertible.
|
46
|
+
# #
|
47
|
+
# # rename_trigger "users", "do_something" do |t|
|
48
|
+
# # t.function "do_something()"
|
49
|
+
# # t.for_each :row
|
50
|
+
# # t.type :after
|
51
|
+
# # t.events %i[insert update]
|
52
|
+
# # end
|
53
|
+
# def rename_trigger(table, name = nil, **options, &block); end
|
39
54
|
# end
|
40
|
-
#
|
41
|
-
# In the same way, when you reset the name to default,
|
42
|
-
# all the essential parameters must be got to make the trigger
|
43
|
-
# invertible.
|
44
|
-
#
|
45
|
-
# rename_trigger "users", "do_something" do |t|
|
46
|
-
# t.function "do_something()"
|
47
|
-
# t.for_each :row
|
48
|
-
# t.type :after
|
49
|
-
# t.events %i[insert update]
|
50
|
-
# end
|
51
|
-
|
52
55
|
module PGTrunk::Operations::Triggers
|
53
56
|
# @private
|
54
57
|
class RenameTrigger < Base
|