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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -15
- data/CHANGELOG.md +21 -0
- data/README.md +3 -1
- data/lib/pg_trunk/core/operation/attributes.rb +1 -1
- data/lib/pg_trunk/core/railtie/custom_types.rb +5 -6
- data/lib/pg_trunk/operations/check_constraints/add_check_constraint.rb +42 -33
- data/lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb +51 -40
- data/lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb +39 -30
- data/lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb +28 -21
- data/lib/pg_trunk/operations/composite_types/change_composite_type.rb +59 -50
- data/lib/pg_trunk/operations/composite_types/create_composite_type.rb +23 -19
- data/lib/pg_trunk/operations/composite_types/drop_composite_type.rb +48 -43
- data/lib/pg_trunk/operations/composite_types/rename_composite_type.rb +15 -12
- data/lib/pg_trunk/operations/domains/change_domain.rb +53 -47
- data/lib/pg_trunk/operations/domains/create_domain.rb +28 -25
- data/lib/pg_trunk/operations/domains/drop_domain.rb +50 -41
- data/lib/pg_trunk/operations/domains/rename_domain.rb +17 -12
- data/lib/pg_trunk/operations/enums/change_enum.rb +37 -32
- data/lib/pg_trunk/operations/enums/create_enum.rb +23 -20
- data/lib/pg_trunk/operations/enums/drop_enum.rb +50 -39
- data/lib/pg_trunk/operations/enums/rename_enum.rb +17 -12
- data/lib/pg_trunk/operations/foreign_keys/add_foreign_key.rb +58 -49
- data/lib/pg_trunk/operations/foreign_keys/drop_foreign_key.rb +57 -48
- data/lib/pg_trunk/operations/foreign_keys/rename_foreign_key.rb +38 -29
- data/lib/pg_trunk/operations/functions/change_function.rb +53 -47
- data/lib/pg_trunk/operations/functions/create_function.rb +75 -64
- data/lib/pg_trunk/operations/functions/drop_function.rb +78 -65
- data/lib/pg_trunk/operations/functions/rename_function.rb +29 -22
- data/lib/pg_trunk/operations/materialized_views/change_materialized_view.rb +65 -55
- data/lib/pg_trunk/operations/materialized_views/create_materialized_view.rb +82 -71
- data/lib/pg_trunk/operations/materialized_views/drop_materialized_view.rb +59 -46
- data/lib/pg_trunk/operations/materialized_views/refresh_materialized_view.rb +29 -24
- data/lib/pg_trunk/operations/materialized_views/rename_materialized_view.rb +29 -22
- data/lib/pg_trunk/operations/procedures/change_procedure.rb +53 -46
- data/lib/pg_trunk/operations/procedures/create_procedure.rb +63 -52
- data/lib/pg_trunk/operations/procedures/drop_procedure.rb +56 -45
- data/lib/pg_trunk/operations/procedures/rename_procedure.rb +29 -22
- data/lib/pg_trunk/operations/rules/base.rb +77 -0
- data/lib/pg_trunk/operations/rules/create_rule.rb +155 -0
- data/lib/pg_trunk/operations/rules/drop_rule.rb +94 -0
- data/lib/pg_trunk/operations/rules/rename_rule.rb +62 -0
- data/lib/pg_trunk/operations/rules.rb +13 -0
- data/lib/pg_trunk/operations/sequences/base.rb +79 -0
- data/lib/pg_trunk/operations/sequences/change_sequence.rb +142 -0
- data/lib/pg_trunk/operations/sequences/create_sequence.rb +180 -0
- data/lib/pg_trunk/operations/sequences/drop_sequence.rb +82 -0
- data/lib/pg_trunk/operations/sequences/rename_sequence.rb +64 -0
- data/lib/pg_trunk/operations/sequences.rb +14 -0
- data/lib/pg_trunk/operations/statistics/create_statistics.rb +67 -56
- data/lib/pg_trunk/operations/statistics/drop_statistics.rb +64 -53
- data/lib/pg_trunk/operations/statistics/rename_statistics.rb +18 -13
- data/lib/pg_trunk/operations/triggers/change_trigger.rb +23 -18
- data/lib/pg_trunk/operations/triggers/create_trigger.rb +63 -54
- data/lib/pg_trunk/operations/triggers/drop_trigger.rb +55 -46
- data/lib/pg_trunk/operations/triggers/rename_trigger.rb +51 -48
- data/lib/pg_trunk/operations/views/change_view.rb +47 -38
- data/lib/pg_trunk/operations/views/create_view.rb +56 -45
- data/lib/pg_trunk/operations/views/drop_view.rb +59 -46
- data/lib/pg_trunk/operations/views/rename_view.rb +27 -20
- data/lib/pg_trunk/operations.rb +2 -0
- data/lib/pg_trunk/version.rb +1 -1
- data/pg_trunk.gemspec +0 -1
- data/spec/operations/rules/create_rule_spec.rb +119 -0
- data/spec/operations/rules/drop_rule_spec.rb +117 -0
- data/spec/operations/rules/rename_rule_spec.rb +148 -0
- data/spec/operations/sequences/change_sequence_spec.rb +134 -0
- data/spec/operations/sequences/create_sequence_spec.rb +156 -0
- data/spec/operations/sequences/drop_sequence_spec.rb +102 -0
- data/spec/operations/sequences/rename_sequence_spec.rb +100 -0
- metadata +22 -68
@@ -1,45 +1,56 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @option [
|
9
|
-
# @option [
|
10
|
-
# @option [
|
11
|
-
# @
|
12
|
-
# @
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Drop an enumerated type by qualified name
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] name (nil) The qualified name of the type
|
8
|
+
# # @option options [Boolean] :if_exists (false) Suppress the error when the type is absent
|
9
|
+
# # @option options [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
|
10
|
+
# # @option options [Array<#to_s>] :values ([]) The list of values
|
11
|
+
# # @option options [#to_s] :comment (nil) The comment describing the constraint
|
12
|
+
# # @yield [e] the block with the type's definition
|
13
|
+
# # @yieldparam Object receiver of methods specifying the type
|
14
|
+
# # @return [void]
|
15
|
+
# #
|
16
|
+
# # The operation drops a enumerated type identified by its
|
17
|
+
# # qualified name (it can include a schema).
|
18
|
+
# #
|
19
|
+
# # ```ruby
|
20
|
+
# # drop_enum "finances.currency"
|
21
|
+
# # ```
|
22
|
+
# #
|
23
|
+
# # To make the operation invertible, use the same options
|
24
|
+
# # as in the `create_enum` operation.
|
25
|
+
# #
|
26
|
+
# # ```ruby
|
27
|
+
# # drop_enum "finances.currency" do |e|
|
28
|
+
# # e.values "BTC", "EUR", "GBP", "USD"
|
29
|
+
# # e.value "JPY" # the alternative way to add a value
|
30
|
+
# # e.comment <<~COMMENT
|
31
|
+
# # The list of values for supported currencies.
|
32
|
+
# # COMMENT
|
33
|
+
# # end
|
34
|
+
# # ```
|
35
|
+
# #
|
36
|
+
# # With the `force: :cascade` option the operation would remove
|
37
|
+
# # all the objects that use the type.
|
38
|
+
# #
|
39
|
+
# # ```ruby
|
40
|
+
# # drop_enum "finances.currency", force: :cascade
|
41
|
+
# # ```
|
42
|
+
# #
|
43
|
+
# # With the `if_exists: true` option the operation won't fail
|
44
|
+
# # even when the view was absent in the database.
|
45
|
+
# #
|
46
|
+
# # ```ruby
|
47
|
+
# # drop_enum "finances.currency", if_exists: true
|
48
|
+
# # ```
|
49
|
+
# #
|
50
|
+
# # Both options make a migration irreversible due to uncertainty
|
51
|
+
# # of the previous state of the database.
|
52
|
+
# def drop_enum(name, **options, &block); end
|
28
53
|
# end
|
29
|
-
#
|
30
|
-
# With the `force: :cascade` option the operation would remove
|
31
|
-
# all the objects that use the type.
|
32
|
-
#
|
33
|
-
# drop_enum "finances.currency", force: :cascade
|
34
|
-
#
|
35
|
-
# With the `if_exists: true` option the operation won't fail
|
36
|
-
# even when the view was absent in the database.
|
37
|
-
#
|
38
|
-
# drop_enum "finances.currency", if_exists: true
|
39
|
-
#
|
40
|
-
# Both options make a migration irreversible due to uncertainty
|
41
|
-
# of the previous state of the database.
|
42
|
-
|
43
54
|
module PGTrunk::Operations::Enums
|
44
55
|
# @private
|
45
56
|
class DropEnum < Base
|
@@ -1,17 +1,22 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
#
|
9
|
-
# @
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Change the name and/or schema of an enumerated type
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] :name (nil) The qualified name of the type
|
8
|
+
# # @option options [#to_s] :to (nil) The new qualified name for the type
|
9
|
+
# # @return [void]
|
10
|
+
# #
|
11
|
+
# # @example:
|
12
|
+
# #
|
13
|
+
# # ```ruby
|
14
|
+
# # rename_enum "currencies", to: "finances.currency"
|
15
|
+
# # ```
|
16
|
+
# #
|
17
|
+
# # The operation is always reversible.
|
18
|
+
# def rename_enum(name, to:); end
|
19
|
+
# end
|
15
20
|
module PGTrunk::Operations::Enums
|
16
21
|
# @private
|
17
22
|
class RenameEnum < Base
|
@@ -1,55 +1,64 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @option [#to_s] :
|
10
|
-
# @option [
|
11
|
-
# @option [
|
12
|
-
# @option [
|
13
|
-
# @option [
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# @
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
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 options [#to_s] :name (nil) The current name of the foreign key
|
10
|
+
# # @option options [#to_s] :to (nil) The new name for the foreign key
|
11
|
+
# # @option options [Array<#to_s>] :columns ([]) The list of columns of the table
|
12
|
+
# # @option options [#to_s] :column (nil) An alias for :columns for the case of single-column keys
|
13
|
+
# # @option options [Array<#to_s>] :primary_key ([]) The list of columns of the reference table
|
14
|
+
# # @option options [Symbol] :match (:full) Define how to match rows
|
15
|
+
# # Supported values: :full (default), :partial, :simple
|
16
|
+
# # @option options [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 options [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
|
+
# # ```ruby
|
30
|
+
# # # same as `..., column: 'role_id', primary_key: 'id'`
|
31
|
+
# # add_foreign_key :users, :roles
|
32
|
+
# # ```
|
33
|
+
# #
|
34
|
+
# # The block syntax can be used for any argument:
|
35
|
+
# #
|
36
|
+
# # ```ruby
|
37
|
+
# # add_foreign_key do |k|
|
38
|
+
# # k.table "users"
|
39
|
+
# # k.reference "roles"
|
40
|
+
# # k.column "role_id" # (generated by default from reference and pk)
|
41
|
+
# # k.primary_key "id" # (default)
|
42
|
+
# # k.on_update :cascade # :restrict (default)
|
43
|
+
# # k.on_delete :cascade # :restrict (default)
|
44
|
+
# # k.name "user_roles_fk" # can be generated
|
45
|
+
# # k.comment "Phone is 10+ chars long"
|
46
|
+
# # end
|
47
|
+
# # ```
|
48
|
+
# #
|
49
|
+
# # Composite foreign keys are supported as well:
|
50
|
+
# #
|
51
|
+
# # ```ruby
|
52
|
+
# # add_foreign_key "users", "roles" do |k|
|
53
|
+
# # k.columns %w[role_name role_id]
|
54
|
+
# # k.primary_key %w[name id] # Requires unique index
|
55
|
+
# # k.match :full # :partial, :simple (default)
|
56
|
+
# # end
|
57
|
+
# # ```
|
58
|
+
# #
|
59
|
+
# # The operation is always invertible.
|
60
|
+
# def add_foreign_key(table, reference, **options, &block); end
|
41
61
|
# 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
62
|
module PGTrunk::Operations::ForeignKeys
|
54
63
|
# @private
|
55
64
|
class AddForeignKey < Base
|
@@ -1,54 +1,63 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @option [
|
10
|
-
# @option [
|
11
|
-
# @option [
|
12
|
-
# @option [
|
13
|
-
# @option [
|
14
|
-
# @option [
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# @
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
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 options [#to_s] :name (nil) The current name of the foreign key
|
10
|
+
# # @option options [Boolean] :if_exists (false) Suppress the error when the constraint is absent
|
11
|
+
# # @option options [#to_s] :to (nil) The new name for the foreign key
|
12
|
+
# # @option options [Array<#to_s>] :columns ([]) The list of columns of the table
|
13
|
+
# # @option options [#to_s] :column (nil) An alias for :columns for the case of single-column keys
|
14
|
+
# # @option options [Array<#to_s>] :primary_key ([]) The list of columns of the reference table
|
15
|
+
# # @option options [Symbol] :match (:full) Define how to match rows
|
16
|
+
# # Supported values: :full (default), :partial, :simple
|
17
|
+
# # @option options [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 options [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
|
+
# # ```ruby
|
30
|
+
# # drop_foreign_key "users", name: "user_roles_fk"
|
31
|
+
# # ```
|
32
|
+
# #
|
33
|
+
# # To make it invertible use the same options like
|
34
|
+
# # in the `add_foreign_key` operation.
|
35
|
+
# #
|
36
|
+
# # ```ruby
|
37
|
+
# # drop_foreign_key do |k|
|
38
|
+
# # k.table "users"
|
39
|
+
# # k.reference "roles"
|
40
|
+
# # k.column "role_id"
|
41
|
+
# # k.primary_key "id"
|
42
|
+
# # k.on_update :cascade
|
43
|
+
# # k.on_delete :cascade
|
44
|
+
# # k.comment "Phone is 10+ chars long"
|
45
|
+
# # end
|
46
|
+
# # ```
|
47
|
+
# #
|
48
|
+
# # Notice that the name can be skipped, in this case we would
|
49
|
+
# # find it in the database.
|
50
|
+
# #
|
51
|
+
# # The operation can be called with `if_exists` option.
|
52
|
+
# #
|
53
|
+
# # ```ruby
|
54
|
+
# # drop_foreign_key "users", name: "user_roles_fk", if_exists: true
|
55
|
+
# # ```
|
56
|
+
# #
|
57
|
+
# # In this case the operation is always irreversible due to
|
58
|
+
# # uncertainty of the previous state of the database.
|
59
|
+
# def drop_foreign_key(table, reference, **options, &block); end
|
40
60
|
# 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
61
|
module PGTrunk::Operations::ForeignKeys
|
53
62
|
# @private
|
54
63
|
class DropForeignKey < Base
|
@@ -1,34 +1,43 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @option [#to_s] :
|
10
|
-
# @option [
|
11
|
-
# @option [
|
12
|
-
# @option [
|
13
|
-
# @
|
14
|
-
# @
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
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 options [#to_s] :name (nil) The current name of the foreign key
|
10
|
+
# # @option options [#to_s] :to (nil) The new name for the foreign key
|
11
|
+
# # @option options [Array<#to_s>] :columns ([]) The list of columns of the table
|
12
|
+
# # @option options [#to_s] :column (nil) An alias for :columns for the case of single-column keys
|
13
|
+
# # @option options [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
|
+
# # ```ruby
|
21
|
+
# # rename_foreign_key :users,
|
22
|
+
# # name: "user_roles_fk",
|
23
|
+
# # to: "constraints.users_by_roles_fk"
|
24
|
+
# # ```
|
25
|
+
# #
|
26
|
+
# # The key can also be found in the database by table/reference/columns/pk
|
27
|
+
# #
|
28
|
+
# # ```ruby
|
29
|
+
# # rename_foreign_key :users, :roles, primary_key: "name", to: "user_roles"
|
30
|
+
# # ```
|
31
|
+
# #
|
32
|
+
# # If a new name is missed, then the name will be reset to the auto-generated one:
|
33
|
+
# #
|
34
|
+
# # ```ruby
|
35
|
+
# # rename_foreign_key :users, "user_roles_fk"
|
36
|
+
# # ```
|
37
|
+
# #
|
38
|
+
# # The operation is always reversible.
|
39
|
+
# def rename_foreign_key(table, reference, **options, &block); end
|
40
|
+
# end
|
32
41
|
module PGTrunk::Operations::ForeignKeys
|
33
42
|
#
|
34
43
|
# Definition for the `rename_foreign_key` operation
|
@@ -1,52 +1,58 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @
|
9
|
-
# @
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# f.
|
23
|
-
# f.
|
24
|
-
# f.
|
25
|
-
# #
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# f.
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# #
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
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 options [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
|
+
# # ```ruby
|
21
|
+
# # change_function "math.mult(int, int)" do |f|
|
22
|
+
# # f.volatility :immutable, from: :stable
|
23
|
+
# # f.parallel :safe, from: :restricted
|
24
|
+
# # f.security :invoker
|
25
|
+
# # f.leakproof true
|
26
|
+
# # f.strict true
|
27
|
+
# # f.cost 5.0
|
28
|
+
# # # f.rows 1 (supported for functions returning sets of rows)
|
29
|
+
# # SQL
|
30
|
+
# # ```
|
31
|
+
# #
|
32
|
+
# # The example above is not invertible because of uncertainty
|
33
|
+
# # about the previous volatility, parallelism, and cost.
|
34
|
+
# # To define them, use a from options (available in a block syntax only):
|
35
|
+
# #
|
36
|
+
# # ```ruby
|
37
|
+
# # change_function "math.mult(a int, b int)" do |f|
|
38
|
+
# # f.body <<~SQL, from: <<~SQL
|
39
|
+
# # SELECT a * b;
|
40
|
+
# # SQL
|
41
|
+
# # SELECT min(a * b, 1);
|
42
|
+
# # SQL
|
43
|
+
# # f.volatility :immutable, from: :volatile
|
44
|
+
# # f.parallel :safe, from: :unsafe
|
45
|
+
# # f.leakproof true
|
46
|
+
# # f.strict true
|
47
|
+
# # f.cost 5.0, from: 100.0
|
48
|
+
# # SQL
|
49
|
+
# # ```
|
50
|
+
# #
|
51
|
+
# # Like in the other operations, the function can be
|
52
|
+
# # identified by a qualified name (with types of arguments).
|
53
|
+
# # If it has no overloaded implementations, the plain name is supported as well.
|
54
|
+
# def change_function(name, **options, &block); end
|
55
|
+
# end
|
50
56
|
module PGTrunk::Operations::Functions
|
51
57
|
# @private
|
52
58
|
class ChangeFunction < Base
|