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