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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/pg_trunk/operations/check_constraints/add_check_constraint.rb +36 -33
- data/lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb +43 -40
- data/lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb +33 -30
- data/lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb +24 -21
- data/lib/pg_trunk/operations/composite_types/change_composite_type.rb +53 -50
- data/lib/pg_trunk/operations/composite_types/create_composite_type.rb +22 -19
- data/lib/pg_trunk/operations/composite_types/drop_composite_type.rb +46 -43
- data/lib/pg_trunk/operations/composite_types/rename_composite_type.rb +15 -12
- data/lib/pg_trunk/operations/domains/change_domain.rb +50 -47
- data/lib/pg_trunk/operations/domains/create_domain.rb +28 -25
- data/lib/pg_trunk/operations/domains/drop_domain.rb +44 -41
- data/lib/pg_trunk/operations/domains/rename_domain.rb +15 -12
- data/lib/pg_trunk/operations/enums/change_enum.rb +35 -32
- data/lib/pg_trunk/operations/enums/create_enum.rb +23 -20
- data/lib/pg_trunk/operations/enums/drop_enum.rb +42 -39
- data/lib/pg_trunk/operations/enums/rename_enum.rb +15 -12
- data/lib/pg_trunk/operations/foreign_keys/add_foreign_key.rb +52 -49
- data/lib/pg_trunk/operations/foreign_keys/drop_foreign_key.rb +51 -48
- data/lib/pg_trunk/operations/foreign_keys/rename_foreign_key.rb +32 -29
- data/lib/pg_trunk/operations/functions/change_function.rb +50 -47
- data/lib/pg_trunk/operations/functions/create_function.rb +67 -64
- data/lib/pg_trunk/operations/functions/drop_function.rb +68 -65
- data/lib/pg_trunk/operations/functions/rename_function.rb +25 -22
- data/lib/pg_trunk/operations/materialized_views/change_materialized_view.rb +58 -55
- data/lib/pg_trunk/operations/materialized_views/create_materialized_view.rb +74 -71
- data/lib/pg_trunk/operations/materialized_views/drop_materialized_view.rb +49 -46
- data/lib/pg_trunk/operations/materialized_views/refresh_materialized_view.rb +27 -24
- data/lib/pg_trunk/operations/materialized_views/rename_materialized_view.rb +25 -22
- data/lib/pg_trunk/operations/procedures/change_procedure.rb +49 -46
- data/lib/pg_trunk/operations/procedures/create_procedure.rb +55 -52
- data/lib/pg_trunk/operations/procedures/drop_procedure.rb +48 -45
- data/lib/pg_trunk/operations/procedures/rename_procedure.rb +25 -22
- data/lib/pg_trunk/operations/statistics/create_statistics.rb +59 -56
- data/lib/pg_trunk/operations/statistics/drop_statistics.rb +56 -53
- data/lib/pg_trunk/operations/statistics/rename_statistics.rb +16 -13
- data/lib/pg_trunk/operations/triggers/change_trigger.rb +21 -18
- data/lib/pg_trunk/operations/triggers/create_trigger.rb +57 -54
- data/lib/pg_trunk/operations/triggers/drop_trigger.rb +49 -46
- data/lib/pg_trunk/operations/triggers/rename_trigger.rb +51 -48
- data/lib/pg_trunk/operations/views/change_view.rb +41 -38
- data/lib/pg_trunk/operations/views/create_view.rb +48 -45
- data/lib/pg_trunk/operations/views/drop_view.rb +49 -46
- data/lib/pg_trunk/operations/views/rename_view.rb +23 -20
- data/lib/pg_trunk/version.rb +1 -1
- metadata +2 -2
@@ -1,58 +1,61 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @option [
|
9
|
-
# @option [
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# @
|
16
|
-
# @
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# s.
|
29
|
-
#
|
30
|
-
# SQL
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# s.
|
42
|
-
#
|
43
|
-
# SQL
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Drop a custom statistics
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] name (nil) The qualified name of the statistics
|
8
|
+
# # @option [Boolean] :if_exists (false) Suppress the error when the statistics is absent
|
9
|
+
# # @option [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
|
10
|
+
# # @option [#to_s] table (nil)
|
11
|
+
# # The qualified name of the table whose statistics will be collected
|
12
|
+
# # @option [Array<Symbol>] kinds ([:dependencies, :mcv, :ndistinct])
|
13
|
+
# # The kinds of statistics to be collected (all by default).
|
14
|
+
# # Supported values in the array: :dependencies, :mcv, :ndistinct
|
15
|
+
# # @option [#to_s] :comment The description of the statistics
|
16
|
+
# # @yield [s] the block with the statistics' definition
|
17
|
+
# # @yieldparam Object receiver of methods specifying the statistics
|
18
|
+
# # @return [void]
|
19
|
+
# #
|
20
|
+
# # A statistics can be dropped by its name only:
|
21
|
+
# #
|
22
|
+
# # drop_statistics "my_stats"
|
23
|
+
# #
|
24
|
+
# # Such operation is irreversible. To make it inverted
|
25
|
+
# # you have to provide a full definition:
|
26
|
+
# #
|
27
|
+
# # drop_statistics "users_stat" do |s|
|
28
|
+
# # s.table "users"
|
29
|
+
# # s.columns "firstname", "name"
|
30
|
+
# # s.expression <<~SQL
|
31
|
+
# # round(age, 10)
|
32
|
+
# # SQL
|
33
|
+
# # s.kinds :dependency, :mcv, :ndistinct
|
34
|
+
# # p.comment "Statistics for name, firstname, and rough age"
|
35
|
+
# # SQL
|
36
|
+
# #
|
37
|
+
# # If the statistics was anonymous (used the generated name),
|
38
|
+
# # it can be dropped without defining the name as well:
|
39
|
+
# #
|
40
|
+
# # drop_statistics do |s|
|
41
|
+
# # s.table "users"
|
42
|
+
# # s.columns "firstname", "name"
|
43
|
+
# # s.expression <<~SQL
|
44
|
+
# # round(age, 10)
|
45
|
+
# # SQL
|
46
|
+
# # s.kinds :dependency, :mcv, :ndistinct
|
47
|
+
# # p.comment "Statistics for name, firstname, and rough age"
|
48
|
+
# # SQL
|
49
|
+
# #
|
50
|
+
# # The operation can be called with `if_exists` option. In this case
|
51
|
+
# # it would do nothing when no statistics existed.
|
52
|
+
# #
|
53
|
+
# # drop_procedure "unknown_statistics", if_exists: true
|
54
|
+
# #
|
55
|
+
# # Notice, that this option make the operation irreversible because of
|
56
|
+
# # uncertainty about the previous state of the database.
|
57
|
+
# def drop_statistics(name, **options, &block); end
|
58
|
+
# end
|
56
59
|
module PGTrunk::Operations::Statistics
|
57
60
|
# @private
|
58
61
|
class DropStatistics < Base
|
@@ -1,18 +1,21 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Change the name and/or schema of a statistics
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] :name (nil) The qualified name of the statistics
|
8
|
+
# # @option [#to_s] :to (nil) The new qualified name for the statistics
|
9
|
+
# # @return [void]
|
10
|
+
# #
|
11
|
+
# # A custom statistics can be renamed by changing both the name
|
12
|
+
# # and the schema (namespace) it belongs to.
|
13
|
+
# #
|
14
|
+
# # rename_statistics "math.my_stat", to: "public.my_stats"
|
15
|
+
# #
|
16
|
+
# # The operation is always reversible.
|
17
|
+
# def rename_statistics(name, to:); end
|
18
|
+
# end
|
16
19
|
module PGTrunk::Operations::Statistics
|
17
20
|
# @private
|
18
21
|
class RenameStatistics < Base
|
@@ -1,24 +1,27 @@
|
|
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
|
-
# t.
|
18
|
-
# t.
|
19
|
-
# t.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Create a trigger for a table
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] name (nil) The name of the trigger
|
9
|
+
# # @option [Boolean] :if_exists (false) Suppress the error when the trigger is absent
|
10
|
+
# # @yield [t] the block with the trigger's definition
|
11
|
+
# # @yieldparam Object receiver of methods specifying the trigger
|
12
|
+
# # @return [void]
|
13
|
+
# #
|
14
|
+
# # The trigger can be changed using `CREATE OR REPLACE TRIGGER` command:
|
15
|
+
# #
|
16
|
+
# # change_trigger "users", "do_something" do |t|
|
17
|
+
# # t.function "do_something()", from: "do_something_different()"
|
18
|
+
# # t.for_each :row # from: :statement
|
19
|
+
# # t.type :after, from: :before
|
20
|
+
# # t.events %i[insert update], from: %i[insert]
|
21
|
+
# # t.comment "Does something useful", from: ""
|
22
|
+
# # end
|
23
|
+
# def create_trigger(table, name = nil, **options, &block); end
|
20
24
|
# end
|
21
|
-
|
22
25
|
module PGTrunk::Operations::Triggers
|
23
26
|
# @private
|
24
27
|
class ChangeTrigger < Base
|
@@ -1,60 +1,63 @@
|
|
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
|
-
# @option [
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @option [
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @
|
22
|
-
# @
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# t
|
38
|
-
# t.
|
39
|
-
# t.
|
40
|
-
# t.
|
41
|
-
# t.
|
42
|
-
# t.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Create a trigger for a table
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] name (nil) The name of the trigger
|
9
|
+
# # @option [Boolean] :replace_existing (false) If the trigger should overwrite an existing one
|
10
|
+
# # @option [#to_s] :function (nil) The qualified name of the function to be called
|
11
|
+
# # @option [Symbol] :type (nil) When the trigger should be run
|
12
|
+
# # Supported values: :before, :after, :instead_of
|
13
|
+
# # @option [Array<Symbol>] :events List of events running the trigger
|
14
|
+
# # Supported values in the array: :insert, :update, :delete, :truncate
|
15
|
+
# # @option [Boolean] :constraint (false) If the trigger is a constraint
|
16
|
+
# # @option [Symbol] :initially (:immediate) If the constraint check should be deferred
|
17
|
+
# # Supported values: :immediate (default), :deferred
|
18
|
+
# # @option [#to_s] :when (nil) The SQL snippet definiing a condition for the trigger
|
19
|
+
# # @option [Symbol] :for_each (:statement) Define if a trigger should be run for every row
|
20
|
+
# # Supported values: :statement (default), :row
|
21
|
+
# # @option [#to_s] :comment (nil) The commend describing the trigger
|
22
|
+
# # @yield [t] the block with the trigger's definition
|
23
|
+
# # @yieldparam Object receiver of methods specifying the trigger
|
24
|
+
# # @return [void]
|
25
|
+
# #
|
26
|
+
# # The trigger can be created either using inline syntax
|
27
|
+
# #
|
28
|
+
# # create_trigger "users", "do_something",
|
29
|
+
# # function: "do_something()",
|
30
|
+
# # for_each: :row,
|
31
|
+
# # type: :after,
|
32
|
+
# # events: %i[insert update],
|
33
|
+
# # comment: "Does something useful"
|
34
|
+
# #
|
35
|
+
# # or using a block:
|
36
|
+
# #
|
37
|
+
# # create_trigger do |t|
|
38
|
+
# # t.table "users"
|
39
|
+
# # t.name "do_something"
|
40
|
+
# # t.function "do_something()"
|
41
|
+
# # t.for_each :row
|
42
|
+
# # t.type :after
|
43
|
+
# # t.events %i[insert update]
|
44
|
+
# # t.comment "Does something useful"
|
45
|
+
# # end
|
46
|
+
# #
|
47
|
+
# # With a `replace_existing: true` option,
|
48
|
+
# # it will be created using the `CREATE OR REPLACE` clause.
|
49
|
+
# # (Available in PostgreSQL v14+).
|
50
|
+
# #
|
51
|
+
# # create_trigger "users", "do_something",
|
52
|
+
# # function: "do_something()",
|
53
|
+
# # type: :after,
|
54
|
+
# # events: %i[insert update],
|
55
|
+
# # replace_previous: true
|
56
|
+
# #
|
57
|
+
# # In this case the migration is irreversible because we
|
58
|
+
# # don't know if and how to restore its previous definition.
|
59
|
+
# def create_trigger(table, name = nil, **options, &block); end
|
43
60
|
# end
|
44
|
-
#
|
45
|
-
# With a `replace_existing: true` option,
|
46
|
-
# it will be created using the `CREATE OR REPLACE` clause.
|
47
|
-
# (Available in PostgreSQL v14+).
|
48
|
-
#
|
49
|
-
# create_trigger "users", "do_something",
|
50
|
-
# function: "do_something()",
|
51
|
-
# type: :after,
|
52
|
-
# events: %i[insert update],
|
53
|
-
# replace_previous: true
|
54
|
-
#
|
55
|
-
# In this case the migration is irreversible because we
|
56
|
-
# don't know if and how to restore its previous definition.
|
57
|
-
|
58
61
|
module PGTrunk::Operations::Triggers
|
59
62
|
# @private
|
60
63
|
class CreateTrigger < Base
|
@@ -1,52 +1,55 @@
|
|
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
|
-
# @option [
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @option [
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @
|
22
|
-
# @
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# t
|
33
|
-
# t.
|
34
|
-
# t.
|
35
|
-
# t.
|
36
|
-
# t.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Drop a trigger for a table
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] name (nil) The name of the trigger
|
9
|
+
# # @option [Boolean] :if_exists (false) Suppress the error when the trigger is absent
|
10
|
+
# # @option [#to_s] :function (nil) The qualified name of the function to be called
|
11
|
+
# # @option [Symbol] :type (nil) When the trigger should be run
|
12
|
+
# # Supported values: :before, :after, :instead_of
|
13
|
+
# # @option [Array<Symbol>] :events List of events running the trigger
|
14
|
+
# # Supported values in the array: :insert, :update, :delete, :truncate
|
15
|
+
# # @option [Boolean] :constraint (false) If the trigger is a constraint
|
16
|
+
# # @option [Symbol] :initially (:immediate) If the constraint check should be deferred
|
17
|
+
# # Supported values: :immediate (default), :deferred
|
18
|
+
# # @option [#to_s] :when (nil) The SQL snippet definiing a condition for the trigger
|
19
|
+
# # @option [Symbol] :for_each (:statement) Define if a trigger should be run for every row
|
20
|
+
# # Supported values: :statement (default), :row
|
21
|
+
# # @option [#to_s] :comment (nil) The commend describing the trigger
|
22
|
+
# # @yield [t] the block with the trigger's definition
|
23
|
+
# # @yieldparam Object receiver of methods specifying the trigger
|
24
|
+
# # @return [void]
|
25
|
+
# #
|
26
|
+
# # A trigger can be dropped by a table and name:
|
27
|
+
# #
|
28
|
+
# # drop_trigger "users", "do_something"
|
29
|
+
# #
|
30
|
+
# # the default name can be restored from its attributes as well.
|
31
|
+
# #
|
32
|
+
# # drop_trigger "users" do |t|
|
33
|
+
# # t.function "send_notifications()"
|
34
|
+
# # t.for_each :row
|
35
|
+
# # t.type :after
|
36
|
+
# # t.events %i[update]
|
37
|
+
# # t.columns %w[email phone]
|
38
|
+
# # t.comment "Does something"
|
39
|
+
# # end
|
40
|
+
# #
|
41
|
+
# # Notice, that you have to specify all attributes to make
|
42
|
+
# # the operation reversible.
|
43
|
+
# #
|
44
|
+
# # The operation can be called with `if_exists` option. In this case
|
45
|
+
# # it would do nothing when no trigger existed.
|
46
|
+
# #
|
47
|
+
# # drop_trigger "users", "unknown_trigger", if_exists: true
|
48
|
+
# #
|
49
|
+
# # This option, though, makes the operation irreversible because of
|
50
|
+
# # uncertainty of the previous state of the database.
|
51
|
+
# def drop_trigger(table, name = nil, **options, &block); end
|
37
52
|
# end
|
38
|
-
#
|
39
|
-
# Notice, that you have to specify all attributes to make
|
40
|
-
# the operation reversible.
|
41
|
-
#
|
42
|
-
# The operation can be called with `if_exists` option. In this case
|
43
|
-
# it would do nothing when no trigger existed.
|
44
|
-
#
|
45
|
-
# drop_trigger "users", "unknown_trigger", if_exists: true
|
46
|
-
#
|
47
|
-
# This option, though, makes the operation irreversible because of
|
48
|
-
# uncertainty of the previous state of the database.
|
49
|
-
|
50
53
|
module PGTrunk::Operations::Triggers
|
51
54
|
# @private
|
52
55
|
class DropTrigger < Base
|
@@ -1,54 +1,57 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param [#to_s]
|
8
|
-
# @
|
9
|
-
# @
|
10
|
-
# @param [#to_s]
|
11
|
-
# @
|
12
|
-
# @option [#to_s] :
|
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
|
-
# t.
|
38
|
-
# t.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Rename a trigger
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
8
|
+
# # @param [#to_s] name (nil) The name of the trigger
|
9
|
+
# # @option [#to_s] :to (nil) The new name of the trigger
|
10
|
+
# # @param [#to_s] table (nil) The qualified name of the table
|
11
|
+
# # @param [#to_s] name (nil) The current name of the trigger
|
12
|
+
# # @option [#to_s] :to (nil) The new name for the trigger
|
13
|
+
# # @option [#to_s] :function (nil) The qualified name of the function to be called
|
14
|
+
# # @option [Symbol] :type (nil) When the trigger should be run
|
15
|
+
# # Supported values: :before, :after, :instead_of
|
16
|
+
# # @option [Array<Symbol>] :events List of events running the trigger
|
17
|
+
# # Supported values in the array: :insert, :update, :delete, :truncate
|
18
|
+
# # @option [Symbol] :for_each (:statement) Define if a trigger should be run for every row
|
19
|
+
# # Supported values: :statement (default), :row
|
20
|
+
# # @yield [t] the block with the trigger's definition
|
21
|
+
# # @yieldparam Object receiver of methods specifying the trigger
|
22
|
+
# # @return [void]
|
23
|
+
# #
|
24
|
+
# # A trigger can be renamed by either setting a new name explicitly
|
25
|
+
# #
|
26
|
+
# # rename_trigger "users", "do_something", to: "do_something_different"
|
27
|
+
# #
|
28
|
+
# # or resetting it to the default (generated) value.
|
29
|
+
# #
|
30
|
+
# # rename_trigger "users", "do_something"
|
31
|
+
# #
|
32
|
+
# # The previously generated name of the trigger can be get
|
33
|
+
# # from its parameters. In this case all the essentials
|
34
|
+
# # parameters must be specified:
|
35
|
+
# #
|
36
|
+
# # rename_trigger "users", to: "do_something_different" do |t|
|
37
|
+
# # t.function "do_something()"
|
38
|
+
# # t.for_each :row
|
39
|
+
# # t.type :after
|
40
|
+
# # t.events %i[insert update]
|
41
|
+
# # end
|
42
|
+
# #
|
43
|
+
# # In the same way, when you reset the name to default,
|
44
|
+
# # all the essential parameters must be got to make the trigger
|
45
|
+
# # invertible.
|
46
|
+
# #
|
47
|
+
# # rename_trigger "users", "do_something" do |t|
|
48
|
+
# # t.function "do_something()"
|
49
|
+
# # t.for_each :row
|
50
|
+
# # t.type :after
|
51
|
+
# # t.events %i[insert update]
|
52
|
+
# # end
|
53
|
+
# def rename_trigger(table, name = nil, **options, &block); end
|
39
54
|
# end
|
40
|
-
#
|
41
|
-
# In the same way, when you reset the name to default,
|
42
|
-
# all the essential parameters must be got to make the trigger
|
43
|
-
# invertible.
|
44
|
-
#
|
45
|
-
# rename_trigger "users", "do_something" do |t|
|
46
|
-
# t.function "do_something()"
|
47
|
-
# t.for_each :row
|
48
|
-
# t.type :after
|
49
|
-
# t.events %i[insert update]
|
50
|
-
# end
|
51
|
-
|
52
55
|
module PGTrunk::Operations::Triggers
|
53
56
|
# @private
|
54
57
|
class RenameTrigger < Base
|
@@ -1,44 +1,47 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @
|
9
|
-
# @
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# SQL
|
17
|
-
# SELECT
|
18
|
-
# SQL
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Modify a view
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] name (nil) The qualified name of the view
|
8
|
+
# # @option [Boolean] :if_exists (false) Suppress the error when the view is absent
|
9
|
+
# # @yield [v] the block with the view's definition
|
10
|
+
# # @yieldparam Object receiver of methods specifying the view
|
11
|
+
# # @return [void]
|
12
|
+
# #
|
13
|
+
# # The operation replaces the view with a new definition(s):
|
14
|
+
# #
|
15
|
+
# # change_view "admin_users" do |v|
|
16
|
+
# # v.sql_definition: <<~SQL, from: <<~SQL
|
17
|
+
# # SELECT id, name FROM users WHERE admin;
|
18
|
+
# # SQL
|
19
|
+
# # SELECT * FROM users WHERE admin;
|
20
|
+
# # SQL
|
21
|
+
# # end
|
22
|
+
# #
|
23
|
+
# # For some compatibility to the `scenic` gem, we also support
|
24
|
+
# # adding a definition via its version:
|
25
|
+
# #
|
26
|
+
# # change_view "admin_users" do |v|
|
27
|
+
# # v.version 2, from: 1
|
28
|
+
# # end
|
29
|
+
# #
|
30
|
+
# # It is expected, that both `db/views/admin_users_v01.sql`
|
31
|
+
# # and `db/views/admin_users_v02.sql` to contain SQL snippets.
|
32
|
+
# #
|
33
|
+
# # Please, notice that neither deletion of columns,
|
34
|
+
# # nor changing their types is supported by the PostgreSQL.
|
35
|
+
# #
|
36
|
+
# # You can also (re)set a comment describing the view,
|
37
|
+
# # and the check option (either `:local` or `:cascaded`):
|
38
|
+
# #
|
39
|
+
# # change_view "admin_users" do |v|
|
40
|
+
# # v.check :local, from: :cascaded
|
41
|
+
# # v.comment "Admin users only", from: ""
|
42
|
+
# # end
|
43
|
+
# def change_view(name, **options, &block); end
|
19
44
|
# end
|
20
|
-
#
|
21
|
-
# For some compatibility to the `scenic` gem, we also support
|
22
|
-
# adding a definition via its version:
|
23
|
-
#
|
24
|
-
# change_view "admin_users" do |v|
|
25
|
-
# v.version 2, from: 1
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# It is expected, that both `db/views/admin_users_v01.sql`
|
29
|
-
# and `db/views/admin_users_v02.sql` to contain SQL snippets.
|
30
|
-
#
|
31
|
-
# Please, notice that neither deletion of columns,
|
32
|
-
# nor changing their types is supported by the PostgreSQL.
|
33
|
-
#
|
34
|
-
# You can also (re)set a comment describing the view,
|
35
|
-
# and the check option (either `:local` or `:cascaded`):
|
36
|
-
#
|
37
|
-
# change_view "admin_users" do |v|
|
38
|
-
# v.check :local, from: :cascaded
|
39
|
-
# v.comment "Admin users only", from: ""
|
40
|
-
# end
|
41
|
-
|
42
45
|
module PGTrunk::Operations::Views
|
43
46
|
# @private
|
44
47
|
class ChangeView < Base
|