Skip to content

Commit 1eb92de

Browse files
committed
Fix inline docs for ActiveRecord::Migration methods
1 parent a955332 commit 1eb92de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1749
-1620
lines changed

lib/pg_trunk/operations/check_constraints/add_check_constraint.rb

+36-33
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
# frozen_string_literal: false
22

3-
# @!method ActiveRecord::Migration#add_check_constraint(table, expression = nil, **options, &block)
4-
# Add a check constraint to the table
5-
#
6-
# @param [#to_s] table (nil) The qualified name of the table
7-
# @param [#to_s] expression (nil) The SQL expression
8-
# @option [#to_s] :name (nil) The optional name of the constraint
9-
# @option [Boolean] :inherit (true) If the constraint should be inherited by subtables
10-
# @option [#to_s] :comment (nil) The comment describing the constraint
11-
# @yield [Proc] the block with the constraint's definition
12-
# @yieldparam The receiver of methods specifying the constraint
13-
#
14-
# The name of the new constraint can be set explicitly
15-
#
16-
# add_check_constraint :users, "length(phone) > 10",
17-
# name: "phone_is_long_enough",
18-
# inherit: false,
19-
# comment: "Phone is 10+ chars long"
20-
#
21-
# The name can also be skipped (it will be generated by default):
22-
#
23-
# add_check_constraint :users, "length(phone) > 1"
24-
#
25-
# The block syntax can be used for any argument as usual:
26-
#
27-
# add_check_constraint do |c|
28-
# c.table "users"
29-
# c.expression "length(phone) > 10"
30-
# c.name "phone_is_long_enough"
31-
# c.inherit false
32-
# c.comment "Phone is 10+ chars long"
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 [#to_s] :name (nil) The optional name of the constraint
10+
# # @option [Boolean] :inherit (true) If the constraint should be inherited by subtables
11+
# # @option [#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+
# # add_check_constraint :users, "length(phone) > 10",
19+
# # name: "phone_is_long_enough",
20+
# # inherit: false,
21+
# # comment: "Phone is 10+ chars long"
22+
# #
23+
# # The name can also be skipped (it will be generated by default):
24+
# #
25+
# # add_check_constraint :users, "length(phone) > 1"
26+
# #
27+
# # The block syntax can be used for any argument as usual:
28+
# #
29+
# # add_check_constraint do |c|
30+
# # c.table "users"
31+
# # c.expression "length(phone) > 10"
32+
# # c.name "phone_is_long_enough"
33+
# # c.inherit false
34+
# # c.comment "Phone is 10+ chars long"
35+
# # end
36+
# #
37+
# # The operation is always reversible.
38+
# def add_check_constraint(table, expression = nil, **options, &block); end
3339
# end
34-
#
35-
# The operation is always reversible.
36-
3740
module PGTrunk::Operations::CheckConstraints
3841
# @private
3942
class AddCheckConstraint < Base

lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb

+43-40
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
11
# frozen_string_literal: false
22

3-
# @!method ActiveRecord::Migration#drop_check_constraint(table, expression = nil, **options, &block)
4-
# Remove a check constraint from the table
5-
#
6-
# @param [#to_s] table (nil) The qualified name of the table
7-
# @param [#to_s] expression (nil) The SQL expression
8-
# @option [Boolean] :if_exists (false) Suppress the error when the constraint is absent
9-
# @option [#to_s] :name (nil) The optional name of the constraint
10-
# @option [Boolean] :inherit (true) If the constraint should be inherited by subtables
11-
# @option [#to_s] :comment (nil) The comment describing the constraint
12-
# @yield [Proc] the block with the constraint's definition
13-
# @yieldparam The receiver of methods specifying the constraint
14-
#
15-
# Definition for the `drop_check_constraint` operation
16-
#
17-
# The constraint can be identified by the table and explicit name
18-
#
19-
# drop_check_constraint :users, name: "phone_is_long_enough"
20-
#
21-
# Alternatively the name can be got from the expression.
22-
# Be careful! the expression must have exactly the same form
23-
# as stored in the database:
24-
#
25-
# drop_check_constraint :users, "length((phone::text) > 10)"
26-
#
27-
# To made operation reversible the expression must be provided:
28-
#
29-
# drop_check_constraint "users" do |c|
30-
# c.expression "length((phone::text) > 10)"
31-
# c.inherit false
32-
# c.comment "The phone is 10+ chars long"
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 [Boolean] :if_exists (false) Suppress the error when the constraint is absent
10+
# # @option [#to_s] :name (nil) The optional name of the constraint
11+
# # @option [Boolean] :inherit (true) If the constraint should be inherited by subtables
12+
# # @option [#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+
# # drop_check_constraint :users, name: "phone_is_long_enough"
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+
# # drop_check_constraint :users, "length((phone::text) > 10)"
28+
# #
29+
# # To made operation reversible the expression must be provided:
30+
# #
31+
# # drop_check_constraint "users" do |c|
32+
# # c.expression "length((phone::text) > 10)"
33+
# # c.inherit false
34+
# # c.comment "The phone is 10+ chars long"
35+
# # end
36+
# #
37+
# # The operation can be called with `if_exists` option.
38+
# #
39+
# # drop_check_constraint :users,
40+
# # name: "phone_is_long_enough",
41+
# # if_exists: true
42+
# #
43+
# # In this case the operation is always irreversible due to
44+
# # uncertainty of the previous state of the database.
45+
# def drop_check_constraint(table, expression = nil, **options, &block); end
3346
# 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-
4447
module PGTrunk::Operations::CheckConstraints
4548
# @private
4649
class DropCheckConstraint < Base

lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb

+33-30
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
# frozen_string_literal: false
22

3-
# @!method ActiveRecord::Migration#rename_check_constraint(table, expression = nil, **options, &block)
4-
# Rename a check constraint
5-
#
6-
# @param [#to_s] table (nil) The qualified name of the table
7-
# @param [#to_s] expression (nil) The SQL expression
8-
# @option [#to_s] :name (nil) The current name of the constraint
9-
# @option [#to_s] :to (nil) The new name for the constraint
10-
# @yield [Proc] the block with the constraint's definition
11-
# @yieldparam The receiver of methods specifying the constraint
12-
#
13-
# A constraint can be identified by the table and explicit name
14-
#
15-
# rename_check_constraint :users,
16-
# name: "phone_is_long_enough",
17-
# to: "phones.long_enough"
18-
#
19-
# Alternatively the name can be got from the expression.
20-
# Be careful! the expression must have exactly the same form
21-
# as stored in the database:
22-
#
23-
# rename_check_constraint :users, "length((phone::text) > 10)",
24-
# to: "long_enough"
25-
#
26-
# The name can be reset to auto-generated when
27-
# the `:to` option is missed or blank:
28-
#
29-
# rename_check_constraint :users, "phone_is_long_enough"
30-
#
31-
# The operation is always reversible.
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 [#to_s] :name (nil) The current name of the constraint
10+
# # @option [#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+
# # rename_check_constraint :users,
18+
# # name: "phone_is_long_enough",
19+
# # to: "phones.long_enough"
20+
# #
21+
# # Alternatively the name can be got from the expression.
22+
# # Be careful! the expression must have exactly the same form
23+
# # as stored in the database:
24+
# #
25+
# # rename_check_constraint :users, "length((phone::text) > 10)",
26+
# # to: "long_enough"
27+
# #
28+
# # The name can be reset to auto-generated when
29+
# # the `:to` option is missed or blank:
30+
# #
31+
# # rename_check_constraint :users, "phone_is_long_enough"
32+
# #
33+
# # The operation is always reversible.
34+
# def rename_check_constraint(table, expression = nil, **options, &block); end
35+
# end
3336
module PGTrunk::Operations::CheckConstraints
3437
# @private
3538
class RenameCheckConstraint < Base

lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
# frozen_string_literal: false
22

3-
# @!method ActiveRecord::Migration#validate_check_constraint(table, expression = nil, **options, &block)
4-
# Validate an invalid check constraint
5-
#
6-
# @param [#to_s] table (nil) The qualified name of the table
7-
# @param [#to_s] expression (nil) The SQL expression
8-
# @option [#to_s] :name (nil) The optional name of the constraint
9-
# @yield [Proc] the block with the constraint's definition
10-
# @yieldparam The receiver of methods specifying the constraint
11-
#
12-
# The invalid constraint can be identified by table and explicit name:
13-
#
14-
# validate_check_constraint :users, name: "phone_is_long_enough"
15-
#
16-
# Alternatively it can be specified by expression. In this case
17-
# you must ensure the expression has the same form as it is stored
18-
# in the database (after parsing the source).
19-
#
20-
# validate_check_constraint :users, "length((phone::text) > 10)"
21-
#
22-
# Notice that it is invertible but the inverted operation does nothing.
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 [#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+
# # validate_check_constraint :users, name: "phone_is_long_enough"
17+
# #
18+
# # Alternatively it can be specified by expression. In this case
19+
# # you must ensure the expression has the same form as it is stored
20+
# # in the database (after parsing the source).
21+
# #
22+
# # validate_check_constraint :users, "length((phone::text) > 10)"
23+
# #
24+
# # Notice that it is invertible but the inverted operation does nothing.
25+
# def validate_check_constraint(table, expression = nil, **options, &block); end
26+
# end
2427
module PGTrunk::Operations::CheckConstraints
2528
# @private
2629
class ValidateCheckConstraint < Base

lib/pg_trunk/operations/composite_types/change_composite_type.rb

+53-50
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,59 @@
11
# frozen_string_literal: false
22

3-
# @!method ActiveRecord::Migration#change_composite_type(name, **options, &block)
4-
# Modify a composite type
5-
#
6-
# @param [#to_s] name (nil) The qualified name of the type
7-
# @option [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
8-
# @option [#to_s] :comment (nil) The comment describing the constraint
9-
# @yield [Proc] the block with the type's definition
10-
# @yieldparam The receiver of methods specifying the type
11-
#
12-
# The operation can be used to add, drop, rename or change columns.
13-
# The comment can be changed as well.
14-
#
15-
# Providing a type "paint.colored_point":
16-
#
17-
# create_composite_type "paint.colored_point" do |t|
18-
# t.column "color", "text", collation: "en_US"
19-
# t.column "x", "integer"
20-
# t.column "z", "integer"
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 [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
9+
# # @option [#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+
# # create_composite_type "paint.colored_point" do |t|
20+
# # t.column "color", "text", collation: "en_US"
21+
# # t.column "x", "integer"
22+
# # t.column "z", "integer"
23+
# # end
24+
# #
25+
# # After the following change:
26+
# #
27+
# # change_composite_type "paint.colored_point" do |t|
28+
# # t.change_column "color", "text", collation: "ru_RU", from_collation: "en_US"
29+
# # t.change_column "x", "bigint", from_type: "integer"
30+
# # t.drop_column "z", "integer"
31+
# # t.add_column "Y", "bigint"
32+
# # t.rename_column "x", to: "X"
33+
# # t.comment "2D point with a color", from: "2D point"
34+
# # end
35+
# #
36+
# # The definition became:
37+
# #
38+
# # create_composite_type "paint.colored_point" do |t|
39+
# # t.column "color", "text", collation: "ru_RU"
40+
# # t.column "X", "bigint"
41+
# # t.column "Y", "integer"
42+
# # end
43+
# #
44+
# # Notice, that all renames will be done AFTER other changes,
45+
# # so in `change_column` you should use the old names.
46+
# #
47+
# # In several cases the operation is not invertible:
48+
# #
49+
# # - when a column was dropped
50+
# # - when `force: :cascade` option is used (to update
51+
# # objects that use the type)
52+
# # - when `if_exists: true` is added to the `drop_column` clause
53+
# # - when a previous state of the column type, collation or comment
54+
# # is not specified.
55+
# def change_composite_type(name, **options, &block); end
2156
# 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-
5457
module PGTrunk::Operations::CompositeTypes
5558
# @private
5659
class ChangeCompositeType < Base

0 commit comments

Comments
 (0)