pg_trunk 0.1.1 → 0.1.2
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/CHANGELOG.md +5 -1
- data/README.md +1 -1
- data/lib/pg_trunk/core/railtie/custom_types.rb +5 -6
- data/lib/pg_trunk/operations/check_constraints/add_check_constraint.rb +18 -12
- data/lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb +18 -10
- data/lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb +12 -6
- data/lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb +6 -2
- data/lib/pg_trunk/operations/composite_types/change_composite_type.rb +24 -18
- data/lib/pg_trunk/operations/composite_types/create_composite_type.rb +10 -9
- data/lib/pg_trunk/operations/composite_types/drop_composite_type.rb +25 -23
- data/lib/pg_trunk/operations/composite_types/rename_composite_type.rb +3 -3
- data/lib/pg_trunk/operations/domains/change_domain.rb +27 -24
- data/lib/pg_trunk/operations/domains/create_domain.rb +11 -11
- data/lib/pg_trunk/operations/domains/drop_domain.rb +19 -13
- data/lib/pg_trunk/operations/domains/rename_domain.rb +3 -1
- data/lib/pg_trunk/operations/enums/change_enum.rb +13 -11
- data/lib/pg_trunk/operations/enums/create_enum.rb +9 -9
- data/lib/pg_trunk/operations/enums/drop_enum.rb +18 -10
- data/lib/pg_trunk/operations/enums/rename_enum.rb +3 -1
- data/lib/pg_trunk/operations/foreign_keys/add_foreign_key.rb +23 -17
- data/lib/pg_trunk/operations/foreign_keys/drop_foreign_key.rb +17 -11
- data/lib/pg_trunk/operations/foreign_keys/rename_foreign_key.rb +11 -5
- data/lib/pg_trunk/operations/functions/change_function.rb +24 -21
- data/lib/pg_trunk/operations/functions/create_function.rb +34 -26
- data/lib/pg_trunk/operations/functions/drop_function.rb +28 -18
- data/lib/pg_trunk/operations/functions/rename_function.rb +6 -2
- data/lib/pg_trunk/operations/materialized_views/change_materialized_view.rb +24 -17
- data/lib/pg_trunk/operations/materialized_views/create_materialized_view.rb +37 -29
- data/lib/pg_trunk/operations/materialized_views/drop_materialized_view.rb +20 -10
- data/lib/pg_trunk/operations/materialized_views/refresh_materialized_view.rb +3 -1
- data/lib/pg_trunk/operations/materialized_views/rename_materialized_view.rb +8 -4
- data/lib/pg_trunk/operations/procedures/change_procedure.rb +22 -18
- data/lib/pg_trunk/operations/procedures/create_procedure.rb +26 -18
- data/lib/pg_trunk/operations/procedures/drop_procedure.rb +18 -10
- data/lib/pg_trunk/operations/procedures/rename_procedure.rb +6 -2
- data/lib/pg_trunk/operations/statistics/create_statistics.rb +32 -24
- data/lib/pg_trunk/operations/statistics/drop_statistics.rb +26 -18
- data/lib/pg_trunk/operations/statistics/rename_statistics.rb +3 -1
- data/lib/pg_trunk/operations/triggers/change_trigger.rb +9 -7
- data/lib/pg_trunk/operations/triggers/create_trigger.rb +26 -20
- data/lib/pg_trunk/operations/triggers/drop_trigger.rb +16 -10
- data/lib/pg_trunk/operations/views/change_view.rb +20 -14
- data/lib/pg_trunk/operations/views/create_view.rb +18 -10
- data/lib/pg_trunk/operations/views/drop_view.rb +19 -9
- data/lib/pg_trunk/operations/views/rename_view.rb +6 -2
- data/lib/pg_trunk/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e7e7834f9f7da413371ea11262161da230fab549707bad615f3d5ab4ad9b19c
|
4
|
+
data.tar.gz: 14084be1a484bd0a7201f33d680546a1bba2ff8e5b34bc59aa3f3597f5d48c87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 056da9038cee7e60551a7b1ddb3cf990fe6a0eaeee95b48b95b38babd777ec97e9cce2564e3c1e1dbcd13a30072360beb87a0f20f48c152b2080997e0e489cd6
|
7
|
+
data.tar.gz: c83b7f738860de782e7cf407cfdbcd71fbfe3e3c5f995aa3a4fcdc7643e9a000f69eeca02b4c025e4219f5ecf19fb24781704e4fc8524944c7e11a9bc18f355e
|
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,13 @@ The noteworthy changes for each PGTrunk version are included here.
|
|
4
4
|
The format is based on [Keep a Changelog] and this project adheres to [Semantic Versioning].
|
5
5
|
For a complete changelog, see the [commits] for each version via the version links.
|
6
6
|
|
7
|
+
## [0.1.2] (2022-01-17)
|
8
|
+
|
9
|
+
* Fix registry of custom types (nepalez)
|
10
|
+
|
7
11
|
## [0.1.1] (2022-01-16)
|
8
12
|
|
9
|
-
* Fix inline documentation for methods added to ActiveRecord::Migration
|
13
|
+
* Fix inline documentation for methods added to ActiveRecord::Migration (nepalez)
|
10
14
|
|
11
15
|
## [0.1.0] (2022-01-14)
|
12
16
|
|
data/README.md
CHANGED
@@ -88,7 +88,7 @@ The gem is targeted to support PostgreSQL-specific features, that's why we won't
|
|
88
88
|
## Documentation
|
89
89
|
|
90
90
|
The gem provides a lot of additional methods to create, rename, change a drop various objects.
|
91
|
-
You can find the necessary details
|
91
|
+
You can find the necessary details [here](https://rubydoc.info/gems/pg_trunk/ActiveRecord/Migration).
|
92
92
|
|
93
93
|
## Installation
|
94
94
|
|
@@ -12,22 +12,21 @@ module PGTrunk
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def enable_pg_trunk_types
|
15
|
-
execute(<<~SQL).each { |item| enable_pg_trunk_type
|
15
|
+
execute(<<~SQL).each { |item| enable_pg_trunk_type(**item.symbolize_keys) }
|
16
16
|
SELECT (
|
17
17
|
CASE
|
18
18
|
WHEN t.typnamespace = 'public'::regnamespace THEN t.typname
|
19
19
|
ELSE t.typnamespace::regnamespace || '.' || t.typname
|
20
20
|
END
|
21
|
-
) AS name
|
21
|
+
) AS name, t.oid
|
22
22
|
FROM pg_trunk e JOIN pg_type t ON t.oid = e.oid
|
23
23
|
WHERE e.classid = 'pg_type'::regclass
|
24
24
|
SQL
|
25
25
|
end
|
26
26
|
|
27
|
-
def enable_pg_trunk_type(
|
28
|
-
|
29
|
-
|
30
|
-
type_map.register_type(type, TYPE.new(type)) unless type_map.key?(type)
|
27
|
+
def enable_pg_trunk_type(oid:, name:)
|
28
|
+
CustomTypes.known << name
|
29
|
+
type_map.register_type(oid.to_i, TYPE.new(name.to_s))
|
31
30
|
end
|
32
31
|
|
33
32
|
def valid_type?(type)
|
@@ -15,24 +15,30 @@
|
|
15
15
|
# #
|
16
16
|
# # The name of the new constraint can be set explicitly
|
17
17
|
# #
|
18
|
-
# #
|
19
|
-
# #
|
20
|
-
# #
|
21
|
-
# #
|
18
|
+
# # ```ruby
|
19
|
+
# # add_check_constraint :users, "length(phone) > 10",
|
20
|
+
# # name: "phone_is_long_enough",
|
21
|
+
# # inherit: false,
|
22
|
+
# # comment: "Phone is 10+ chars long"
|
23
|
+
# # ```
|
22
24
|
# #
|
23
25
|
# # The name can also be skipped (it will be generated by default):
|
24
26
|
# #
|
25
|
-
# #
|
27
|
+
# # ```ruby
|
28
|
+
# # add_check_constraint :users, "length(phone) > 1"
|
29
|
+
# # ```
|
26
30
|
# #
|
27
31
|
# # The block syntax can be used for any argument as usual:
|
28
32
|
# #
|
29
|
-
# #
|
30
|
-
# #
|
31
|
-
# #
|
32
|
-
# #
|
33
|
-
# #
|
34
|
-
# #
|
35
|
-
# #
|
33
|
+
# # ```ruby
|
34
|
+
# # add_check_constraint do |c|
|
35
|
+
# # c.table "users"
|
36
|
+
# # c.expression "length(phone) > 10"
|
37
|
+
# # c.name "phone_is_long_enough"
|
38
|
+
# # c.inherit false
|
39
|
+
# # c.comment "Phone is 10+ chars long"
|
40
|
+
# # end
|
41
|
+
# # ```
|
36
42
|
# #
|
37
43
|
# # The operation is always reversible.
|
38
44
|
# def add_check_constraint(table, expression = nil, **options, &block); end
|
@@ -18,27 +18,35 @@
|
|
18
18
|
# #
|
19
19
|
# # The constraint can be identified by the table and explicit name
|
20
20
|
# #
|
21
|
-
# #
|
21
|
+
# # ```ruby
|
22
|
+
# # drop_check_constraint :users, name: "phone_is_long_enough"
|
23
|
+
# # ```
|
22
24
|
# #
|
23
25
|
# # Alternatively the name can be got from the expression.
|
24
26
|
# # Be careful! the expression must have exactly the same form
|
25
27
|
# # as stored in the database:
|
26
28
|
# #
|
27
|
-
# #
|
29
|
+
# # ```ruby
|
30
|
+
# # drop_check_constraint :users, "length((phone::text) > 10)"
|
31
|
+
# # ```
|
28
32
|
# #
|
29
33
|
# # To made operation reversible the expression must be provided:
|
30
34
|
# #
|
31
|
-
# #
|
32
|
-
# #
|
33
|
-
# #
|
34
|
-
# #
|
35
|
-
# #
|
35
|
+
# # ```ruby
|
36
|
+
# # drop_check_constraint "users" do |c|
|
37
|
+
# # c.expression "length((phone::text) > 10)"
|
38
|
+
# # c.inherit false
|
39
|
+
# # c.comment "The phone is 10+ chars long"
|
40
|
+
# # end
|
41
|
+
# # ```
|
36
42
|
# #
|
37
43
|
# # The operation can be called with `if_exists` option.
|
38
44
|
# #
|
39
|
-
# #
|
40
|
-
# #
|
41
|
-
# #
|
45
|
+
# # ```ruby
|
46
|
+
# # drop_check_constraint :users,
|
47
|
+
# # name: "phone_is_long_enough",
|
48
|
+
# # if_exists: true
|
49
|
+
# # ```
|
42
50
|
# #
|
43
51
|
# # In this case the operation is always irreversible due to
|
44
52
|
# # uncertainty of the previous state of the database.
|
@@ -14,21 +14,27 @@
|
|
14
14
|
# #
|
15
15
|
# # A constraint can be identified by the table and explicit name
|
16
16
|
# #
|
17
|
-
# #
|
18
|
-
# #
|
19
|
-
# #
|
17
|
+
# # ```ruby
|
18
|
+
# # rename_check_constraint :users,
|
19
|
+
# # name: "phone_is_long_enough",
|
20
|
+
# # to: "phones.long_enough"
|
21
|
+
# # ```
|
20
22
|
# #
|
21
23
|
# # Alternatively the name can be got from the expression.
|
22
24
|
# # Be careful! the expression must have exactly the same form
|
23
25
|
# # as stored in the database:
|
24
26
|
# #
|
25
|
-
# #
|
26
|
-
# #
|
27
|
+
# # ```ruby
|
28
|
+
# # rename_check_constraint :users, "length((phone::text) > 10)",
|
29
|
+
# # to: "long_enough"
|
30
|
+
# # ```
|
27
31
|
# #
|
28
32
|
# # The name can be reset to auto-generated when
|
29
33
|
# # the `:to` option is missed or blank:
|
30
34
|
# #
|
31
|
-
# #
|
35
|
+
# # ```ruby
|
36
|
+
# # rename_check_constraint :users, "phone_is_long_enough"
|
37
|
+
# # ```
|
32
38
|
# #
|
33
39
|
# # The operation is always reversible.
|
34
40
|
# def rename_check_constraint(table, expression = nil, **options, &block); end
|
@@ -13,13 +13,17 @@
|
|
13
13
|
# #
|
14
14
|
# # The invalid constraint can be identified by table and explicit name:
|
15
15
|
# #
|
16
|
-
# #
|
16
|
+
# # ```ruby
|
17
|
+
# # validate_check_constraint :users, name: "phone_is_long_enough"
|
18
|
+
# # ```
|
17
19
|
# #
|
18
20
|
# # Alternatively it can be specified by expression. In this case
|
19
21
|
# # you must ensure the expression has the same form as it is stored
|
20
22
|
# # in the database (after parsing the source).
|
21
23
|
# #
|
22
|
-
# #
|
24
|
+
# # ```ruby
|
25
|
+
# # validate_check_constraint :users, "length((phone::text) > 10)"
|
26
|
+
# # ```
|
23
27
|
# #
|
24
28
|
# # Notice that it is invertible but the inverted operation does nothing.
|
25
29
|
# def validate_check_constraint(table, expression = nil, **options, &block); end
|
@@ -16,30 +16,36 @@
|
|
16
16
|
# #
|
17
17
|
# # Providing a type "paint.colored_point":
|
18
18
|
# #
|
19
|
-
# #
|
20
|
-
# #
|
21
|
-
# #
|
22
|
-
# #
|
23
|
-
# #
|
19
|
+
# # ```ruby
|
20
|
+
# # create_composite_type "paint.colored_point" do |t|
|
21
|
+
# # t.column "color", "text", collation: "en_US"
|
22
|
+
# # t.column "x", "integer"
|
23
|
+
# # t.column "z", "integer"
|
24
|
+
# # end
|
25
|
+
# # ```
|
24
26
|
# #
|
25
27
|
# # After the following change:
|
26
28
|
# #
|
27
|
-
# #
|
28
|
-
# #
|
29
|
-
# #
|
30
|
-
# #
|
31
|
-
# #
|
32
|
-
# #
|
33
|
-
# #
|
34
|
-
# #
|
29
|
+
# # ```ruby
|
30
|
+
# # change_composite_type "paint.colored_point" do |t|
|
31
|
+
# # t.change_column "color", "text", collation: "ru_RU", from_collation: "en_US"
|
32
|
+
# # t.change_column "x", "bigint", from_type: "integer"
|
33
|
+
# # t.drop_column "z", "integer"
|
34
|
+
# # t.add_column "Y", "bigint"
|
35
|
+
# # t.rename_column "x", to: "X"
|
36
|
+
# # t.comment "2D point with a color", from: "2D point"
|
37
|
+
# # end
|
38
|
+
# # ```
|
35
39
|
# #
|
36
40
|
# # The definition became:
|
37
41
|
# #
|
38
|
-
# #
|
39
|
-
# #
|
40
|
-
# #
|
41
|
-
# #
|
42
|
-
# #
|
42
|
+
# # ```ruby
|
43
|
+
# # create_composite_type "paint.colored_point" do |t|
|
44
|
+
# # t.column "color", "text", collation: "ru_RU"
|
45
|
+
# # t.column "X", "bigint"
|
46
|
+
# # t.column "Y", "integer"
|
47
|
+
# # end
|
48
|
+
# # ```
|
43
49
|
# #
|
44
50
|
# # Notice, that all renames will be done AFTER other changes,
|
45
51
|
# # so in `change_column` you should use the old names.
|
@@ -10,15 +10,16 @@
|
|
10
10
|
# # @yieldparam Object receiver of methods specifying the type
|
11
11
|
# # @return [void]
|
12
12
|
# #
|
13
|
-
# #
|
14
|
-
# #
|
15
|
-
# #
|
16
|
-
# #
|
17
|
-
# #
|
18
|
-
# #
|
19
|
-
# #
|
20
|
-
# #
|
21
|
-
# #
|
13
|
+
# # ```ruby
|
14
|
+
# # create_composite_type "paint.colored_point" do |d|
|
15
|
+
# # d.column "x", "integer"
|
16
|
+
# # d.column "y", "integer"
|
17
|
+
# # d.column "color", "text", collation: "en_US"
|
18
|
+
# # d.comment <<~COMMENT
|
19
|
+
# # 2D point with color
|
20
|
+
# # COMMENT
|
21
|
+
# # end
|
22
|
+
# # ```
|
22
23
|
# #
|
23
24
|
# # It is always reversible.
|
24
25
|
# def create_composite_type(name, **options, &block); end
|
@@ -12,39 +12,41 @@
|
|
12
12
|
# # @yieldparam Object receiver of methods specifying the type
|
13
13
|
# # @return [void]
|
14
14
|
# #
|
15
|
-
# # The operation drops a composite_type type identified by its
|
16
|
-
# # qualified name (it can include a schema).
|
15
|
+
# # The operation drops a composite_type type identified by its qualified name (it can include a schema).
|
17
16
|
# #
|
18
|
-
# # For inversion use the same options as in the
|
19
|
-
# # `create_composite_type` operation.
|
17
|
+
# # For inversion use the same options as in the `create_composite_type` operation.
|
20
18
|
# #
|
21
|
-
# #
|
22
|
-
# #
|
23
|
-
# #
|
24
|
-
# #
|
25
|
-
# #
|
26
|
-
# #
|
27
|
-
# #
|
28
|
-
# #
|
19
|
+
# # ```ruby
|
20
|
+
# # drop_composite_type "paint.colored_point" do |d|
|
21
|
+
# # d.column "x", "integer"
|
22
|
+
# # d.column "y", "integer"
|
23
|
+
# # d.column "color", "text", collation: "en_US"
|
24
|
+
# # d.comment <<~COMMENT
|
25
|
+
# # 2D point with color
|
26
|
+
# # COMMENT
|
27
|
+
# # end
|
28
|
+
# # ```
|
29
29
|
# #
|
30
30
|
# # Notice, that the composite type creation can use no attributes.
|
31
|
-
# # That's why dropping it is always reversible; though the reversion
|
32
|
-
# # would provide a type without columns:
|
31
|
+
# # That's why dropping it is always reversible; though the reversion provides a type without columns:
|
33
32
|
# #
|
34
|
-
# #
|
33
|
+
# # ```ruby
|
34
|
+
# # drop_composite_type "paint.colored_point"
|
35
|
+
# # ```
|
35
36
|
# #
|
36
|
-
# # With the `force: :cascade` option the operation
|
37
|
-
# # all objects using the type.
|
37
|
+
# # With the `force: :cascade` option the operation removes all objects using the type.
|
38
38
|
# #
|
39
|
-
# #
|
39
|
+
# # ```ruby
|
40
|
+
# # drop_composite_type "paint.colored_point", force: :cascade
|
41
|
+
# # ```
|
40
42
|
# #
|
41
|
-
# # With the `if_exists: true` option the operation won't fail
|
42
|
-
# # even when the view was absent in the database.
|
43
|
+
# # With the `if_exists: true` option the operation won't fail even when the view was absent.
|
43
44
|
# #
|
44
|
-
# #
|
45
|
+
# # ```ruby
|
46
|
+
# # drop_composite_type "paint.colored_point", if_exists: true
|
47
|
+
# # ```
|
45
48
|
# #
|
46
|
-
# # Both options make a migration irreversible due to uncertainty
|
47
|
-
# # of the previous state of the database.
|
49
|
+
# # Both options make a migration irreversible due to uncertainty of the previous state of the database.
|
48
50
|
# def drop_composite_type(name, **options, &block); end
|
49
51
|
# end
|
50
52
|
module PGTrunk::Operations::CompositeTypes
|
@@ -8,9 +8,9 @@
|
|
8
8
|
# # @option [#to_s] :to (nil) The new qualified name for the type
|
9
9
|
# # @return [void]
|
10
10
|
# #
|
11
|
-
# #
|
12
|
-
# #
|
13
|
-
# #
|
11
|
+
# # ```ruby
|
12
|
+
# # rename_composite_type "point", to: "paint.colored_point"
|
13
|
+
# # ```
|
14
14
|
# #
|
15
15
|
# # The operation is always reversible.
|
16
16
|
# def rename_composite_type(name, to:); end
|
@@ -13,22 +13,24 @@
|
|
13
13
|
# # modify the default_sql value, or the description of the domain type.
|
14
14
|
# # Neither the underlying type nor the collation can be changed.
|
15
15
|
# #
|
16
|
-
# #
|
17
|
-
# #
|
18
|
-
# #
|
19
|
-
# #
|
20
|
-
# #
|
21
|
-
# #
|
22
|
-
# #
|
23
|
-
# #
|
24
|
-
# #
|
25
|
-
# #
|
26
|
-
# #
|
27
|
-
# #
|
28
|
-
# #
|
29
|
-
# #
|
30
|
-
# #
|
31
|
-
# #
|
16
|
+
# # ```ruby
|
17
|
+
# # change_domain "dict.us_postal_code" do |d|
|
18
|
+
# # d.null true # from: false
|
19
|
+
# # # check is added for inversion
|
20
|
+
# # d.drop_constraint "postal_code_length", check: <<~SQL
|
21
|
+
# # length(VALUE) > 3 AND length(VALUE) < 6
|
22
|
+
# # SQL
|
23
|
+
# # d.add_constraint <<~SQL, name: "postal_code_valid"
|
24
|
+
# # VALUE ~ '^\d{5}$' OR VALUE ~ '^\d{5}-\d{4}$'
|
25
|
+
# # SQL
|
26
|
+
# # d.default_sql "'00000'::text", from: "'0000'::text"
|
27
|
+
# # d.comment <<~COMMENT, from: <<~COMMENT
|
28
|
+
# # Supported currencies
|
29
|
+
# # COMMENT
|
30
|
+
# # Currencies
|
31
|
+
# # COMMENT
|
32
|
+
# # end
|
33
|
+
# # ```
|
32
34
|
# #
|
33
35
|
# # Use blank string (not a `nil` value) to reset either a default_sql,
|
34
36
|
# # or the comment. `nil`-s here will be ignored.
|
@@ -41,14 +43,15 @@
|
|
41
43
|
# # has `if_exists: true` or `force: :cascade` option -- due to
|
42
44
|
# # uncertainty of the previous state of the database:
|
43
45
|
# #
|
44
|
-
# #
|
45
|
-
# #
|
46
|
-
# #
|
47
|
-
# #
|
48
|
-
# #
|
49
|
-
# #
|
50
|
-
# #
|
51
|
-
# #
|
46
|
+
# # ```ruby
|
47
|
+
# # change_domain "dict.us_postal_code", force: :cascade do |d|
|
48
|
+
# # d.drop_constraint "postal_code_valid" # missed `:check` option
|
49
|
+
# # d.drop_constraint "postal_code_length"
|
50
|
+
# # d.drop_constraint "postal_code_format", if_exists: true
|
51
|
+
# # d.default_sql "'0000'::text" # missed `:from` option
|
52
|
+
# # d.comment "New comment" # missed `:from` option
|
53
|
+
# # end
|
54
|
+
# # ```
|
52
55
|
# def change_domain(name, &block); end
|
53
56
|
# end
|
54
57
|
module PGTrunk::Operations::Domains
|
@@ -14,17 +14,17 @@
|
|
14
14
|
# # @yieldparam Object receiver of methods specifying the type
|
15
15
|
# # @return [void]
|
16
16
|
# #
|
17
|
-
# #
|
18
|
-
# #
|
19
|
-
# #
|
20
|
-
# #
|
21
|
-
# #
|
22
|
-
# #
|
23
|
-
# # d
|
24
|
-
# #
|
25
|
-
# #
|
26
|
-
# #
|
27
|
-
# #
|
17
|
+
# # ```ruby
|
18
|
+
# # create_domain "dict.us_postal_code", as: "text" do |d|
|
19
|
+
# # d.collation "en_US"
|
20
|
+
# # d.default_sql "'0000'::text"
|
21
|
+
# # d.null false
|
22
|
+
# # d.constraint <<~SQL, name: "code_valid"
|
23
|
+
# # VALUE ~ '^\d{5}$' OR VALUE ~ '^\d{5}-\d{4}$'
|
24
|
+
# # SQL
|
25
|
+
# # d.comment "US postal code"
|
26
|
+
# # end
|
27
|
+
# # ```
|
28
28
|
# #
|
29
29
|
# # It is always reversible.
|
30
30
|
# def create_domain(name, **options, &block); end
|
@@ -15,31 +15,37 @@
|
|
15
15
|
# # @yieldparam Object receiver of methods specifying the type
|
16
16
|
# # @return [void]
|
17
17
|
# #
|
18
|
-
# #
|
19
|
-
# #
|
20
|
-
# #
|
18
|
+
# # ```ruby
|
19
|
+
# # drop_domain "dict.us_postal_code"
|
20
|
+
# # ```
|
21
21
|
# #
|
22
22
|
# # To make the operation invertible, use the same options
|
23
23
|
# # as in the `create_domain` operation.
|
24
24
|
# #
|
25
|
-
# #
|
26
|
-
# #
|
27
|
-
# #
|
28
|
-
# #
|
29
|
-
# #
|
30
|
-
# #
|
31
|
-
# #
|
32
|
-
# #
|
25
|
+
# # ```ruby
|
26
|
+
# # drop_domain "dict.us_postal_code", as: "string" do |d|
|
27
|
+
# # d.constraint <<~SQL, name: "code_valid"
|
28
|
+
# # VALUE ~ '^\d{5}$' OR VALUE ~ '^\d{5}-\d{4}$'
|
29
|
+
# # SQL
|
30
|
+
# # d.comment <<~COMMENT
|
31
|
+
# # US postal code
|
32
|
+
# # COMMENT
|
33
|
+
# # end
|
34
|
+
# # ```
|
33
35
|
# #
|
34
36
|
# # With the `force: :cascade` option the operation would remove
|
35
37
|
# # all the objects that use the type.
|
36
38
|
# #
|
37
|
-
# #
|
39
|
+
# # ```ruby
|
40
|
+
# # drop_domain "dict.us_postal_code", force: :cascade
|
41
|
+
# # ```
|
38
42
|
# #
|
39
43
|
# # With the `if_exists: true` option the operation won't fail
|
40
44
|
# # even when the view was absent in the database.
|
41
45
|
# #
|
42
|
-
# #
|
46
|
+
# # ```ruby
|
47
|
+
# # drop_domain "dict.us_postal_code", if_exists: true
|
48
|
+
# # ```
|
43
49
|
# #
|
44
50
|
# # Both options make a migration irreversible due to uncertainty
|
45
51
|
# # of the previous state of the database.
|
@@ -10,7 +10,9 @@
|
|
10
10
|
# #
|
11
11
|
# # A domain type can be both renamed and moved to another schema.
|
12
12
|
# #
|
13
|
-
# #
|
13
|
+
# # ```ruby
|
14
|
+
# # rename_domain "us_code", to: "dict.us_postal_code"
|
15
|
+
# # ```
|
14
16
|
# #
|
15
17
|
# # The operation is always reversible.
|
16
18
|
# def rename_domain(name, to:); end
|
@@ -12,17 +12,19 @@
|
|
12
12
|
# # The operation can be used to rename or add values to the
|
13
13
|
# # enumerated type. The commend can be changed as well.
|
14
14
|
# #
|
15
|
-
# #
|
16
|
-
# #
|
17
|
-
# #
|
18
|
-
# #
|
19
|
-
# #
|
20
|
-
# #
|
21
|
-
# #
|
22
|
-
# #
|
23
|
-
# #
|
24
|
-
# #
|
25
|
-
# #
|
15
|
+
# # ```ruby
|
16
|
+
# # change_enum "currencies" do |e|
|
17
|
+
# # e.add_value "EUR", after: "BTC"
|
18
|
+
# # e.add_value "GBP", before: "usd"
|
19
|
+
# # e.add_value "JPY" # to the end of the list
|
20
|
+
# # e.rename_value "usd", to: "USD"
|
21
|
+
# # e.comment <<~COMMENT, from: <<~COMMENT
|
22
|
+
# # Supported currencies
|
23
|
+
# # COMMENT
|
24
|
+
# # Currencies
|
25
|
+
# # COMMENT
|
26
|
+
# # end
|
27
|
+
# # ```
|
26
28
|
# #
|
27
29
|
# # Please, keep in mind that all values will be added before
|
28
30
|
# # the first rename. That's why you should use old values
|
@@ -11,15 +11,15 @@
|
|
11
11
|
# # @yieldparam Object receiver of methods specifying the type
|
12
12
|
# # @return [void]
|
13
13
|
# #
|
14
|
-
# #
|
15
|
-
# #
|
16
|
-
# #
|
17
|
-
# #
|
18
|
-
# #
|
19
|
-
# #
|
20
|
-
# #
|
21
|
-
# #
|
22
|
-
# #
|
14
|
+
# # ```ruby
|
15
|
+
# # create_enum "finances.currency" do |e|
|
16
|
+
# # e.values "BTC", "EUR", "GBP", "USD"
|
17
|
+
# # e.value "JPY" # the alternative way to add a value to the tail
|
18
|
+
# # e.comment <<~COMMENT
|
19
|
+
# # The list of values for supported currencies.
|
20
|
+
# # COMMENT
|
21
|
+
# # end
|
22
|
+
# # ```
|
23
23
|
# #
|
24
24
|
# # It is always reversible.
|
25
25
|
# def create_enum(name, **options, &block); end
|