pg_trunk 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +4 -15
  3. data/CHANGELOG.md +21 -0
  4. data/README.md +3 -1
  5. data/lib/pg_trunk/core/operation/attributes.rb +1 -1
  6. data/lib/pg_trunk/core/railtie/custom_types.rb +5 -6
  7. data/lib/pg_trunk/operations/check_constraints/add_check_constraint.rb +42 -33
  8. data/lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb +51 -40
  9. data/lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb +39 -30
  10. data/lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb +28 -21
  11. data/lib/pg_trunk/operations/composite_types/change_composite_type.rb +59 -50
  12. data/lib/pg_trunk/operations/composite_types/create_composite_type.rb +23 -19
  13. data/lib/pg_trunk/operations/composite_types/drop_composite_type.rb +48 -43
  14. data/lib/pg_trunk/operations/composite_types/rename_composite_type.rb +15 -12
  15. data/lib/pg_trunk/operations/domains/change_domain.rb +53 -47
  16. data/lib/pg_trunk/operations/domains/create_domain.rb +28 -25
  17. data/lib/pg_trunk/operations/domains/drop_domain.rb +50 -41
  18. data/lib/pg_trunk/operations/domains/rename_domain.rb +17 -12
  19. data/lib/pg_trunk/operations/enums/change_enum.rb +37 -32
  20. data/lib/pg_trunk/operations/enums/create_enum.rb +23 -20
  21. data/lib/pg_trunk/operations/enums/drop_enum.rb +50 -39
  22. data/lib/pg_trunk/operations/enums/rename_enum.rb +17 -12
  23. data/lib/pg_trunk/operations/foreign_keys/add_foreign_key.rb +58 -49
  24. data/lib/pg_trunk/operations/foreign_keys/drop_foreign_key.rb +57 -48
  25. data/lib/pg_trunk/operations/foreign_keys/rename_foreign_key.rb +38 -29
  26. data/lib/pg_trunk/operations/functions/change_function.rb +53 -47
  27. data/lib/pg_trunk/operations/functions/create_function.rb +75 -64
  28. data/lib/pg_trunk/operations/functions/drop_function.rb +78 -65
  29. data/lib/pg_trunk/operations/functions/rename_function.rb +29 -22
  30. data/lib/pg_trunk/operations/materialized_views/change_materialized_view.rb +65 -55
  31. data/lib/pg_trunk/operations/materialized_views/create_materialized_view.rb +82 -71
  32. data/lib/pg_trunk/operations/materialized_views/drop_materialized_view.rb +59 -46
  33. data/lib/pg_trunk/operations/materialized_views/refresh_materialized_view.rb +29 -24
  34. data/lib/pg_trunk/operations/materialized_views/rename_materialized_view.rb +29 -22
  35. data/lib/pg_trunk/operations/procedures/change_procedure.rb +53 -46
  36. data/lib/pg_trunk/operations/procedures/create_procedure.rb +63 -52
  37. data/lib/pg_trunk/operations/procedures/drop_procedure.rb +56 -45
  38. data/lib/pg_trunk/operations/procedures/rename_procedure.rb +29 -22
  39. data/lib/pg_trunk/operations/rules/base.rb +77 -0
  40. data/lib/pg_trunk/operations/rules/create_rule.rb +155 -0
  41. data/lib/pg_trunk/operations/rules/drop_rule.rb +94 -0
  42. data/lib/pg_trunk/operations/rules/rename_rule.rb +62 -0
  43. data/lib/pg_trunk/operations/rules.rb +13 -0
  44. data/lib/pg_trunk/operations/sequences/base.rb +79 -0
  45. data/lib/pg_trunk/operations/sequences/change_sequence.rb +142 -0
  46. data/lib/pg_trunk/operations/sequences/create_sequence.rb +180 -0
  47. data/lib/pg_trunk/operations/sequences/drop_sequence.rb +82 -0
  48. data/lib/pg_trunk/operations/sequences/rename_sequence.rb +64 -0
  49. data/lib/pg_trunk/operations/sequences.rb +14 -0
  50. data/lib/pg_trunk/operations/statistics/create_statistics.rb +67 -56
  51. data/lib/pg_trunk/operations/statistics/drop_statistics.rb +64 -53
  52. data/lib/pg_trunk/operations/statistics/rename_statistics.rb +18 -13
  53. data/lib/pg_trunk/operations/triggers/change_trigger.rb +23 -18
  54. data/lib/pg_trunk/operations/triggers/create_trigger.rb +63 -54
  55. data/lib/pg_trunk/operations/triggers/drop_trigger.rb +55 -46
  56. data/lib/pg_trunk/operations/triggers/rename_trigger.rb +51 -48
  57. data/lib/pg_trunk/operations/views/change_view.rb +47 -38
  58. data/lib/pg_trunk/operations/views/create_view.rb +56 -45
  59. data/lib/pg_trunk/operations/views/drop_view.rb +59 -46
  60. data/lib/pg_trunk/operations/views/rename_view.rb +27 -20
  61. data/lib/pg_trunk/operations.rb +2 -0
  62. data/lib/pg_trunk/version.rb +1 -1
  63. data/pg_trunk.gemspec +0 -1
  64. data/spec/operations/rules/create_rule_spec.rb +119 -0
  65. data/spec/operations/rules/drop_rule_spec.rb +117 -0
  66. data/spec/operations/rules/rename_rule_spec.rb +148 -0
  67. data/spec/operations/sequences/change_sequence_spec.rb +134 -0
  68. data/spec/operations/sequences/create_sequence_spec.rb +156 -0
  69. data/spec/operations/sequences/drop_sequence_spec.rb +102 -0
  70. data/spec/operations/sequences/rename_sequence_spec.rb +100 -0
  71. metadata +22 -68
@@ -1,70 +1,81 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#create_function(name, **options, &block)
4
- # Create a function
5
- #
6
- # @param [#to_s] name (nil)
7
- # The qualified name of the function with arguments and returned value type
8
- # @option [Boolean] :replace_existing (false) If the function should overwrite an existing one
9
- # @option [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
10
- # @option [#to_s] :body (nil) The body of the function
11
- # @option [Symbol] :volatility (:volatile) The volatility of the function.
12
- # Supported values: :volatile (default), :stable, :immutable
13
- # @option [Symbol] :parallel (:unsafe) The safety of parallel execution.
14
- # Supported values: :unsafe (default), :restricted, :safe
15
- # @option [Symbol] :security (:invoker) Define the role under which the function is invoked
16
- # Supported values: :invoker (default), :definer
17
- # @option [Boolean] :leakproof (false) If the function is leakproof
18
- # @option [Boolean] :strict (false) If the function is strict
19
- # @option [Float] :cost (nil) The cost estimation for the function
20
- # @option [Integer] :rows (nil) The number of rows returned by a function
21
- # @option [#to_s] :comment The description of the function
22
- # @yield [Proc] the block with the function's definition
23
- # @yieldparam The receiver of methods specifying the function
24
- #
25
- # The function can be created either using inline syntax
26
- #
27
- # create_function "math.mult(a int, b int) int",
28
- # language: :sql,
29
- # body: "SELECT a * b",
30
- # volatility: :immutable,
31
- # leakproof: true,
32
- # comment: "Multiplies 2 integers"
33
- #
34
- # or using a block:
35
- #
36
- # create_function "math.mult(a int, b int) int" do |f|
37
- # f.language "sql" # (default)
38
- # f.body <<~SQL
39
- # SELECT a * b;
40
- # SQL
41
- # f.volatility :immutable # :stable, :volatile (default)
42
- # f.parallel :safe # :restricted, :unsafe (default)
43
- # f.security :invoker # (default), also :definer
44
- # f.leakproof true
45
- # f.strict true
46
- # f.cost 5.0
47
- # # f.rows 1 (supported for functions returning sets of rows)
48
- # f.comment "Multiplies 2 integers"
49
- # SQL
50
- #
51
- # With a `replace_existing: true` option,
52
- # it will be created using the `CREATE OR REPLACE` clause.
53
- # In this case the migration is irreversible because we
54
- # don't know if and how to restore its previous definition.
55
- #
56
- # create_function "math.mult(a int, b int) int",
57
- # body: "SELECT a * b",
58
- # replace_existing: true
59
- #
60
- # We presume a function without arguments should have
61
- # no arguments and return `void` like
62
- #
63
- # # the same as "do_something() void"
64
- # create_function "do_something" do |f|
65
- # # ...
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Create a function
6
+ # #
7
+ # # @param [#to_s] name (nil)
8
+ # # The qualified name of the function with arguments and returned value type
9
+ # # @option options [Boolean] :replace_existing (false) If the function should overwrite an existing one
10
+ # # @option options [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
11
+ # # @option options [#to_s] :body (nil) The body of the function
12
+ # # @option options [Symbol] :volatility (:volatile) The volatility of the function.
13
+ # # Supported values: :volatile (default), :stable, :immutable
14
+ # # @option options [Symbol] :parallel (:unsafe) The safety of parallel execution.
15
+ # # Supported values: :unsafe (default), :restricted, :safe
16
+ # # @option options [Symbol] :security (:invoker) Define the role under which the function is invoked
17
+ # # Supported values: :invoker (default), :definer
18
+ # # @option options [Boolean] :leakproof (false) If the function is leakproof
19
+ # # @option options [Boolean] :strict (false) If the function is strict
20
+ # # @option options [Float] :cost (nil) The cost estimation for the function
21
+ # # @option options [Integer] :rows (nil) The number of rows returned by a function
22
+ # # @option options [#to_s] :comment The description of the function
23
+ # # @yield [f] the block with the function's definition
24
+ # # @yieldparam Object receiver of methods specifying the function
25
+ # # @return [void]
26
+ # #
27
+ # # The function can be created either using inline syntax
28
+ # #
29
+ # # ```ruby
30
+ # # create_function "math.mult(a int, b int) int",
31
+ # # language: :sql,
32
+ # # body: "SELECT a * b",
33
+ # # volatility: :immutable,
34
+ # # leakproof: true,
35
+ # # comment: "Multiplies 2 integers"
36
+ # # ```
37
+ # #
38
+ # # or using a block:
39
+ # #
40
+ # # ```ruby
41
+ # # create_function "math.mult(a int, b int) int" do |f|
42
+ # # f.language "sql" # (default)
43
+ # # f.body <<~SQL
44
+ # # SELECT a * b;
45
+ # # SQL
46
+ # # f.volatility :immutable # :stable, :volatile (default)
47
+ # # f.parallel :safe # :restricted, :unsafe (default)
48
+ # # f.security :invoker # (default), also :definer
49
+ # # f.leakproof true
50
+ # # f.strict true
51
+ # # f.cost 5.0
52
+ # # # f.rows 1 (supported for functions returning sets of rows)
53
+ # # f.comment "Multiplies 2 integers"
54
+ # # SQL
55
+ # # ```
56
+ # #
57
+ # # With a `replace_existing: true` option,
58
+ # # it will be created using the `CREATE OR REPLACE` clause.
59
+ # # In this case the migration is irreversible because we
60
+ # # don't know if and how to restore its previous definition.
61
+ # #
62
+ # # ```ruby
63
+ # # create_function "math.mult(a int, b int) int",
64
+ # # body: "SELECT a * b",
65
+ # # replace_existing: true
66
+ # # ```
67
+ # #
68
+ # # We presume a function without arguments should have
69
+ # # no arguments and return `void` like
70
+ # #
71
+ # # ```ruby
72
+ # # # the same as "do_something() void"
73
+ # # create_function "do_something" do |f|
74
+ # # # ...
75
+ # # end
76
+ # # ```
77
+ # def create_function(name, **options, &block); end
66
78
  # end
67
-
68
79
  module PGTrunk::Operations::Functions
69
80
  # @private
70
81
  class CreateFunction < Base
@@ -1,71 +1,84 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#drop_function(name, **options, &block)
4
- # Drop a function
5
- #
6
- # @param [#to_s] name (nil)
7
- # The qualified name of the function with arguments and returned value type
8
- # @option [Boolean] :if_exists (false) Suppress the error when the function is absent
9
- # @option [Symbol] :force (:restrict) How to process dependent objects
10
- # Supported values: :restrict (default), :cascade
11
- # @option [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
12
- # @option [#to_s] :body (nil) The body of the function
13
- # @option [Symbol] :volatility (:volatile) The volatility of the function.
14
- # Supported values: :volatile (default), :stable, :immutable
15
- # @option [Symbol] :parallel (:unsafe) The safety of parallel execution.
16
- # Supported values: :unsafe (default), :restricted, :safe
17
- # @option [Symbol] :security (:invoker) Define the role under which the function is invoked
18
- # Supported values: :invoker (default), :definer
19
- # @option [Boolean] :leakproof (false) If the function is leakproof
20
- # @option [Boolean] :strict (false) If the function is strict
21
- # @option [Float] :cost (nil) The cost estimation for the function
22
- # @option [Integer] :rows (nil) The number of rows returned by a function
23
- # @option [#to_s] :comment The description of the function
24
- # @yield [Proc] the block with the function's definition
25
- # @yieldparam The receiver of methods specifying the function
26
- #
27
- # A function can be dropped by a plain name:
28
- #
29
- # drop_function "multiply"
30
- #
31
- # If several overloaded functions have the name,
32
- # then you must specify the signature having
33
- # types of attributes at least:
34
- #
35
- # drop_function "multiply(int, int)"
36
- #
37
- # In both cases above the operation is irreversible. To make it
38
- # inverted you have to provide a full signature along with
39
- # the body definition. The other options are supported as well:
40
- #
41
- # drop_function "math.mult(a int, b int) int" do |f|
42
- # f.language "sql" # (default)
43
- # f.body <<~SQL
44
- # SELECT a * b;
45
- # SQL
46
- # f.volatility :immutable # :stable, :volatile (default)
47
- # f.parallel :safe # :restricted, :unsafe (default)
48
- # f.security :invoker # (default), also :definer
49
- # f.leakproof true
50
- # f.strict true
51
- # f.cost 5.0
52
- # # f.rows 1 (supported for functions returning sets of rows)
53
- # f.comment "Multiplies 2 integers"
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Drop a function
6
+ # #
7
+ # # @param [#to_s] name (nil)
8
+ # # The qualified name of the function with arguments and returned value type
9
+ # # @option options [Boolean] :if_exists (false) Suppress the error when the function is absent
10
+ # # @option options [Symbol] :force (:restrict) How to process dependent objects
11
+ # # Supported values: :restrict (default), :cascade
12
+ # # @option options [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
13
+ # # @option options [#to_s] :body (nil) The body of the function
14
+ # # @option options [Symbol] :volatility (:volatile) The volatility of the function.
15
+ # # Supported values: :volatile (default), :stable, :immutable
16
+ # # @option options [Symbol] :parallel (:unsafe) The safety of parallel execution.
17
+ # # Supported values: :unsafe (default), :restricted, :safe
18
+ # # @option options [Symbol] :security (:invoker) Define the role under which the function is invoked
19
+ # # Supported values: :invoker (default), :definer
20
+ # # @option options [Boolean] :leakproof (false) If the function is leakproof
21
+ # # @option options [Boolean] :strict (false) If the function is strict
22
+ # # @option options [Float] :cost (nil) The cost estimation for the function
23
+ # # @option options [Integer] :rows (nil) The number of rows returned by a function
24
+ # # @option options [#to_s] :comment The description of the function
25
+ # # @yield [f] the block with the function's definition
26
+ # # @yieldparam Object receiver of methods specifying the function
27
+ # # @return [void]
28
+ # #
29
+ # # A function can be dropped by a plain name:
30
+ # #
31
+ # # ```ruby
32
+ # # drop_function "multiply"
33
+ # # ```
34
+ # #
35
+ # # If several overloaded functions have the name,
36
+ # # then you must specify the signature having
37
+ # # types of attributes at least:
38
+ # #
39
+ # # ```ruby
40
+ # # drop_function "multiply(int, int)"
41
+ # # ```
42
+ # #
43
+ # # In both cases above the operation is irreversible. To make it
44
+ # # inverted you have to provide a full signature along with
45
+ # # the body definition. The other options are supported as well:
46
+ # #
47
+ # # ```ruby
48
+ # # drop_function "math.mult(a int, b int) int" do |f|
49
+ # # f.language "sql" # (default)
50
+ # # f.body <<~SQL
51
+ # # SELECT a * b;
52
+ # # SQL
53
+ # # f.volatility :immutable # :stable, :volatile (default)
54
+ # # f.parallel :safe # :restricted, :unsafe (default)
55
+ # # f.security :invoker # (default), also :definer
56
+ # # f.leakproof true
57
+ # # f.strict true
58
+ # # f.cost 5.0
59
+ # # # f.rows 1 (supported for functions returning sets of rows)
60
+ # # f.comment "Multiplies 2 integers"
61
+ # # end
62
+ # # ```
63
+ # #
64
+ # # The operation can be called with `if_exists` option. In this case
65
+ # # it would do nothing when no function existed.
66
+ # #
67
+ # # ```ruby
68
+ # # drop_function "math.multiply(integer, integer)", if_exists: true
69
+ # # ```
70
+ # #
71
+ # # Another operation-specific option `force: :cascade` enables
72
+ # # to drop silently any object depending on the function.
73
+ # #
74
+ # # ```ruby
75
+ # # drop_function "math.multiply(integer, integer)", force: :cascade
76
+ # # ```
77
+ # #
78
+ # # Both options make the operation irreversible because of
79
+ # # uncertainty about the previous state of the database.
80
+ # def drop_function(name, **options, &block); end
54
81
  # end
55
- #
56
- # The operation can be called with `if_exists` option. In this case
57
- # it would do nothing when no function existed.
58
- #
59
- # drop_function "math.multiply(integer, integer)", if_exists: true
60
- #
61
- # Another operation-specific option `force: :cascade` enables
62
- # to drop silently any object depending on the function.
63
- #
64
- # drop_function "math.multiply(integer, integer)", force: :cascade
65
- #
66
- # Both options make the operation irreversible because of
67
- # uncertainty about the previous state of the database.
68
-
69
82
  module PGTrunk::Operations::Functions
70
83
  # @private
71
84
  class DropFunction < Base
@@ -1,27 +1,34 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#rename_function(name, to:)
4
- # Change the name and/or schema of a function
5
- #
6
- # @param [#to_s] :name (nil) The qualified name of the function
7
- # @option [#to_s] :to (nil) The new qualified name for the function
8
- #
9
- # A function can be renamed by changing both the name
10
- # and the schema (namespace) it belongs to.
11
- #
12
- # If there are no overloaded functions, then you can use a plain name:
13
- #
14
- # rename_function "math.multiply", to: "public.product"
15
- #
16
- # otherwise the types of attributes must be explicitly specified.
17
- #
18
- # rename_function "math.multiply(int, int)", to: "public.product"
19
- #
20
- # Any specification of attributes or returned values in `to:` option
21
- # is ignored because they cannot be changed anyway.
22
- #
23
- # The operation is always reversible.
24
-
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Change the name and/or schema of a function
6
+ # #
7
+ # # @param [#to_s] :name (nil) The qualified name of the function
8
+ # # @option options [#to_s] :to (nil) The new qualified name for the function
9
+ # # @return [void]
10
+ # #
11
+ # # A function can be renamed by changing both the name
12
+ # # and the schema (namespace) it belongs to.
13
+ # #
14
+ # # If there are no overloaded functions, then you can use a plain name:
15
+ # #
16
+ # # ```ruby
17
+ # # rename_function "math.multiply", to: "public.product"
18
+ # # ```
19
+ # #
20
+ # # otherwise the types of attributes must be explicitly specified.
21
+ # #
22
+ # # ```ruby
23
+ # # rename_function "math.multiply(int, int)", to: "public.product"
24
+ # # ```
25
+ # #
26
+ # # Any specification of attributes or returned values in `to:` option
27
+ # # is ignored because they cannot be changed anyway.
28
+ # #
29
+ # # The operation is always reversible.
30
+ # def rename_function(name, to:); end
31
+ # end
25
32
  module PGTrunk::Operations::Functions
26
33
  # @private
27
34
  class RenameFunction < Base
@@ -1,61 +1,71 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # @!method ActiveRecord::Migration#change_materialized_view(name, **options, &block)
4
- # Modify a materialized view
5
- #
6
- # @param [#to_s] name (nil) The qualified name of the view
7
- # @option [Boolean] :if_exists (false) Suppress the error when the view is absent
8
- # @yield [Proc] the block with the view's definition
9
- # @yieldparam The receiver of methods specifying the view
10
- #
11
- # The operation enables to alter a view without recreating
12
- # its from scratch. You can rename columns, change their
13
- # storage settings (how the column is TOAST-ed), or
14
- # customize their statistics.
15
- #
16
- # change_materialized_view "admin_users" do |v|
17
- # v.rename_column "name", to: "full_name"
18
- # v.column "name", storage: "extended", from_storage: "expanded"
19
- # v.column "admin", n_distinct: 2
20
- # v.column "role", statistics: 100
3
+ # @!parse
4
+ # class ActiveRecord::Migration
5
+ # # Modify a materialized view
6
+ # #
7
+ # # @param [#to_s] name (nil) The qualified name of the view
8
+ # # @option options [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 enables to alter a view without recreating
14
+ # # its from scratch. You can rename columns, change their
15
+ # # storage settings (how the column is TOAST-ed), or customize their statistics.
16
+ # #
17
+ # # ```ruby
18
+ # # change_materialized_view "admin_users" do |v|
19
+ # # v.rename_column "name", to: "full_name"
20
+ # # v.column "name", storage: "extended", from_storage: "expanded"
21
+ # # v.column "admin", n_distinct: 2
22
+ # # v.column "role", statistics: 100
23
+ # # end
24
+ # # ```
25
+ # #
26
+ # # Notice that renaming will be done AFTER all changes even
27
+ # # though the order of declarations can be different.
28
+ # #
29
+ # # As in the snippet above, to make the change invertible,
30
+ # # you have to define a previous storage via `from_storage` option.
31
+ # # The inversion would always reset statistics (set it to 0).
32
+ # #
33
+ # # In addition to changing columns, the operation enables
34
+ # # to set a default clustering by given index:
35
+ # #
36
+ # # ```ruby
37
+ # # change_materialized_view "admin_users" do |v|
38
+ # # v.cluster_on "admin_users_by_names_idx"
39
+ # # end
40
+ # # ```
41
+ # #
42
+ # # The clustering is invertible, but its inversion does nothing,
43
+ # # keeping the clustering unchanged.
44
+ # #
45
+ # # The comment can also be changed:
46
+ # #
47
+ # # ```ruby
48
+ # # change_materialized_view "admin_users" do |v|
49
+ # # v.comment "Admin users", from: "Admin users only"
50
+ # # end
51
+ # # ```
52
+ # #
53
+ # # Notice, that without `from` option the operation is still
54
+ # # invertible, but its inversion would delete the comment.
55
+ # # It can also be reset to the blank string explicitly:
56
+ # #
57
+ # # ```ruby
58
+ # # change_materialized_view "admin_users" do |v|
59
+ # # v.comment "", from: "Admin users only"
60
+ # # end
61
+ # # ```
62
+ # #
63
+ # # With the `if_exists: true` option, the operation won't fail
64
+ # # even when the view wasn't existed. At the same time,
65
+ # # this option makes a migration irreversible due to uncertainty
66
+ # # of the previous state of the database.
67
+ # def change_materialized_view(name, **options, &block); end
21
68
  # end
22
- #
23
- # Notice that renaming will be done AFTER all changes even
24
- # though the order of declarations can be different.
25
- #
26
- # As in the snippet above, to make the change invertible,
27
- # you have to define a previous storage via `from_storage` option.
28
- # The inversion would always reset statistics (set it to 0).
29
- #
30
- # In addition to changing columns, the operation enables
31
- # to set a default clustering by given index:
32
- #
33
- # change_materialized_view "admin_users" do |v|
34
- # v.cluster_on "admin_users_by_names_idx"
35
- # end
36
- #
37
- # The clustering is invertible, but its inversion does nothing,
38
- # keeping the clustering unchanged.
39
- #
40
- # The comment can also be changed:
41
- #
42
- # change_materialized_view "admin_users" do |v|
43
- # v.comment "Admin users", from: "Admin users only"
44
- # end
45
- #
46
- # Notice, that without `from` option the operation is still
47
- # invertible, but its inversion would delete the comment.
48
- # It can also be reset to the blank string explicitly:
49
- #
50
- # change_materialized_view "admin_users" do |v|
51
- # v.comment "", from: "Admin users only"
52
- # end
53
- #
54
- # With the `if_exists: true` option, the operation won't fail
55
- # even when the view wasn't existed. At the same time,
56
- # this option makes a migration irreversible due to uncertainty
57
- # of the previous state of the database.
58
-
59
69
  module PGTrunk::Operations::MaterializedViews
60
70
  # @private
61
71
  class ChangeMaterializedView < Base