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.
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,77 +1,88 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#create_materialized_view(name, **options, &block)
4
- # Create a materialized view
5
- #
6
- # @param [#to_s] name (nil) The qualified name of the view
7
- # @option [Boolean] :if_not_exists (false) Suppress the error when a view has been already created
8
- # @option [#to_s] :sql_definition (nil) The snippet containing the query
9
- # @option [#to_i] :version (nil)
10
- # The alternative way to set sql_definition by referencing to a file containing the snippet
11
- # @option [#to_s] :tablespace (nil) The tablespace for the view
12
- # @option [Boolean] :with_data (true) If the view should be populated after creation
13
- # @option [#to_s] :comment (nil) The comment describing the view
14
- # @yield [Proc] the block with the view's definition
15
- # @yieldparam The receiver of methods specifying the view
16
- #
17
- # The operation creates the view using its `sql_definition`:
18
- #
19
- # create_materialized_view("views.admin_users", sql_definition: <<~SQL)
20
- # SELECT id, name FROM users WHERE admin;
21
- # SQL
22
- #
23
- # For compatibility to the `scenic` gem, we also support
24
- # adding a definition via its version:
25
- #
26
- # create_materialized_view "admin_users", version: 1
27
- #
28
- # It is expected, that a `db/materialized_views/admin_users_v01.sql`
29
- # to contain the SQL snippet.
30
- #
31
- # The tablespace can be specified for the created view.
32
- # Notice that later it can't be changed (in PostgreSQL all rows
33
- # can be moved to another tablespace, but we don't support
34
- # this feature yet).
35
- #
36
- # create_materialized_view "admin_users" do |v|
37
- # v.tablespace "fast_ssd"
38
- # v.sql_definition <<~SQL
39
- # SELECT id, name, password, admin, on_duty
40
- # FROM users
41
- # WHERE admin
42
- # SQL
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Create a materialized view
6
+ # #
7
+ # # @param [#to_s] name (nil) The qualified name of the view
8
+ # # @option options [Boolean] :if_not_exists (false) Suppress the error when a view has been already created
9
+ # # @option options [#to_s] :sql_definition (nil) The snippet containing the query
10
+ # # @option options [#to_i] :version (nil)
11
+ # # The alternative way to set sql_definition by referencing to a file containing the snippet
12
+ # # @option options [#to_s] :tablespace (nil) The tablespace for the view
13
+ # # @option options [Boolean] :with_data (true) If the view should be populated after creation
14
+ # # @option options [#to_s] :comment (nil) The comment describing the view
15
+ # # @yield [v] the block with the view's definition
16
+ # # @yieldparam Object receiver of methods specifying the view
17
+ # # @return [void]
18
+ # #
19
+ # # The operation creates the view using its `sql_definition`:
20
+ # #
21
+ # # ```ruby
22
+ # # create_materialized_view("views.admin_users", sql_definition: <<~SQL)
23
+ # # SELECT id, name FROM users WHERE admin;
24
+ # # SQL
25
+ # # ```
26
+ # #
27
+ # # For compatibility to the `scenic` gem, we also support
28
+ # # adding a definition via its version:
29
+ # #
30
+ # # ```ruby
31
+ # # create_materialized_view "admin_users", version: 1
32
+ # # ```
33
+ # #
34
+ # # It is expected, that a `db/materialized_views/admin_users_v01.sql`
35
+ # # to contain the SQL snippet.
36
+ # #
37
+ # # The tablespace can be specified for the created view.
38
+ # # Notice that later it can't be changed (in PostgreSQL all rows
39
+ # # can be moved to another tablespace, but we don't support
40
+ # # this feature yet).
41
+ # #
42
+ # # ```ruby
43
+ # # create_materialized_view "admin_users" do |v|
44
+ # # v.tablespace "fast_ssd"
45
+ # # v.sql_definition <<~SQL
46
+ # # SELECT id, name, password, admin, on_duty
47
+ # # FROM users
48
+ # # WHERE admin
49
+ # # SQL
50
+ # # end
51
+ # # ```
52
+ # #
53
+ # # You can also set a comment describing the view,
54
+ # # and redefine the storage options for some TOAST-ed columns,
55
+ # # as well as their custom statistics:
56
+ # #
57
+ # # ```ruby
58
+ # # create_materialized_view "admin_users" do |v|
59
+ # # v.sql_definition <<~SQL
60
+ # # SELECT id, name, password, admin, on_duty
61
+ # # FROM users
62
+ # # WHERE admin
63
+ # # SQL
64
+ # # v.column "password", storage: "external" # to avoid compression
65
+ # # v.column "password", n_distinct: -1 # linear dependency
66
+ # # v.column "admin", n_distinct: 1 # exact number of values
67
+ # # v.column "on_duty", statistics: 2 # the total number of values
68
+ # # v.comment "Admin users only"
69
+ # # end
70
+ # # ```
71
+ # #
72
+ # # With the `replace_existing: true` option the operation
73
+ # # would use `CREATE OR REPLACE VIEW` command, so it
74
+ # # can be used to "update" (or reload) the existing view.
75
+ # #
76
+ # # ```ruby
77
+ # # create_materialized_view "admin_users",
78
+ # # version: 1,
79
+ # # replace_existing: true
80
+ # # ```
81
+ # #
82
+ # # This option makes the migration irreversible due to uncertainty
83
+ # # of the previous state of the database.
84
+ # def create_materialized_view(name, **options, &block); end
43
85
  # end
44
- #
45
- # You can also set a comment describing the view,
46
- # and redefine the storage options for some TOAST-ed columns,
47
- # as well as their custom statistics:
48
- #
49
- # create_materialized_view "admin_users" do |v|
50
- # v.sql_definition <<~SQL
51
- # SELECT id, name, password, admin, on_duty
52
- # FROM users
53
- # WHERE admin
54
- # SQL
55
- #
56
- # v.column "password", storage: "external" # to avoid compression
57
- # v.column "password", n_distinct: -1 # linear dependency
58
- # v.column "admin", n_distinct: 1 # exact number of values
59
- # v.column "on_duty", statistics: 2 # the total number of values
60
- #
61
- # v.comment "Admin users only"
62
- # end
63
- #
64
- # With the `replace_existing: true` option the operation
65
- # would use `CREATE OR REPLACE VIEW` command, so it
66
- # can be used to "update" (or reload) the existing view.
67
- #
68
- # create_materialized_view "admin_users",
69
- # version: 1,
70
- # replace_existing: true
71
- #
72
- # This option makes the migration irreversible due to uncertainty
73
- # of the previous state of the database.
74
-
75
86
  module PGTrunk::Operations::MaterializedViews
76
87
  # @private
77
88
  class CreateMaterializedView < Base
@@ -1,52 +1,65 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#drop_materialized_view(name, **options, &block)
4
- # Drop a materialized 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
- # @option [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
9
- # @option [#to_s] :sql_definition (nil) The snippet containing the query
10
- # @option [#to_i] :revert_to_version (nil)
11
- # The alternative way to set sql_definition by referencing to a file containing the snippet
12
- # @option [#to_s] :tablespace (nil) The tablespace for the view
13
- # @option [Boolean] :with_data (true) If the view should be populated after creation
14
- # @option [#to_s] :comment (nil) The comment describing the view
15
- # @yield [Proc] the block with the view's definition
16
- # @yieldparam The receiver of methods specifying the view
17
- #
18
- # The operation drops a materialized view identified by its
19
- # qualified name (it can include a schema).
20
- #
21
- # drop_materialized_view "views.admin_users"
22
- #
23
- # To make the operation invertible, use the same options
24
- # as in the `create_view` operation.
25
- #
26
- # drop_materialized_view "views.admin_users" do |v|
27
- # v.sql_definition "SELECT name, password FROM users WHERE admin;"
28
- # v.column "password", storage: "external" # prevent compression
29
- # v.with_data false
30
- # v.comment "Admin users only"
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Drop a materialized view
6
+ # #
7
+ # # @param [#to_s] name (nil) The qualified name of the view
8
+ # # @option options [Boolean] :if_exists (false) Suppress the error when the view is absent
9
+ # # @option options [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
10
+ # # @option options [#to_s] :sql_definition (nil) The snippet containing the query
11
+ # # @option options [#to_i] :revert_to_version (nil)
12
+ # # The alternative way to set sql_definition by referencing to a file containing the snippet
13
+ # # @option options [#to_s] :tablespace (nil) The tablespace for the view
14
+ # # @option options [Boolean] :with_data (true) If the view should be populated after creation
15
+ # # @option options [#to_s] :comment (nil) The comment describing the view
16
+ # # @yield [v] the block with the view's definition
17
+ # # @yieldparam Object receiver of methods specifying the view
18
+ # # @return [void]
19
+ # #
20
+ # # The operation drops a materialized view identified by its
21
+ # # qualified name (it can include a schema).
22
+ # #
23
+ # # ```ruby
24
+ # # drop_materialized_view "views.admin_users"
25
+ # # ```
26
+ # #
27
+ # # To make the operation invertible, use the same options
28
+ # # as in the `create_view` operation.
29
+ # #
30
+ # # ```ruby
31
+ # # drop_materialized_view "views.admin_users" do |v|
32
+ # # v.sql_definition "SELECT name, password FROM users WHERE admin;"
33
+ # # v.column "password", storage: "external" # prevent compression
34
+ # # v.with_data false
35
+ # # v.comment "Admin users only"
36
+ # # end
37
+ # # ```
38
+ # #
39
+ # # You can also use a version-base SQL definition like:
40
+ # #
41
+ # # ```ruby
42
+ # # drop_materialized_view "admin_users", revert_to_version: 1
43
+ # # ```
44
+ # #
45
+ # # With the `force: :cascade` option the operation would remove
46
+ # # all the objects which depend on the view.
47
+ # #
48
+ # # ```ruby
49
+ # # drop_materialized_view "admin_users", force: :cascade
50
+ # # ```
51
+ # #
52
+ # # With the `if_exists: true` option the operation won't fail
53
+ # # even when the view was absent in the database.
54
+ # #
55
+ # # ```ruby
56
+ # # drop_materialized_view "admin_users", if_exists: true
57
+ # # ```
58
+ # #
59
+ # # Both options make a migration irreversible due to uncertainty
60
+ # # of the previous state of the database.
61
+ # def drop_materialized_view(name, **options, &block); end
31
62
  # end
32
- #
33
- # You can also use a version-base SQL definition like:
34
- #
35
- # drop_materialized_view "admin_users", revert_to_version: 1
36
- #
37
- # With the `force: :cascade` option the operation would remove
38
- # all the objects which depend on the view.
39
- #
40
- # drop_materialized_view "admin_users", force: :cascade
41
- #
42
- # With the `if_exists: true` option the operation won't fail
43
- # even when the view was absent in the database.
44
- #
45
- # drop_materialized_view "admin_users", if_exists: true
46
- #
47
- # Both options make a migration irreversible due to uncertainty
48
- # of the previous state of the database.
49
-
50
63
  module PGTrunk::Operations::MaterializedViews
51
64
  # @private
52
65
  class DropMaterializedView < Base
@@ -1,29 +1,34 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#refresh_materialized_view(name, **options)
4
- # Refresh a materialized view
5
- #
6
- # @param [#to_s] name (nil) The qualified name of the view
7
- # @option [Boolean] :with_data (true) If the view should be populated after creation
8
- # @option [Symbol] :algorithm (nil) Makes the operation concurrent when set to :concurrently
9
- #
10
- # The operation enables refreshing a materialized view
11
- # by reloading its underlying SQL query:
12
- #
13
- # refresh_materialized_view "admin_users"
14
- #
15
- # The option `algorithm: :concurrently` acts exactly
16
- # like in the `create_index` definition. You should
17
- # possibly add the `disable_ddl_transaction!` command
18
- # to the migration as well.
19
- #
20
- # With option `with_data: false` the command won't
21
- # update the data. This option can't be used along with
22
- # the `:algorithm`.
23
- #
24
- # The operation is always reversible, though its
25
- # inversion does nothing.
26
-
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Refresh a materialized view
6
+ # #
7
+ # # @param [#to_s] name (nil) The qualified name of the view
8
+ # # @option options [Boolean] :with_data (true) If the view should be populated after creation
9
+ # # @option options [Symbol] :algorithm (nil) Makes the operation concurrent when set to :concurrently
10
+ # # @return [void]
11
+ # #
12
+ # # The operation enables refreshing a materialized view
13
+ # # by reloading its underlying SQL query:
14
+ # #
15
+ # # ```ruby
16
+ # # refresh_materialized_view "admin_users"
17
+ # # ```
18
+ # #
19
+ # # The option `algorithm: :concurrently` acts exactly
20
+ # # like in the `create_index` definition. You should
21
+ # # possibly add the `disable_ddl_transaction!` command
22
+ # # to the migration as well.
23
+ # #
24
+ # # With option `with_data: false` the command won't
25
+ # # update the data. This option can't be used along with
26
+ # # the `:algorithm`.
27
+ # #
28
+ # # The operation is always reversible, though its
29
+ # # inversion does nothing.
30
+ # def refresh_materialized_view(name, **options); end
31
+ # end
27
32
  module PGTrunk::Operations::MaterializedViews
28
33
  # @private
29
34
  class RefreshMaterializedView < Base
@@ -1,27 +1,34 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#rename_materialized_view(name, **options)
4
- # Change the name and/or schema of a materialized view
5
- #
6
- # @param [#to_s] :name (nil) The qualified name of the view
7
- # @option [#to_s] :to (nil) The new qualified name for the view
8
- # @option [Boolean] :if_exists (false) Suppress the error when the view is absent
9
- #
10
- # A materialized view can be renamed by changing both the name
11
- # and the schema (namespace) it belongs to.
12
- #
13
- # rename_materialized_view "views.admin_users", to: "admins"
14
- #
15
- # With the `if_exists: true` option, the operation won't fail
16
- # even when the view wasn't existed.
17
- #
18
- # rename_materialized_view "admin_users",
19
- # to: "admins",
20
- # if_exists: true
21
- #
22
- # At the same time, the option makes a migration irreversible
23
- # due to uncertainty of the previous state of the database.
24
-
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Change the name and/or schema of a materialized view
6
+ # #
7
+ # # @param [#to_s] :name (nil) The qualified name of the view
8
+ # # @option options [#to_s] :to (nil) The new qualified name for the view
9
+ # # @option options [Boolean] :if_exists (false) Suppress the error when the view is absent
10
+ # # @return [void]
11
+ # #
12
+ # # A materialized view can be renamed by changing both the name
13
+ # # and the schema (namespace) it belongs to.
14
+ # #
15
+ # # ```ruby
16
+ # # rename_materialized_view "views.admin_users", to: "admins"
17
+ # # ```
18
+ # #
19
+ # # With the `if_exists: true` option, the operation won't fail
20
+ # # even when the view wasn't existed.
21
+ # #
22
+ # # ```ruby
23
+ # # rename_materialized_view "admin_users",
24
+ # # to: "admins",
25
+ # # if_exists: true
26
+ # # ```
27
+ # #
28
+ # # At the same time, the option makes a migration irreversible
29
+ # # due to uncertainty of the previous state of the database.
30
+ # def rename_materialized_view(name, **options); end
31
+ # end
25
32
  module PGTrunk::Operations::MaterializedViews
26
33
  # @private
27
34
  class RenameMaterializedView < Base
@@ -1,51 +1,58 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#change_procedure(name, **options, &block)
4
- # Modify a procedure
5
- #
6
- # @param [#to_s] name (nil) The qualified name of the procedure
7
- # @option [Boolean] :if_exists (false) Suppress the error when the procedure is absent
8
- # @yield [Proc] the block with the procedure's definition
9
- # @yieldparam The receiver of methods specifying the procedure
10
- #
11
- # The operation changes the procedure without dropping it
12
- # (which is useful when there are other objects
13
- # using the function and you don't want to change them all).
14
- #
15
- # You can change any property except for the name
16
- # (use `rename_function` instead) and `language`.
17
- #
18
- # change_procedure "metadata.set_foo(a int)" do |p|
19
- # p.body <<~SQL
20
- # SET foo = a
21
- # SQL
22
- # p.security :invoker
23
- # p.comment "Multiplies 2 integers"
24
- # SQL
25
- #
26
- # The example above is not invertible because of uncertainty
27
- # about the previous state of body and comment.
28
- # To define them, use a from options (available in a block syntax only):
29
- #
30
- # change_procedure "metadata.set_foo(a int)" do |p|
31
- # p.body <<~SQL, from: <<~SQL
32
- # SET foo = a
33
- # SQL
34
- # SET foo = -a
35
- # SQL
36
- # p.comment <<~MSG, from: <<~MSG
37
- # Multiplies 2 integers
38
- # MSG
39
- # Multiplies ints
40
- # MSG
41
- # p.security :invoker
42
- # SQL
43
- #
44
- # Like in the other operations, the procedure can be
45
- # identified by a qualified name (with types of arguments).
46
- # If it has no overloaded implementations,
47
- # the plain name is supported as well.
48
-
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Modify a procedure
6
+ # #
7
+ # # @param [#to_s] name (nil) The qualified name of the procedure
8
+ # # @option options [Boolean] :if_exists (false) Suppress the error when the procedure is absent
9
+ # # @yield [p] the block with the procedure's definition
10
+ # # @yieldparam Object receiver of methods specifying the procedure
11
+ # # @return [void]
12
+ # #
13
+ # # The operation changes the procedure without dropping it
14
+ # # (which is useful when there are other objects
15
+ # # using the function and you don't want to change them all).
16
+ # #
17
+ # # You can change any property except for the name
18
+ # # (use `rename_function` instead) and `language`.
19
+ # #
20
+ # # ```ruby
21
+ # # change_procedure "metadata.set_foo(a int)" do |p|
22
+ # # p.body <<~SQL
23
+ # # SET foo = a
24
+ # # SQL
25
+ # # p.security :invoker
26
+ # # p.comment "Multiplies 2 integers"
27
+ # # SQL
28
+ # # ```
29
+ # #
30
+ # # The example above is not invertible because of uncertainty
31
+ # # about the previous state of body and comment.
32
+ # # To define them, use a from options (available in a block syntax only):
33
+ # #
34
+ # # ```ruby
35
+ # # change_procedure "metadata.set_foo(a int)" do |p|
36
+ # # p.body <<~SQL, from: <<~SQL
37
+ # # SET foo = a
38
+ # # SQL
39
+ # # SET foo = -a
40
+ # # SQL
41
+ # # p.comment <<~MSG, from: <<~MSG
42
+ # # Multiplies 2 integers
43
+ # # MSG
44
+ # # Multiplies ints
45
+ # # MSG
46
+ # # p.security :invoker
47
+ # # SQL
48
+ # # ```
49
+ # #
50
+ # # Like in the other operations, the procedure can be
51
+ # # identified by a qualified name (with types of arguments).
52
+ # # If it has no overloaded implementations,
53
+ # # the plain name is supported as well.
54
+ # def change_procedure(name, **options, &block); end
55
+ # end
49
56
  module PGTrunk::Operations::Procedures
50
57
  # @private
51
58
  class ChangeProcedure < Base
@@ -1,58 +1,69 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#create_procedure(name, **options, &block)
4
- # Create a procedure
5
- #
6
- # @param [#to_s] name (nil)
7
- # The qualified name of the procedure with arguments and returned value type
8
- # @option [Boolean] :replace_existing (false) If the procedure should overwrite an existing one
9
- # @option [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
10
- # @option [#to_s] :body (nil) The body of the procedure
11
- # @option [Symbol] :security (:invoker) Define the role under which the procedure is invoked
12
- # Supported values: :invoker (default), :definer
13
- # @option [#to_s] :comment The description of the procedure
14
- # @yield [Proc] the block with the procedure's definition
15
- # @yieldparam The receiver of methods specifying the procedure
16
- #
17
- # The syntax of the operation is the same as for `create_function`,
18
- # but with only `security` option available. Notice, that
19
- # procedures cannot return values so you're expected not to
20
- # define a returned value as well.
21
- #
22
- # The procedure can be created either using inline syntax
23
- #
24
- # create_procedure "metadata.set_foo(a int)",
25
- # language: :sql,
26
- # body: "SET foo = a",
27
- # comment: "Sets foo value"
28
- #
29
- # or using a block:
30
- #
31
- # create_procedure "metadata.set_foo(a int)" do |p|
32
- # p.language "sql" # (default)
33
- # p.body <<~SQL
34
- # SET foo = a
35
- # SQL
36
- # p.security :invoker # (default), also :definer
37
- # p.comment "Multiplies 2 integers"
38
- # SQL
39
- #
40
- # With a `replace_existing: true` option,
41
- # it will be created using the `CREATE OR REPLACE` clause.
42
- # In this case the migration is irreversible because we
43
- # don't know if and how to restore its previous definition.
44
- #
45
- # create_procedure "set_foo(a int)",
46
- # body: "SET foo = a",
47
- # replace_existing: true
48
- #
49
- # A procedure without arguments is supported as well
50
- #
51
- # # the same as "do_something()"
52
- # create_procedure "do_something" do |p|
53
- # # ...
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Create a procedure
6
+ # #
7
+ # # @param [#to_s] name (nil)
8
+ # # The qualified name of the procedure with arguments and returned value type
9
+ # # @option options [Boolean] :replace_existing (false) If the procedure should overwrite an existing one
10
+ # # @option options [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
11
+ # # @option options [#to_s] :body (nil) The body of the procedure
12
+ # # @option options [Symbol] :security (:invoker) Define the role under which the procedure is invoked
13
+ # # Supported values: :invoker (default), :definer
14
+ # # @option options [#to_s] :comment The description of the procedure
15
+ # # @yield [p] the block with the procedure's definition
16
+ # # @yieldparam Object receiver of methods specifying the procedure
17
+ # # @return [void]
18
+ # #
19
+ # # The syntax of the operation is the same as for `create_function`,
20
+ # # but with only `security` option available. Notice, that
21
+ # # procedures cannot return values so you're expected not to
22
+ # # define a returned value as well.
23
+ # #
24
+ # # The procedure can be created either using inline syntax
25
+ # #
26
+ # # ```ruby
27
+ # # create_procedure "metadata.set_foo(a int)",
28
+ # # language: :sql,
29
+ # # body: "SET foo = a",
30
+ # # comment: "Sets foo value"
31
+ # # ```
32
+ # #
33
+ # # or using a block:
34
+ # #
35
+ # # ```ruby
36
+ # # create_procedure "metadata.set_foo(a int)" do |p|
37
+ # # p.language "sql" # (default)
38
+ # # p.body <<~SQL
39
+ # # SET foo = a
40
+ # # SQL
41
+ # # p.security :invoker # (default), also :definer
42
+ # # p.comment "Multiplies 2 integers"
43
+ # # SQL
44
+ # # ```
45
+ # #
46
+ # # With a `replace_existing: true` option,
47
+ # # it will be created using the `CREATE OR REPLACE` clause.
48
+ # # In this case the migration is irreversible because we
49
+ # # don't know if and how to restore its previous definition.
50
+ # #
51
+ # # ```ruby
52
+ # # create_procedure "set_foo(a int)",
53
+ # # body: "SET foo = a",
54
+ # # replace_existing: true
55
+ # # ```
56
+ # #
57
+ # # A procedure without arguments is supported as well
58
+ # #
59
+ # # ```ruby
60
+ # # # the same as "do_something()"
61
+ # # create_procedure "do_something" do |p|
62
+ # # # ...
63
+ # # end
64
+ # # ```
65
+ # def create_procedure(name, **options, &block); end
54
66
  # end
55
-
56
67
  module PGTrunk::Operations::Procedures
57
68
  # @private
58
69
  class CreateProcedure < Base