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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7e02c0f3a19350a502afda3e8697421912161b9bd800eb6302738cc623eb3eb
|
4
|
+
data.tar.gz: c0108a41cabe1fd1eebc0695e222ceafeb27c195b9c8fe2766e1f4ced4142c63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7af9d03c65275a700408841a032cf2f074349943a8d131e54d5dff4f467b9e4bb3fadce657d70469ec2cb1471b41578bef68fc91a92771429d3da84b648161f8
|
7
|
+
data.tar.gz: 9a47edbac23bffb1db4c74f0108f42c06c5e9d7aa28b5d213fed05f908a8e738114db1ad4c38557fde7db7e2d514cabf6646d65a8193c7e5bf664b4d20bc38ff
|
data/.github/workflows/ci.yml
CHANGED
@@ -58,25 +58,14 @@ jobs:
|
|
58
58
|
- name: Checkout
|
59
59
|
uses: actions/checkout@v2
|
60
60
|
|
61
|
-
- name: Install Ruby ${{ matrix.ruby }}
|
62
|
-
uses: ruby/setup-ruby@v1.61.1
|
63
|
-
with:
|
64
|
-
ruby-version: ${{ matrix.ruby }}
|
65
|
-
|
66
61
|
- name: Install dependent libraries
|
67
62
|
run: sudo apt-get install libpq-dev
|
68
63
|
|
69
|
-
- name:
|
70
|
-
|
71
|
-
|
72
|
-
- name: Cache dependencies
|
73
|
-
uses: actions/cache@v1
|
64
|
+
- name: Install Ruby ${{ matrix.ruby }}
|
65
|
+
uses: ruby/setup-ruby@v1.61.1
|
74
66
|
with:
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
- name: Set up PGTrunk
|
79
|
-
run: bin/setup
|
67
|
+
ruby-version: ${{ matrix.ruby }}
|
68
|
+
bundler-cache: true # 'bundle install' and cache
|
80
69
|
|
81
70
|
- name: Check code style
|
82
71
|
run: bundle exec rubocop
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,26 @@ 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.2.0] (2022-01-26)
|
8
|
+
|
9
|
+
* Add support for sequences (nepalez)
|
10
|
+
* Fix inheritance of attribute aliases (nepalez)
|
11
|
+
* Fix documentation for rules (nepalez)
|
12
|
+
|
13
|
+
## [0.1.3] (2022-01-20)
|
14
|
+
|
15
|
+
* Add support for rules (nepalez)
|
16
|
+
* Fix CI/CD flow (olleolleolle)
|
17
|
+
* Fix documentation (nepalez)
|
18
|
+
|
19
|
+
## [0.1.2] (2022-01-17)
|
20
|
+
|
21
|
+
* Fix registry of custom types (nepalez)
|
22
|
+
|
23
|
+
## [0.1.1] (2022-01-16)
|
24
|
+
|
25
|
+
* Fix inline documentation for methods added to ActiveRecord::Migration (nepalez)
|
26
|
+
|
7
27
|
## [0.1.0] (2022-01-14)
|
8
28
|
|
9
29
|
This is a first public release (nepalez)
|
@@ -24,6 +44,7 @@ Supported features:
|
|
24
44
|
- composite types
|
25
45
|
- domains types
|
26
46
|
|
47
|
+
[0.1.1]: https://github.com/nepalez/pg_trunk/releases/tag/v0.1.1
|
27
48
|
[0.1.0]: https://github.com/nepalez/pg_trunk/releases/tag/v0.1.0
|
28
49
|
|
29
50
|
[Keep a Changelog]: http://keepachangelog.com/
|
data/README.md
CHANGED
@@ -72,6 +72,8 @@ As of today we support creation, modification and dropping the following objects
|
|
72
72
|
- enumerable types
|
73
73
|
- composite types
|
74
74
|
- domains types
|
75
|
+
- rules
|
76
|
+
- sequences
|
75
77
|
|
76
78
|
For `tables` and `indexes` we reuse the ActiveRecord's native methods.
|
77
79
|
For `check constraints` and `foreign keys` we support both the native definitions inside the table
|
@@ -88,7 +90,7 @@ The gem is targeted to support PostgreSQL-specific features, that's why we won't
|
|
88
90
|
## Documentation
|
89
91
|
|
90
92
|
The gem provides a lot of additional methods to create, rename, change a drop various objects.
|
91
|
-
You can find the necessary details
|
93
|
+
You can find the necessary details [here](https://rubydoc.info/gems/pg_trunk/ActiveRecord/Migration).
|
92
94
|
|
93
95
|
## Installation
|
94
96
|
|
@@ -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)
|
@@ -1,39 +1,48 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @option [
|
10
|
-
# @option [
|
11
|
-
# @
|
12
|
-
# @
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# The
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Add a check constraint to the table
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] expression (nil) The SQL expression
|
9
|
+
# # @option options [#to_s] :name (nil) The optional name of the constraint
|
10
|
+
# # @option options [Boolean] :inherit (true) If the constraint should be inherited by subtables
|
11
|
+
# # @option options [#to_s] :comment (nil) The comment describing the constraint
|
12
|
+
# # @yield [c] the block with the constraint's definition
|
13
|
+
# # @yieldparam Object receiver of methods specifying the constraint
|
14
|
+
# # @return [void]
|
15
|
+
# #
|
16
|
+
# # The name of the new constraint can be set explicitly
|
17
|
+
# #
|
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
|
+
# # ```
|
24
|
+
# #
|
25
|
+
# # The name can also be skipped (it will be generated by default):
|
26
|
+
# #
|
27
|
+
# # ```ruby
|
28
|
+
# # add_check_constraint :users, "length(phone) > 1"
|
29
|
+
# # ```
|
30
|
+
# #
|
31
|
+
# # The block syntax can be used for any argument as usual:
|
32
|
+
# #
|
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
|
+
# # ```
|
42
|
+
# #
|
43
|
+
# # The operation is always reversible.
|
44
|
+
# def add_check_constraint(table, expression = nil, **options, &block); end
|
33
45
|
# end
|
34
|
-
#
|
35
|
-
# The operation is always reversible.
|
36
|
-
|
37
46
|
module PGTrunk::Operations::CheckConstraints
|
38
47
|
# @private
|
39
48
|
class AddCheckConstraint < Base
|
@@ -1,46 +1,57 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @option [
|
10
|
-
# @option [
|
11
|
-
# @option [
|
12
|
-
# @
|
13
|
-
# @
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Remove a check constraint from the table
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] expression (nil) The SQL expression
|
9
|
+
# # @option options [Boolean] :if_exists (false) Suppress the error when the constraint is absent
|
10
|
+
# # @option options [#to_s] :name (nil) The optional name of the constraint
|
11
|
+
# # @option options [Boolean] :inherit (true) If the constraint should be inherited by subtables
|
12
|
+
# # @option options [#to_s] :comment (nil) The comment describing the constraint
|
13
|
+
# # @yield [c] the block with the constraint's definition
|
14
|
+
# # @yieldparam Object receiver of methods specifying the constraint
|
15
|
+
# # @return [void]
|
16
|
+
# #
|
17
|
+
# # Definition for the `drop_check_constraint` operation
|
18
|
+
# #
|
19
|
+
# # The constraint can be identified by the table and explicit name
|
20
|
+
# #
|
21
|
+
# # ```ruby
|
22
|
+
# # drop_check_constraint :users, name: "phone_is_long_enough"
|
23
|
+
# # ```
|
24
|
+
# #
|
25
|
+
# # Alternatively the name can be got from the expression.
|
26
|
+
# # Be careful! the expression must have exactly the same form
|
27
|
+
# # as stored in the database:
|
28
|
+
# #
|
29
|
+
# # ```ruby
|
30
|
+
# # drop_check_constraint :users, "length((phone::text) > 10)"
|
31
|
+
# # ```
|
32
|
+
# #
|
33
|
+
# # To made operation reversible the expression must be provided:
|
34
|
+
# #
|
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
|
+
# # ```
|
42
|
+
# #
|
43
|
+
# # The operation can be called with `if_exists` option.
|
44
|
+
# #
|
45
|
+
# # ```ruby
|
46
|
+
# # drop_check_constraint :users,
|
47
|
+
# # name: "phone_is_long_enough",
|
48
|
+
# # if_exists: true
|
49
|
+
# # ```
|
50
|
+
# #
|
51
|
+
# # In this case the operation is always irreversible due to
|
52
|
+
# # uncertainty of the previous state of the database.
|
53
|
+
# def drop_check_constraint(table, expression = nil, **options, &block); end
|
33
54
|
# end
|
34
|
-
#
|
35
|
-
# The operation can be called with `if_exists` option.
|
36
|
-
#
|
37
|
-
# drop_check_constraint :users,
|
38
|
-
# name: "phone_is_long_enough",
|
39
|
-
# if_exists: true
|
40
|
-
#
|
41
|
-
# In this case the operation is always irreversible due to
|
42
|
-
# uncertainty of the previous state of the database.
|
43
|
-
|
44
55
|
module PGTrunk::Operations::CheckConstraints
|
45
56
|
# @private
|
46
57
|
class DropCheckConstraint < Base
|
@@ -1,35 +1,44 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @option [#to_s] :
|
10
|
-
# @
|
11
|
-
# @
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Rename a check constraint
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] expression (nil) The SQL expression
|
9
|
+
# # @option options [#to_s] :name (nil) The current name of the constraint
|
10
|
+
# # @option options [#to_s] :to (nil) The new name for the constraint
|
11
|
+
# # @yield [c] the block with the constraint's definition
|
12
|
+
# # @yieldparam Object receiver of methods specifying the constraint
|
13
|
+
# # @return [void]
|
14
|
+
# #
|
15
|
+
# # A constraint can be identified by the table and explicit name
|
16
|
+
# #
|
17
|
+
# # ```ruby
|
18
|
+
# # rename_check_constraint :users,
|
19
|
+
# # name: "phone_is_long_enough",
|
20
|
+
# # to: "phones.long_enough"
|
21
|
+
# # ```
|
22
|
+
# #
|
23
|
+
# # Alternatively the name can be got from the expression.
|
24
|
+
# # Be careful! the expression must have exactly the same form
|
25
|
+
# # as stored in the database:
|
26
|
+
# #
|
27
|
+
# # ```ruby
|
28
|
+
# # rename_check_constraint :users, "length((phone::text) > 10)",
|
29
|
+
# # to: "long_enough"
|
30
|
+
# # ```
|
31
|
+
# #
|
32
|
+
# # The name can be reset to auto-generated when
|
33
|
+
# # the `:to` option is missed or blank:
|
34
|
+
# #
|
35
|
+
# # ```ruby
|
36
|
+
# # rename_check_constraint :users, "phone_is_long_enough"
|
37
|
+
# # ```
|
38
|
+
# #
|
39
|
+
# # The operation is always reversible.
|
40
|
+
# def rename_check_constraint(table, expression = nil, **options, &block); end
|
41
|
+
# end
|
33
42
|
module PGTrunk::Operations::CheckConstraints
|
34
43
|
# @private
|
35
44
|
class RenameCheckConstraint < Base
|
@@ -1,26 +1,33 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @
|
10
|
-
# @
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Validate an invalid check constraint
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] expression (nil) The SQL expression
|
9
|
+
# # @option options [#to_s] :name (nil) The optional name of the constraint
|
10
|
+
# # @yield [c] the block with the constraint's definition
|
11
|
+
# # @yieldparam Object receiver of methods specifying the constraint
|
12
|
+
# # @return [void]
|
13
|
+
# #
|
14
|
+
# # The invalid constraint can be identified by table and explicit name:
|
15
|
+
# #
|
16
|
+
# # ```ruby
|
17
|
+
# # validate_check_constraint :users, name: "phone_is_long_enough"
|
18
|
+
# # ```
|
19
|
+
# #
|
20
|
+
# # Alternatively it can be specified by expression. In this case
|
21
|
+
# # you must ensure the expression has the same form as it is stored
|
22
|
+
# # in the database (after parsing the source).
|
23
|
+
# #
|
24
|
+
# # ```ruby
|
25
|
+
# # validate_check_constraint :users, "length((phone::text) > 10)"
|
26
|
+
# # ```
|
27
|
+
# #
|
28
|
+
# # Notice that it is invertible but the inverted operation does nothing.
|
29
|
+
# def validate_check_constraint(table, expression = nil, **options, &block); end
|
30
|
+
# end
|
24
31
|
module PGTrunk::Operations::CheckConstraints
|
25
32
|
# @private
|
26
33
|
class ValidateCheckConstraint < Base
|
@@ -1,56 +1,65 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @option [
|
9
|
-
# @
|
10
|
-
# @
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Modify a composite type
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] name (nil) The qualified name of the type
|
8
|
+
# # @option options [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
|
9
|
+
# # @option options [#to_s] :comment (nil) The comment describing the constraint
|
10
|
+
# # @yield [t] the block with the type's definition
|
11
|
+
# # @yieldparam Object receiver of methods specifying the type
|
12
|
+
# # @return [void]
|
13
|
+
# #
|
14
|
+
# # The operation can be used to add, drop, rename or change columns.
|
15
|
+
# # The comment can be changed as well.
|
16
|
+
# #
|
17
|
+
# # Providing a type "paint.colored_point":
|
18
|
+
# #
|
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
|
+
# # ```
|
26
|
+
# #
|
27
|
+
# # After the following change:
|
28
|
+
# #
|
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
|
+
# # ```
|
39
|
+
# #
|
40
|
+
# # The definition became:
|
41
|
+
# #
|
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
|
+
# # ```
|
49
|
+
# #
|
50
|
+
# # Notice, that all renames will be done AFTER other changes,
|
51
|
+
# # so in `change_column` you should use the old names.
|
52
|
+
# #
|
53
|
+
# # In several cases the operation is not invertible:
|
54
|
+
# #
|
55
|
+
# # - when a column was dropped
|
56
|
+
# # - when `force: :cascade` option is used (to update
|
57
|
+
# # objects that use the type)
|
58
|
+
# # - when `if_exists: true` is added to the `drop_column` clause
|
59
|
+
# # - when a previous state of the column type, collation or comment
|
60
|
+
# # is not specified.
|
61
|
+
# def change_composite_type(name, **options, &block); end
|
21
62
|
# end
|
22
|
-
#
|
23
|
-
# After the following change:
|
24
|
-
#
|
25
|
-
# change_composite_type "paint.colored_point" do |t|
|
26
|
-
# t.change_column "color", "text", collation: "ru_RU", from_collation: "en_US"
|
27
|
-
# t.change_column "x", "bigint", from_type: "integer"
|
28
|
-
# t.drop_column "z", "integer"
|
29
|
-
# t.add_column "Y", "bigint"
|
30
|
-
# t.rename_column "x", to: "X"
|
31
|
-
# t.comment "2D point with a color", from: "2D point"
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# The definition became:
|
35
|
-
#
|
36
|
-
# create_composite_type "paint.colored_point" do |t|
|
37
|
-
# t.column "color", "text", collation: "ru_RU"
|
38
|
-
# t.column "X", "bigint"
|
39
|
-
# t.column "Y", "integer"
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# Notice, that all renames will be done AFTER other changes,
|
43
|
-
# so in `change_column` you should use the old names.
|
44
|
-
#
|
45
|
-
# In several cases the operation is not invertible:
|
46
|
-
#
|
47
|
-
# - when a column was dropped
|
48
|
-
# - when `force: :cascade` option is used (to update
|
49
|
-
# objects that use the type)
|
50
|
-
# - when `if_exists: true` is added to the `drop_column` clause
|
51
|
-
# - when a previous state of the column type, collation or comment
|
52
|
-
# is not specified.
|
53
|
-
|
54
63
|
module PGTrunk::Operations::CompositeTypes
|
55
64
|
# @private
|
56
65
|
class ChangeCompositeType < Base
|
@@ -1,25 +1,29 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @
|
9
|
-
# @
|
10
|
-
#
|
11
|
-
# @
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# d.column "
|
16
|
-
# d.
|
17
|
-
#
|
18
|
-
# COMMENT
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Create a composite type
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] name (nil) The qualified name of the type
|
8
|
+
# # @option options [#to_s] :comment (nil) The comment describing the constraint
|
9
|
+
# # @yield [t] the block with the type's definition
|
10
|
+
# # @yieldparam Object receiver of methods specifying the type
|
11
|
+
# # @return [void]
|
12
|
+
# #
|
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
|
+
# # ```
|
23
|
+
# #
|
24
|
+
# # It is always reversible.
|
25
|
+
# def create_composite_type(name, **options, &block); end
|
19
26
|
# end
|
20
|
-
#
|
21
|
-
# It is always reversible.
|
22
|
-
|
23
27
|
module PGTrunk::Operations::CompositeTypes
|
24
28
|
# @private
|
25
29
|
class CreateCompositeType < Base
|