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,55 +1,58 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#add_foreign_key(table, reference, **options, &block)
4
- # Create a foreign key constraint
5
- #
6
- # @param [#to_s] table (nil) The qualified name of the table
7
- # @param [#to_s] reference (nil) The qualified name of the reference table
8
- # @option [#to_s] :name (nil) The current name of the foreign key
9
- # @option [#to_s] :to (nil) The new name for the foreign key
10
- # @option [Array<#to_s>] :columns ([]) The list of columns of the table
11
- # @option [#to_s] :column (nil) An alias for :columns for the case of single-column keys
12
- # @option [Array<#to_s>] :primary_key ([]) The list of columns of the reference table
13
- # @option [Symbol] :match (:full) Define how to match rows
14
- # Supported values: :full (default), :partial, :simple
15
- # @option [Symbol] :on_delete (:restrict)
16
- # Define how to handle the deletion of the referred row.
17
- # Supported values: :restrict (default), :cascade, :nullify, :reset
18
- # @option [Symbol] :on_update (:restrict)
19
- # Define how to handle the update of the referred row.
20
- # Supported values: :restrict (default), :cascade, :nullify, :reset
21
- # @yield [Proc] the block with the key's definition
22
- # @yieldparam The receiver of methods specifying the foreign key
23
- #
24
- # The table and reference of the new key must be set explicitly.
25
- # All the rest (including the name) can be generated by default:
26
- #
27
- # # same as `..., column: 'role_id', primary_key: 'id'`
28
- # add_foreign_key :users, :roles
29
- #
30
- # The block syntax can be used for any argument:
31
- #
32
- # add_foreign_key do |c|
33
- # c.table "users"
34
- # c.reference "roles"
35
- # c.column "role_id" # (generated by default from reference and pk)
36
- # c.primary_key "id" # (default)
37
- # c.on_update :cascade # :restrict (default)
38
- # c.on_delete :cascade # :restrict (default)
39
- # c.name "user_roles_fk" # can be generated
40
- # c.comment "Phone is 10+ chars long"
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Create a foreign key constraint
6
+ # #
7
+ # # @param [#to_s] table (nil) The qualified name of the table
8
+ # # @param [#to_s] reference (nil) The qualified name of the reference table
9
+ # # @option [#to_s] :name (nil) The current name of the foreign key
10
+ # # @option [#to_s] :to (nil) The new name for the foreign key
11
+ # # @option [Array<#to_s>] :columns ([]) The list of columns of the table
12
+ # # @option [#to_s] :column (nil) An alias for :columns for the case of single-column keys
13
+ # # @option [Array<#to_s>] :primary_key ([]) The list of columns of the reference table
14
+ # # @option [Symbol] :match (:full) Define how to match rows
15
+ # # Supported values: :full (default), :partial, :simple
16
+ # # @option [Symbol] :on_delete (:restrict)
17
+ # # Define how to handle the deletion of the referred row.
18
+ # # Supported values: :restrict (default), :cascade, :nullify, :reset
19
+ # # @option [Symbol] :on_update (:restrict)
20
+ # # Define how to handle the update of the referred row.
21
+ # # Supported values: :restrict (default), :cascade, :nullify, :reset
22
+ # # @yield [k] the block with the key's definition
23
+ # # @yieldparam Object receiver of methods specifying the foreign key
24
+ # # @return [void]
25
+ # #
26
+ # # The table and reference of the new key must be set explicitly.
27
+ # # All the rest (including the name) can be generated by default:
28
+ # #
29
+ # # # same as `..., column: 'role_id', primary_key: 'id'`
30
+ # # add_foreign_key :users, :roles
31
+ # #
32
+ # # The block syntax can be used for any argument:
33
+ # #
34
+ # # add_foreign_key do |k|
35
+ # # k.table "users"
36
+ # # k.reference "roles"
37
+ # # k.column "role_id" # (generated by default from reference and pk)
38
+ # # k.primary_key "id" # (default)
39
+ # # k.on_update :cascade # :restrict (default)
40
+ # # k.on_delete :cascade # :restrict (default)
41
+ # # k.name "user_roles_fk" # can be generated
42
+ # # k.comment "Phone is 10+ chars long"
43
+ # # end
44
+ # #
45
+ # # Composite foreign keys are supported as well:
46
+ # #
47
+ # # add_foreign_key "users", "roles" do |k|
48
+ # # k.columns %w[role_name role_id]
49
+ # # k.primary_key %w[name id] # Requires unique index
50
+ # # k.match :full # :partial, :simple (default)
51
+ # # end
52
+ # #
53
+ # # The operation is always invertible.
54
+ # def add_foreign_key(table, reference, **options, &block); end
41
55
  # end
42
- #
43
- # Composite foreign keys are supported as well:
44
- #
45
- # add_foreign_key "users", "roles" do |c|
46
- # c.columns %w[role_name role_id]
47
- # c.primary_key %w[name id] # Requires unique index
48
- # c.match :full # :partial, :simple (default)
49
- # end
50
- #
51
- # The operation is always invertible.
52
-
53
56
  module PGTrunk::Operations::ForeignKeys
54
57
  # @private
55
58
  class AddForeignKey < Base
@@ -1,54 +1,57 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#drop_foreign_key(table, reference, **options, &block)
4
- # Drops a foreign key constraint
5
- #
6
- # @param [#to_s] table (nil) The qualified name of the table
7
- # @param [#to_s] reference (nil) The qualified name of the reference table
8
- # @option [#to_s] :name (nil) The current name of the foreign key
9
- # @option [Boolean] :if_exists (false) Suppress the error when the constraint is absent
10
- # @option [#to_s] :to (nil) The new name for the foreign key
11
- # @option [Array<#to_s>] :columns ([]) The list of columns of the table
12
- # @option [#to_s] :column (nil) An alias for :columns for the case of single-column keys
13
- # @option [Array<#to_s>] :primary_key ([]) The list of columns of the reference table
14
- # @option [Symbol] :match (:full) Define how to match rows
15
- # Supported values: :full (default), :partial, :simple
16
- # @option [Symbol] :on_delete (:restrict)
17
- # Define how to handle the deletion of the referred row.
18
- # Supported values: :restrict (default), :cascade, :nullify, :reset
19
- # @option [Symbol] :on_update (:restrict)
20
- # Define how to handle the update of the referred row.
21
- # Supported values: :restrict (default), :cascade, :nullify, :reset
22
- # @yield [Proc] the block with the key's definition
23
- # @yieldparam The receiver of methods specifying the foreign key
24
- #
25
- # The key can be identified by table/name (not invertible):
26
- #
27
- # drop_foreign_key "users", name: "user_roles_fk"
28
- #
29
- # To make it invertible use the same options like
30
- # in the `add_foreign_key` operation.
31
- #
32
- # drop_foreign_key do |c|
33
- # c.table "users"
34
- # c.reference "roles"
35
- # c.column "role_id"
36
- # c.primary_key "id"
37
- # c.on_update :cascade
38
- # c.on_delete :cascade
39
- # c.comment "Phone is 10+ chars long"
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Drops a foreign key constraint
6
+ # #
7
+ # # @param [#to_s] table (nil) The qualified name of the table
8
+ # # @param [#to_s] reference (nil) The qualified name of the reference table
9
+ # # @option [#to_s] :name (nil) The current name of the foreign key
10
+ # # @option [Boolean] :if_exists (false) Suppress the error when the constraint is absent
11
+ # # @option [#to_s] :to (nil) The new name for the foreign key
12
+ # # @option [Array<#to_s>] :columns ([]) The list of columns of the table
13
+ # # @option [#to_s] :column (nil) An alias for :columns for the case of single-column keys
14
+ # # @option [Array<#to_s>] :primary_key ([]) The list of columns of the reference table
15
+ # # @option [Symbol] :match (:full) Define how to match rows
16
+ # # Supported values: :full (default), :partial, :simple
17
+ # # @option [Symbol] :on_delete (:restrict)
18
+ # # Define how to handle the deletion of the referred row.
19
+ # # Supported values: :restrict (default), :cascade, :nullify, :reset
20
+ # # @option [Symbol] :on_update (:restrict)
21
+ # # Define how to handle the update of the referred row.
22
+ # # Supported values: :restrict (default), :cascade, :nullify, :reset
23
+ # # @yield [k] the block with the key's definition
24
+ # # @yieldparam Object receiver of methods specifying the foreign key
25
+ # # @return [void]
26
+ # #
27
+ # # The key can be identified by table/name (not invertible):
28
+ # #
29
+ # # drop_foreign_key "users", name: "user_roles_fk"
30
+ # #
31
+ # # To make it invertible use the same options like
32
+ # # in the `add_foreign_key` operation.
33
+ # #
34
+ # # drop_foreign_key do |k|
35
+ # # k.table "users"
36
+ # # k.reference "roles"
37
+ # # k.column "role_id"
38
+ # # k.primary_key "id"
39
+ # # k.on_update :cascade
40
+ # # k.on_delete :cascade
41
+ # # k.comment "Phone is 10+ chars long"
42
+ # # end
43
+ # #
44
+ # # Notice that the name can be skipped, in this case we would
45
+ # # find it in the database.
46
+ # #
47
+ # # The operation can be called with `if_exists` option.
48
+ # #
49
+ # # drop_foreign_key "users", name: "user_roles_fk", if_exists: true
50
+ # #
51
+ # # In this case the operation is always irreversible due to
52
+ # # uncertainty of the previous state of the database.
53
+ # def drop_foreign_key(table, reference, **options, &block); end
40
54
  # end
41
- #
42
- # Notice that the name can be skipped, in this case we would
43
- # find it in the database.
44
- #
45
- # The operation can be called with `if_exists` option.
46
- #
47
- # drop_foreign_key "users", name: "user_roles_fk", if_exists: true
48
- #
49
- # In this case the operation is always irreversible due to
50
- # uncertainty of the previous state of the database.
51
-
52
55
  module PGTrunk::Operations::ForeignKeys
53
56
  # @private
54
57
  class DropForeignKey < Base
@@ -1,34 +1,37 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#rename_foreign_key(table, reference, **options, &block)
4
- # Rename a foreign key
5
- #
6
- # @param [#to_s] table (nil) The qualified name of the table
7
- # @param [#to_s] reference (nil) The qualified name of the reference table
8
- # @option [#to_s] :name (nil) The current name of the foreign key
9
- # @option [#to_s] :to (nil) The new name for the foreign key
10
- # @option [Array<#to_s>] :columns ([]) The list of columns of the table
11
- # @option [#to_s] :column (nil) An alias for :columns for the case of single-column keys
12
- # @option [Array<#to_s>] :primary_key ([]) The list of columns of the reference table
13
- # @yield [Proc] the block with the key's definition
14
- # @yieldparam The receiver of methods specifying the foreign key
15
- #
16
- # You can rename the foreign key constraint identified by its explicit name:
17
- #
18
- # rename_foreign_key :users,
19
- # name: "user_roles_fk",
20
- # to: "constraints.users_by_roles_fk"
21
- #
22
- # The key can also be found in the database by table/reference/columns/pk
23
- #
24
- # rename_foreign_key :users, :roles, primary_key: "name", to: "user_roles"
25
- #
26
- # If a new name is missed, then the name will be reset to the auto-generated one:
27
- #
28
- # rename_foreign_key :users, "user_roles_fk"
29
- #
30
- # The operation is always reversible.
31
-
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Rename a foreign key
6
+ # #
7
+ # # @param [#to_s] table (nil) The qualified name of the table
8
+ # # @param [#to_s] reference (nil) The qualified name of the reference table
9
+ # # @option [#to_s] :name (nil) The current name of the foreign key
10
+ # # @option [#to_s] :to (nil) The new name for the foreign key
11
+ # # @option [Array<#to_s>] :columns ([]) The list of columns of the table
12
+ # # @option [#to_s] :column (nil) An alias for :columns for the case of single-column keys
13
+ # # @option [Array<#to_s>] :primary_key ([]) The list of columns of the reference table
14
+ # # @yield [k] the block with the key's definition
15
+ # # @yieldparam Object receiver of methods specifying the foreign key
16
+ # # @return [void]
17
+ # #
18
+ # # You can rename the foreign key constraint identified by its explicit name:
19
+ # #
20
+ # # rename_foreign_key :users,
21
+ # # name: "user_roles_fk",
22
+ # # to: "constraints.users_by_roles_fk"
23
+ # #
24
+ # # The key can also be found in the database by table/reference/columns/pk
25
+ # #
26
+ # # rename_foreign_key :users, :roles, primary_key: "name", to: "user_roles"
27
+ # #
28
+ # # If a new name is missed, then the name will be reset to the auto-generated one:
29
+ # #
30
+ # # rename_foreign_key :users, "user_roles_fk"
31
+ # #
32
+ # # The operation is always reversible.
33
+ # def rename_foreign_key(table, reference, **options, &block); end
34
+ # end
32
35
  module PGTrunk::Operations::ForeignKeys
33
36
  #
34
37
  # Definition for the `rename_foreign_key` operation
@@ -1,52 +1,55 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#change_function(name, **options, &block)
4
- # Modify a function
5
- #
6
- # @param [#to_s] name (nil) The qualified name of the function
7
- # @option [Boolean] :if_exists (false) Suppress the error when the function is absent
8
- # @yield [Proc] the block with the function's definition
9
- # @yieldparam The receiver of methods specifying the function
10
- #
11
- # The operation changes the function without dropping it
12
- # (which can be necessary 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_function "math.mult(int, int)" do |f|
19
- # f.volatility :immutable, from: :stable
20
- # f.parallel :safe, from: :restricted
21
- # f.security :invoker
22
- # f.leakproof true
23
- # f.strict true
24
- # f.cost 5.0
25
- # # f.rows 1 (supported for functions returning sets of rows)
26
- # SQL
27
- #
28
- # The example above is not invertible because of uncertainty
29
- # about the previous volatility, parallelism, and cost.
30
- # To define them, use a from options (available in a block syntax only):
31
- #
32
- # change_function "math.mult(a int, b int)" do |f|
33
- # f.body <<~SQL, from: <<~SQL
34
- # SELECT a * b;
35
- # SQL
36
- # SELECT min(a * b, 1);
37
- # SQL
38
- # f.volatility :immutable, from: :volatile
39
- # f.parallel :safe, from: :unsafe
40
- # f.leakproof true
41
- # f.strict true
42
- # f.cost 5.0, from: 100.0
43
- # # f.rows 1, from: 0
44
- # SQL
45
- #
46
- # Like in the other operations, the function can be
47
- # identified by a qualified name (with types of arguments).
48
- # If it has no overloaded implementations, the plain name is supported as well.
49
-
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Modify a function
6
+ # #
7
+ # # @param [#to_s] name (nil) The qualified name of the function
8
+ # # @option [Boolean] :if_exists (false) Suppress the error when the function is absent
9
+ # # @yield [f] the block with the function's definition
10
+ # # @yieldparam Object receiver of methods specifying the function
11
+ # # @return [void]
12
+ # #
13
+ # # The operation changes the function without dropping it
14
+ # # (which can be necessary 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
+ # # change_function "math.mult(int, int)" do |f|
21
+ # # f.volatility :immutable, from: :stable
22
+ # # f.parallel :safe, from: :restricted
23
+ # # f.security :invoker
24
+ # # f.leakproof true
25
+ # # f.strict true
26
+ # # f.cost 5.0
27
+ # # # f.rows 1 (supported for functions returning sets of rows)
28
+ # # SQL
29
+ # #
30
+ # # The example above is not invertible because of uncertainty
31
+ # # about the previous volatility, parallelism, and cost.
32
+ # # To define them, use a from options (available in a block syntax only):
33
+ # #
34
+ # # change_function "math.mult(a int, b int)" do |f|
35
+ # # f.body <<~SQL, from: <<~SQL
36
+ # # SELECT a * b;
37
+ # # SQL
38
+ # # SELECT min(a * b, 1);
39
+ # # SQL
40
+ # # f.volatility :immutable, from: :volatile
41
+ # # f.parallel :safe, from: :unsafe
42
+ # # f.leakproof true
43
+ # # f.strict true
44
+ # # f.cost 5.0, from: 100.0
45
+ # # # f.rows 1, from: 0
46
+ # # SQL
47
+ # #
48
+ # # Like in the other operations, the function can be
49
+ # # identified by a qualified name (with types of arguments).
50
+ # # If it has no overloaded implementations, the plain name is supported as well.
51
+ # def change_function(name, **options, &block); end
52
+ # end
50
53
  module PGTrunk::Operations::Functions
51
54
  # @private
52
55
  class ChangeFunction < Base
@@ -1,70 +1,73 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#create_function(name, **options, &block)
4
- # Create a function
5
- #
6
- # @param [#to_s] name (nil)
7
- # The qualified name of the function with arguments and returned value type
8
- # @option [Boolean] :replace_existing (false) If the function 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 function
11
- # @option [Symbol] :volatility (:volatile) The volatility of the function.
12
- # Supported values: :volatile (default), :stable, :immutable
13
- # @option [Symbol] :parallel (:unsafe) The safety of parallel execution.
14
- # Supported values: :unsafe (default), :restricted, :safe
15
- # @option [Symbol] :security (:invoker) Define the role under which the function is invoked
16
- # Supported values: :invoker (default), :definer
17
- # @option [Boolean] :leakproof (false) If the function is leakproof
18
- # @option [Boolean] :strict (false) If the function is strict
19
- # @option [Float] :cost (nil) The cost estimation for the function
20
- # @option [Integer] :rows (nil) The number of rows returned by a function
21
- # @option [#to_s] :comment The description of the function
22
- # @yield [Proc] the block with the function's definition
23
- # @yieldparam The receiver of methods specifying the function
24
- #
25
- # The function can be created either using inline syntax
26
- #
27
- # create_function "math.mult(a int, b int) int",
28
- # language: :sql,
29
- # body: "SELECT a * b",
30
- # volatility: :immutable,
31
- # leakproof: true,
32
- # comment: "Multiplies 2 integers"
33
- #
34
- # or using a block:
35
- #
36
- # create_function "math.mult(a int, b int) int" do |f|
37
- # f.language "sql" # (default)
38
- # f.body <<~SQL
39
- # SELECT a * b;
40
- # SQL
41
- # f.volatility :immutable # :stable, :volatile (default)
42
- # f.parallel :safe # :restricted, :unsafe (default)
43
- # f.security :invoker # (default), also :definer
44
- # f.leakproof true
45
- # f.strict true
46
- # f.cost 5.0
47
- # # f.rows 1 (supported for functions returning sets of rows)
48
- # f.comment "Multiplies 2 integers"
49
- # SQL
50
- #
51
- # With a `replace_existing: true` option,
52
- # it will be created using the `CREATE OR REPLACE` clause.
53
- # In this case the migration is irreversible because we
54
- # don't know if and how to restore its previous definition.
55
- #
56
- # create_function "math.mult(a int, b int) int",
57
- # body: "SELECT a * b",
58
- # replace_existing: true
59
- #
60
- # We presume a function without arguments should have
61
- # no arguments and return `void` like
62
- #
63
- # # the same as "do_something() void"
64
- # create_function "do_something" do |f|
65
- # # ...
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Create a function
6
+ # #
7
+ # # @param [#to_s] name (nil)
8
+ # # The qualified name of the function with arguments and returned value type
9
+ # # @option [Boolean] :replace_existing (false) If the function should overwrite an existing one
10
+ # # @option [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
11
+ # # @option [#to_s] :body (nil) The body of the function
12
+ # # @option [Symbol] :volatility (:volatile) The volatility of the function.
13
+ # # Supported values: :volatile (default), :stable, :immutable
14
+ # # @option [Symbol] :parallel (:unsafe) The safety of parallel execution.
15
+ # # Supported values: :unsafe (default), :restricted, :safe
16
+ # # @option [Symbol] :security (:invoker) Define the role under which the function is invoked
17
+ # # Supported values: :invoker (default), :definer
18
+ # # @option [Boolean] :leakproof (false) If the function is leakproof
19
+ # # @option [Boolean] :strict (false) If the function is strict
20
+ # # @option [Float] :cost (nil) The cost estimation for the function
21
+ # # @option [Integer] :rows (nil) The number of rows returned by a function
22
+ # # @option [#to_s] :comment The description of the function
23
+ # # @yield [f] the block with the function's definition
24
+ # # @yieldparam Object receiver of methods specifying the function
25
+ # # @return [void]
26
+ # #
27
+ # # The function can be created either using inline syntax
28
+ # #
29
+ # # create_function "math.mult(a int, b int) int",
30
+ # # language: :sql,
31
+ # # body: "SELECT a * b",
32
+ # # volatility: :immutable,
33
+ # # leakproof: true,
34
+ # # comment: "Multiplies 2 integers"
35
+ # #
36
+ # # or using a block:
37
+ # #
38
+ # # create_function "math.mult(a int, b int) int" do |f|
39
+ # # f.language "sql" # (default)
40
+ # # f.body <<~SQL
41
+ # # SELECT a * b;
42
+ # # SQL
43
+ # # f.volatility :immutable # :stable, :volatile (default)
44
+ # # f.parallel :safe # :restricted, :unsafe (default)
45
+ # # f.security :invoker # (default), also :definer
46
+ # # f.leakproof true
47
+ # # f.strict true
48
+ # # f.cost 5.0
49
+ # # # f.rows 1 (supported for functions returning sets of rows)
50
+ # # f.comment "Multiplies 2 integers"
51
+ # # SQL
52
+ # #
53
+ # # With a `replace_existing: true` option,
54
+ # # it will be created using the `CREATE OR REPLACE` clause.
55
+ # # In this case the migration is irreversible because we
56
+ # # don't know if and how to restore its previous definition.
57
+ # #
58
+ # # create_function "math.mult(a int, b int) int",
59
+ # # body: "SELECT a * b",
60
+ # # replace_existing: true
61
+ # #
62
+ # # We presume a function without arguments should have
63
+ # # no arguments and return `void` like
64
+ # #
65
+ # # # the same as "do_something() void"
66
+ # # create_function "do_something" do |f|
67
+ # # # ...
68
+ # # end
69
+ # def create_function(name, **options, &block); end
66
70
  # end
67
-
68
71
  module PGTrunk::Operations::Functions
69
72
  # @private
70
73
  class CreateFunction < Base