pg_trunk 0.1.0 → 0.1.1

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/lib/pg_trunk/operations/check_constraints/add_check_constraint.rb +36 -33
  4. data/lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb +43 -40
  5. data/lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb +33 -30
  6. data/lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb +24 -21
  7. data/lib/pg_trunk/operations/composite_types/change_composite_type.rb +53 -50
  8. data/lib/pg_trunk/operations/composite_types/create_composite_type.rb +22 -19
  9. data/lib/pg_trunk/operations/composite_types/drop_composite_type.rb +46 -43
  10. data/lib/pg_trunk/operations/composite_types/rename_composite_type.rb +15 -12
  11. data/lib/pg_trunk/operations/domains/change_domain.rb +50 -47
  12. data/lib/pg_trunk/operations/domains/create_domain.rb +28 -25
  13. data/lib/pg_trunk/operations/domains/drop_domain.rb +44 -41
  14. data/lib/pg_trunk/operations/domains/rename_domain.rb +15 -12
  15. data/lib/pg_trunk/operations/enums/change_enum.rb +35 -32
  16. data/lib/pg_trunk/operations/enums/create_enum.rb +23 -20
  17. data/lib/pg_trunk/operations/enums/drop_enum.rb +42 -39
  18. data/lib/pg_trunk/operations/enums/rename_enum.rb +15 -12
  19. data/lib/pg_trunk/operations/foreign_keys/add_foreign_key.rb +52 -49
  20. data/lib/pg_trunk/operations/foreign_keys/drop_foreign_key.rb +51 -48
  21. data/lib/pg_trunk/operations/foreign_keys/rename_foreign_key.rb +32 -29
  22. data/lib/pg_trunk/operations/functions/change_function.rb +50 -47
  23. data/lib/pg_trunk/operations/functions/create_function.rb +67 -64
  24. data/lib/pg_trunk/operations/functions/drop_function.rb +68 -65
  25. data/lib/pg_trunk/operations/functions/rename_function.rb +25 -22
  26. data/lib/pg_trunk/operations/materialized_views/change_materialized_view.rb +58 -55
  27. data/lib/pg_trunk/operations/materialized_views/create_materialized_view.rb +74 -71
  28. data/lib/pg_trunk/operations/materialized_views/drop_materialized_view.rb +49 -46
  29. data/lib/pg_trunk/operations/materialized_views/refresh_materialized_view.rb +27 -24
  30. data/lib/pg_trunk/operations/materialized_views/rename_materialized_view.rb +25 -22
  31. data/lib/pg_trunk/operations/procedures/change_procedure.rb +49 -46
  32. data/lib/pg_trunk/operations/procedures/create_procedure.rb +55 -52
  33. data/lib/pg_trunk/operations/procedures/drop_procedure.rb +48 -45
  34. data/lib/pg_trunk/operations/procedures/rename_procedure.rb +25 -22
  35. data/lib/pg_trunk/operations/statistics/create_statistics.rb +59 -56
  36. data/lib/pg_trunk/operations/statistics/drop_statistics.rb +56 -53
  37. data/lib/pg_trunk/operations/statistics/rename_statistics.rb +16 -13
  38. data/lib/pg_trunk/operations/triggers/change_trigger.rb +21 -18
  39. data/lib/pg_trunk/operations/triggers/create_trigger.rb +57 -54
  40. data/lib/pg_trunk/operations/triggers/drop_trigger.rb +49 -46
  41. data/lib/pg_trunk/operations/triggers/rename_trigger.rb +51 -48
  42. data/lib/pg_trunk/operations/views/change_view.rb +41 -38
  43. data/lib/pg_trunk/operations/views/create_view.rb +48 -45
  44. data/lib/pg_trunk/operations/views/drop_view.rb +49 -46
  45. data/lib/pg_trunk/operations/views/rename_view.rb +23 -20
  46. data/lib/pg_trunk/version.rb +1 -1
  47. metadata +2 -2
@@ -1,58 +1,61 @@
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 [Boolean] :if_exists (false) Suppress the error when the statistics is absent
9
+ # # @option [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
10
+ # # @option [#to_s] table (nil)
11
+ # # The qualified name of the table whose statistics will be collected
12
+ # # @option [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 [#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
+ # # drop_statistics "my_stats"
23
+ # #
24
+ # # Such operation is irreversible. To make it inverted
25
+ # # you have to provide a full definition:
26
+ # #
27
+ # # drop_statistics "users_stat" do |s|
28
+ # # s.table "users"
29
+ # # s.columns "firstname", "name"
30
+ # # s.expression <<~SQL
31
+ # # round(age, 10)
32
+ # # SQL
33
+ # # s.kinds :dependency, :mcv, :ndistinct
34
+ # # p.comment "Statistics for name, firstname, and rough age"
35
+ # # SQL
36
+ # #
37
+ # # If the statistics was anonymous (used the generated name),
38
+ # # it can be dropped without defining the name as well:
39
+ # #
40
+ # # drop_statistics do |s|
41
+ # # s.table "users"
42
+ # # s.columns "firstname", "name"
43
+ # # s.expression <<~SQL
44
+ # # round(age, 10)
45
+ # # SQL
46
+ # # s.kinds :dependency, :mcv, :ndistinct
47
+ # # p.comment "Statistics for name, firstname, and rough age"
48
+ # # SQL
49
+ # #
50
+ # # The operation can be called with `if_exists` option. In this case
51
+ # # it would do nothing when no statistics existed.
52
+ # #
53
+ # # drop_procedure "unknown_statistics", if_exists: true
54
+ # #
55
+ # # Notice, that this option make the operation irreversible because of
56
+ # # uncertainty about the previous state of the database.
57
+ # def drop_statistics(name, **options, &block); end
58
+ # end
56
59
  module PGTrunk::Operations::Statistics
57
60
  # @private
58
61
  class DropStatistics < Base
@@ -1,18 +1,21 @@
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 [#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
+ # # rename_statistics "math.my_stat", to: "public.my_stats"
15
+ # #
16
+ # # The operation is always reversible.
17
+ # def rename_statistics(name, to:); end
18
+ # end
16
19
  module PGTrunk::Operations::Statistics
17
20
  # @private
18
21
  class RenameStatistics < Base
@@ -1,24 +1,27 @@
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 [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
+ # # change_trigger "users", "do_something" do |t|
17
+ # # t.function "do_something()", from: "do_something_different()"
18
+ # # t.for_each :row # from: :statement
19
+ # # t.type :after, from: :before
20
+ # # t.events %i[insert update], from: %i[insert]
21
+ # # t.comment "Does something useful", from: ""
22
+ # # end
23
+ # def create_trigger(table, name = nil, **options, &block); end
20
24
  # end
21
-
22
25
  module PGTrunk::Operations::Triggers
23
26
  # @private
24
27
  class ChangeTrigger < Base
@@ -1,60 +1,63 @@
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 [Boolean] :replace_existing (false) If the trigger should overwrite an existing one
10
+ # # @option [#to_s] :function (nil) The qualified name of the function to be called
11
+ # # @option [Symbol] :type (nil) When the trigger should be run
12
+ # # Supported values: :before, :after, :instead_of
13
+ # # @option [Array<Symbol>] :events List of events running the trigger
14
+ # # Supported values in the array: :insert, :update, :delete, :truncate
15
+ # # @option [Boolean] :constraint (false) If the trigger is a constraint
16
+ # # @option [Symbol] :initially (:immediate) If the constraint check should be deferred
17
+ # # Supported values: :immediate (default), :deferred
18
+ # # @option [#to_s] :when (nil) The SQL snippet definiing a condition for the trigger
19
+ # # @option [Symbol] :for_each (:statement) Define if a trigger should be run for every row
20
+ # # Supported values: :statement (default), :row
21
+ # # @option [#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
+ # # create_trigger "users", "do_something",
29
+ # # function: "do_something()",
30
+ # # for_each: :row,
31
+ # # type: :after,
32
+ # # events: %i[insert update],
33
+ # # comment: "Does something useful"
34
+ # #
35
+ # # or using a block:
36
+ # #
37
+ # # create_trigger do |t|
38
+ # # t.table "users"
39
+ # # t.name "do_something"
40
+ # # t.function "do_something()"
41
+ # # t.for_each :row
42
+ # # t.type :after
43
+ # # t.events %i[insert update]
44
+ # # t.comment "Does something useful"
45
+ # # end
46
+ # #
47
+ # # With a `replace_existing: true` option,
48
+ # # it will be created using the `CREATE OR REPLACE` clause.
49
+ # # (Available in PostgreSQL v14+).
50
+ # #
51
+ # # create_trigger "users", "do_something",
52
+ # # function: "do_something()",
53
+ # # type: :after,
54
+ # # events: %i[insert update],
55
+ # # replace_previous: true
56
+ # #
57
+ # # In this case the migration is irreversible because we
58
+ # # don't know if and how to restore its previous definition.
59
+ # def create_trigger(table, name = nil, **options, &block); end
43
60
  # 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
61
  module PGTrunk::Operations::Triggers
59
62
  # @private
60
63
  class CreateTrigger < Base
@@ -1,52 +1,55 @@
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 [Boolean] :if_exists (false) Suppress the error when the trigger is absent
10
+ # # @option [#to_s] :function (nil) The qualified name of the function to be called
11
+ # # @option [Symbol] :type (nil) When the trigger should be run
12
+ # # Supported values: :before, :after, :instead_of
13
+ # # @option [Array<Symbol>] :events List of events running the trigger
14
+ # # Supported values in the array: :insert, :update, :delete, :truncate
15
+ # # @option [Boolean] :constraint (false) If the trigger is a constraint
16
+ # # @option [Symbol] :initially (:immediate) If the constraint check should be deferred
17
+ # # Supported values: :immediate (default), :deferred
18
+ # # @option [#to_s] :when (nil) The SQL snippet definiing a condition for the trigger
19
+ # # @option [Symbol] :for_each (:statement) Define if a trigger should be run for every row
20
+ # # Supported values: :statement (default), :row
21
+ # # @option [#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
+ # # drop_trigger "users", "do_something"
29
+ # #
30
+ # # the default name can be restored from its attributes as well.
31
+ # #
32
+ # # drop_trigger "users" do |t|
33
+ # # t.function "send_notifications()"
34
+ # # t.for_each :row
35
+ # # t.type :after
36
+ # # t.events %i[update]
37
+ # # t.columns %w[email phone]
38
+ # # t.comment "Does something"
39
+ # # end
40
+ # #
41
+ # # Notice, that you have to specify all attributes to make
42
+ # # the operation reversible.
43
+ # #
44
+ # # The operation can be called with `if_exists` option. In this case
45
+ # # it would do nothing when no trigger existed.
46
+ # #
47
+ # # drop_trigger "users", "unknown_trigger", if_exists: true
48
+ # #
49
+ # # This option, though, makes the operation irreversible because of
50
+ # # uncertainty of the previous state of the database.
51
+ # def drop_trigger(table, name = nil, **options, &block); end
37
52
  # 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
53
  module PGTrunk::Operations::Triggers
51
54
  # @private
52
55
  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 [#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 [#to_s] :to (nil) The new name for the trigger
13
+ # # @option [#to_s] :function (nil) The qualified name of the function to be called
14
+ # # @option [Symbol] :type (nil) When the trigger should be run
15
+ # # Supported values: :before, :after, :instead_of
16
+ # # @option [Array<Symbol>] :events List of events running the trigger
17
+ # # Supported values in the array: :insert, :update, :delete, :truncate
18
+ # # @option [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
@@ -1,44 +1,47 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#change_view(name, **options, &block)
4
- # Modify a view
5
- #
6
- # @param [#to_s] name (nil) The qualified name of the view
7
- # @option [Boolean] :if_exists (false) Suppress the error when the view is absent
8
- # @yield [Proc] the block with the view's definition
9
- # @yieldparam The receiver of methods specifying the view
10
- #
11
- # The operation replaces the view with a new definition(s):
12
- #
13
- # change_view "admin_users" do |v|
14
- # v.sql_definition: <<~SQL, from: <<~SQL
15
- # SELECT id, name FROM users WHERE admin;
16
- # SQL
17
- # SELECT * FROM users WHERE admin;
18
- # SQL
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Modify a view
6
+ # #
7
+ # # @param [#to_s] name (nil) The qualified name of the view
8
+ # # @option [Boolean] :if_exists (false) Suppress the error when the view is absent
9
+ # # @yield [v] the block with the view's definition
10
+ # # @yieldparam Object receiver of methods specifying the view
11
+ # # @return [void]
12
+ # #
13
+ # # The operation replaces the view with a new definition(s):
14
+ # #
15
+ # # change_view "admin_users" do |v|
16
+ # # v.sql_definition: <<~SQL, from: <<~SQL
17
+ # # SELECT id, name FROM users WHERE admin;
18
+ # # SQL
19
+ # # SELECT * FROM users WHERE admin;
20
+ # # SQL
21
+ # # end
22
+ # #
23
+ # # For some compatibility to the `scenic` gem, we also support
24
+ # # adding a definition via its version:
25
+ # #
26
+ # # change_view "admin_users" do |v|
27
+ # # v.version 2, from: 1
28
+ # # end
29
+ # #
30
+ # # It is expected, that both `db/views/admin_users_v01.sql`
31
+ # # and `db/views/admin_users_v02.sql` to contain SQL snippets.
32
+ # #
33
+ # # Please, notice that neither deletion of columns,
34
+ # # nor changing their types is supported by the PostgreSQL.
35
+ # #
36
+ # # You can also (re)set a comment describing the view,
37
+ # # and the check option (either `:local` or `:cascaded`):
38
+ # #
39
+ # # change_view "admin_users" do |v|
40
+ # # v.check :local, from: :cascaded
41
+ # # v.comment "Admin users only", from: ""
42
+ # # end
43
+ # def change_view(name, **options, &block); end
19
44
  # end
20
- #
21
- # For some compatibility to the `scenic` gem, we also support
22
- # adding a definition via its version:
23
- #
24
- # change_view "admin_users" do |v|
25
- # v.version 2, from: 1
26
- # end
27
- #
28
- # It is expected, that both `db/views/admin_users_v01.sql`
29
- # and `db/views/admin_users_v02.sql` to contain SQL snippets.
30
- #
31
- # Please, notice that neither deletion of columns,
32
- # nor changing their types is supported by the PostgreSQL.
33
- #
34
- # You can also (re)set a comment describing the view,
35
- # and the check option (either `:local` or `:cascaded`):
36
- #
37
- # change_view "admin_users" do |v|
38
- # v.check :local, from: :cascaded
39
- # v.comment "Admin users only", from: ""
40
- # end
41
-
42
45
  module PGTrunk::Operations::Views
43
46
  # @private
44
47
  class ChangeView < Base