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,71 +1,74 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# @option [
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# @option [#to_s] :
|
13
|
-
# @option [
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# @option [Boolean] :
|
21
|
-
# @option [
|
22
|
-
# @option [
|
23
|
-
# @option [
|
24
|
-
# @
|
25
|
-
# @
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# SQL
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# f.
|
49
|
-
# f.
|
50
|
-
# f.
|
51
|
-
# f.
|
52
|
-
# #
|
53
|
-
# f.
|
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 [Boolean] :if_exists (false) Suppress the error when the function is absent
|
10
|
+
# # @option [Symbol] :force (:restrict) How to process dependent objects
|
11
|
+
# # Supported values: :restrict (default), :cascade
|
12
|
+
# # @option [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
|
13
|
+
# # @option [#to_s] :body (nil) The body of the function
|
14
|
+
# # @option [Symbol] :volatility (:volatile) The volatility of the function.
|
15
|
+
# # Supported values: :volatile (default), :stable, :immutable
|
16
|
+
# # @option [Symbol] :parallel (:unsafe) The safety of parallel execution.
|
17
|
+
# # Supported values: :unsafe (default), :restricted, :safe
|
18
|
+
# # @option [Symbol] :security (:invoker) Define the role under which the function is invoked
|
19
|
+
# # Supported values: :invoker (default), :definer
|
20
|
+
# # @option [Boolean] :leakproof (false) If the function is leakproof
|
21
|
+
# # @option [Boolean] :strict (false) If the function is strict
|
22
|
+
# # @option [Float] :cost (nil) The cost estimation for the function
|
23
|
+
# # @option [Integer] :rows (nil) The number of rows returned by a function
|
24
|
+
# # @option [#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
|
+
# # drop_function "multiply"
|
32
|
+
# #
|
33
|
+
# # If several overloaded functions have the name,
|
34
|
+
# # then you must specify the signature having
|
35
|
+
# # types of attributes at least:
|
36
|
+
# #
|
37
|
+
# # drop_function "multiply(int, int)"
|
38
|
+
# #
|
39
|
+
# # In both cases above the operation is irreversible. To make it
|
40
|
+
# # inverted you have to provide a full signature along with
|
41
|
+
# # the body definition. The other options are supported as well:
|
42
|
+
# #
|
43
|
+
# # drop_function "math.mult(a int, b int) int" do |f|
|
44
|
+
# # f.language "sql" # (default)
|
45
|
+
# # f.body <<~SQL
|
46
|
+
# # SELECT a * b;
|
47
|
+
# # SQL
|
48
|
+
# # f.volatility :immutable # :stable, :volatile (default)
|
49
|
+
# # f.parallel :safe # :restricted, :unsafe (default)
|
50
|
+
# # f.security :invoker # (default), also :definer
|
51
|
+
# # f.leakproof true
|
52
|
+
# # f.strict true
|
53
|
+
# # f.cost 5.0
|
54
|
+
# # # f.rows 1 (supported for functions returning sets of rows)
|
55
|
+
# # f.comment "Multiplies 2 integers"
|
56
|
+
# # end
|
57
|
+
# #
|
58
|
+
# # The operation can be called with `if_exists` option. In this case
|
59
|
+
# # it would do nothing when no function existed.
|
60
|
+
# #
|
61
|
+
# # drop_function "math.multiply(integer, integer)", if_exists: true
|
62
|
+
# #
|
63
|
+
# # Another operation-specific option `force: :cascade` enables
|
64
|
+
# # to drop silently any object depending on the function.
|
65
|
+
# #
|
66
|
+
# # drop_function "math.multiply(integer, integer)", force: :cascade
|
67
|
+
# #
|
68
|
+
# # Both options make the operation irreversible because of
|
69
|
+
# # uncertainty about the previous state of the database.
|
70
|
+
# def drop_function(name, **options, &block); end
|
54
71
|
# 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
72
|
module PGTrunk::Operations::Functions
|
70
73
|
# @private
|
71
74
|
class DropFunction < Base
|
@@ -1,27 +1,30 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
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 [#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
|
+
# # rename_function "math.multiply", to: "public.product"
|
17
|
+
# #
|
18
|
+
# # otherwise the types of attributes must be explicitly specified.
|
19
|
+
# #
|
20
|
+
# # rename_function "math.multiply(int, int)", to: "public.product"
|
21
|
+
# #
|
22
|
+
# # Any specification of attributes or returned values in `to:` option
|
23
|
+
# # is ignored because they cannot be changed anyway.
|
24
|
+
# #
|
25
|
+
# # The operation is always reversible.
|
26
|
+
# def rename_function(name, to:); end
|
27
|
+
# end
|
25
28
|
module PGTrunk::Operations::Functions
|
26
29
|
# @private
|
27
30
|
class RenameFunction < Base
|
@@ -1,61 +1,64 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @
|
9
|
-
# @
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# v.
|
20
|
-
# v.column "
|
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 [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
|
16
|
+
# # customize their statistics.
|
17
|
+
# #
|
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
|
+
# # Notice that renaming will be done AFTER all changes even
|
26
|
+
# # though the order of declarations can be different.
|
27
|
+
# #
|
28
|
+
# # As in the snippet above, to make the change invertible,
|
29
|
+
# # you have to define a previous storage via `from_storage` option.
|
30
|
+
# # The inversion would always reset statistics (set it to 0).
|
31
|
+
# #
|
32
|
+
# # In addition to changing columns, the operation enables
|
33
|
+
# # to set a default clustering by given index:
|
34
|
+
# #
|
35
|
+
# # change_materialized_view "admin_users" do |v|
|
36
|
+
# # v.cluster_on "admin_users_by_names_idx"
|
37
|
+
# # end
|
38
|
+
# #
|
39
|
+
# # The clustering is invertible, but its inversion does nothing,
|
40
|
+
# # keeping the clustering unchanged.
|
41
|
+
# #
|
42
|
+
# # The comment can also be changed:
|
43
|
+
# #
|
44
|
+
# # change_materialized_view "admin_users" do |v|
|
45
|
+
# # v.comment "Admin users", from: "Admin users only"
|
46
|
+
# # end
|
47
|
+
# #
|
48
|
+
# # Notice, that without `from` option the operation is still
|
49
|
+
# # invertible, but its inversion would delete the comment.
|
50
|
+
# # It can also be reset to the blank string explicitly:
|
51
|
+
# #
|
52
|
+
# # change_materialized_view "admin_users" do |v|
|
53
|
+
# # v.comment "", from: "Admin users only"
|
54
|
+
# # end
|
55
|
+
# #
|
56
|
+
# # With the `if_exists: true` option, the operation won't fail
|
57
|
+
# # even when the view wasn't existed. At the same time,
|
58
|
+
# # this option makes a migration irreversible due to uncertainty
|
59
|
+
# # of the previous state of the database.
|
60
|
+
# def change_materialized_view(name, **options, &block); end
|
21
61
|
# 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
62
|
module PGTrunk::Operations::MaterializedViews
|
60
63
|
# @private
|
61
64
|
class ChangeMaterializedView < Base
|
@@ -1,77 +1,80 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @option [
|
9
|
-
# @option [#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# @option [
|
13
|
-
# @option [
|
14
|
-
# @
|
15
|
-
# @
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# SQL
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# can be
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# v
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Create a materialized view
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] name (nil) The qualified name of the view
|
8
|
+
# # @option [Boolean] :if_not_exists (false) Suppress the error when a view has been already created
|
9
|
+
# # @option [#to_s] :sql_definition (nil) The snippet containing the query
|
10
|
+
# # @option [#to_i] :version (nil)
|
11
|
+
# # The alternative way to set sql_definition by referencing to a file containing the snippet
|
12
|
+
# # @option [#to_s] :tablespace (nil) The tablespace for the view
|
13
|
+
# # @option [Boolean] :with_data (true) If the view should be populated after creation
|
14
|
+
# # @option [#to_s] :comment (nil) The comment describing the view
|
15
|
+
# # @yield [v] the block with the view's definition
|
16
|
+
# # @yieldparam Object receiver of methods specifying the view
|
17
|
+
# # @return [void]
|
18
|
+
# #
|
19
|
+
# # The operation creates the view using its `sql_definition`:
|
20
|
+
# #
|
21
|
+
# # create_materialized_view("views.admin_users", sql_definition: <<~SQL)
|
22
|
+
# # SELECT id, name FROM users WHERE admin;
|
23
|
+
# # SQL
|
24
|
+
# #
|
25
|
+
# # For compatibility to the `scenic` gem, we also support
|
26
|
+
# # adding a definition via its version:
|
27
|
+
# #
|
28
|
+
# # create_materialized_view "admin_users", version: 1
|
29
|
+
# #
|
30
|
+
# # It is expected, that a `db/materialized_views/admin_users_v01.sql`
|
31
|
+
# # to contain the SQL snippet.
|
32
|
+
# #
|
33
|
+
# # The tablespace can be specified for the created view.
|
34
|
+
# # Notice that later it can't be changed (in PostgreSQL all rows
|
35
|
+
# # can be moved to another tablespace, but we don't support
|
36
|
+
# # this feature yet).
|
37
|
+
# #
|
38
|
+
# # create_materialized_view "admin_users" do |v|
|
39
|
+
# # v.tablespace "fast_ssd"
|
40
|
+
# # v.sql_definition <<~SQL
|
41
|
+
# # SELECT id, name, password, admin, on_duty
|
42
|
+
# # FROM users
|
43
|
+
# # WHERE admin
|
44
|
+
# # SQL
|
45
|
+
# # end
|
46
|
+
# #
|
47
|
+
# # You can also set a comment describing the view,
|
48
|
+
# # and redefine the storage options for some TOAST-ed columns,
|
49
|
+
# # as well as their custom statistics:
|
50
|
+
# #
|
51
|
+
# # create_materialized_view "admin_users" do |v|
|
52
|
+
# # v.sql_definition <<~SQL
|
53
|
+
# # SELECT id, name, password, admin, on_duty
|
54
|
+
# # FROM users
|
55
|
+
# # WHERE admin
|
56
|
+
# # SQL
|
57
|
+
# #
|
58
|
+
# # v.column "password", storage: "external" # to avoid compression
|
59
|
+
# # v.column "password", n_distinct: -1 # linear dependency
|
60
|
+
# # v.column "admin", n_distinct: 1 # exact number of values
|
61
|
+
# # v.column "on_duty", statistics: 2 # the total number of values
|
62
|
+
# #
|
63
|
+
# # v.comment "Admin users only"
|
64
|
+
# # end
|
65
|
+
# #
|
66
|
+
# # With the `replace_existing: true` option the operation
|
67
|
+
# # would use `CREATE OR REPLACE VIEW` command, so it
|
68
|
+
# # can be used to "update" (or reload) the existing view.
|
69
|
+
# #
|
70
|
+
# # create_materialized_view "admin_users",
|
71
|
+
# # version: 1,
|
72
|
+
# # replace_existing: true
|
73
|
+
# #
|
74
|
+
# # This option makes the migration irreversible due to uncertainty
|
75
|
+
# # of the previous state of the database.
|
76
|
+
# def create_materialized_view(name, **options, &block); end
|
43
77
|
# end
|
44
|
-
#
|
45
|
-
# You can also set a comment describing the view,
|
46
|
-
# and redefine the storage options for some TOAST-ed columns,
|
47
|
-
# as well as their custom statistics:
|
48
|
-
#
|
49
|
-
# create_materialized_view "admin_users" do |v|
|
50
|
-
# v.sql_definition <<~SQL
|
51
|
-
# SELECT id, name, password, admin, on_duty
|
52
|
-
# FROM users
|
53
|
-
# WHERE admin
|
54
|
-
# SQL
|
55
|
-
#
|
56
|
-
# v.column "password", storage: "external" # to avoid compression
|
57
|
-
# v.column "password", n_distinct: -1 # linear dependency
|
58
|
-
# v.column "admin", n_distinct: 1 # exact number of values
|
59
|
-
# v.column "on_duty", statistics: 2 # the total number of values
|
60
|
-
#
|
61
|
-
# v.comment "Admin users only"
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# With the `replace_existing: true` option the operation
|
65
|
-
# would use `CREATE OR REPLACE VIEW` command, so it
|
66
|
-
# can be used to "update" (or reload) the existing view.
|
67
|
-
#
|
68
|
-
# create_materialized_view "admin_users",
|
69
|
-
# version: 1,
|
70
|
-
# replace_existing: true
|
71
|
-
#
|
72
|
-
# This option makes the migration irreversible due to uncertainty
|
73
|
-
# of the previous state of the database.
|
74
|
-
|
75
78
|
module PGTrunk::Operations::MaterializedViews
|
76
79
|
# @private
|
77
80
|
class CreateMaterializedView < Base
|
@@ -1,52 +1,55 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
# @!
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @
|
8
|
-
# @option [
|
9
|
-
# @option [
|
10
|
-
# @option [#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# @option [
|
14
|
-
# @option [
|
15
|
-
# @
|
16
|
-
# @
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# v.
|
30
|
-
# v.
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Drop a materialized 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
|
+
# # @option [Symbol] :force (:restrict) How to process dependent objects (`:cascade` or `:restrict`)
|
10
|
+
# # @option [#to_s] :sql_definition (nil) The snippet containing the query
|
11
|
+
# # @option [#to_i] :revert_to_version (nil)
|
12
|
+
# # The alternative way to set sql_definition by referencing to a file containing the snippet
|
13
|
+
# # @option [#to_s] :tablespace (nil) The tablespace for the view
|
14
|
+
# # @option [Boolean] :with_data (true) If the view should be populated after creation
|
15
|
+
# # @option [#to_s] :comment (nil) The comment describing the view
|
16
|
+
# # @yield [v] the block with the view's definition
|
17
|
+
# # @yieldparam Object receiver of methods specifying the view
|
18
|
+
# # @return [void]
|
19
|
+
# #
|
20
|
+
# # The operation drops a materialized view identified by its
|
21
|
+
# # qualified name (it can include a schema).
|
22
|
+
# #
|
23
|
+
# # drop_materialized_view "views.admin_users"
|
24
|
+
# #
|
25
|
+
# # To make the operation invertible, use the same options
|
26
|
+
# # as in the `create_view` operation.
|
27
|
+
# #
|
28
|
+
# # drop_materialized_view "views.admin_users" do |v|
|
29
|
+
# # v.sql_definition "SELECT name, password FROM users WHERE admin;"
|
30
|
+
# # v.column "password", storage: "external" # prevent compression
|
31
|
+
# # v.with_data false
|
32
|
+
# # v.comment "Admin users only"
|
33
|
+
# # end
|
34
|
+
# #
|
35
|
+
# # You can also use a version-base SQL definition like:
|
36
|
+
# #
|
37
|
+
# # drop_materialized_view "admin_users", revert_to_version: 1
|
38
|
+
# #
|
39
|
+
# # With the `force: :cascade` option the operation would remove
|
40
|
+
# # all the objects which depend on the view.
|
41
|
+
# #
|
42
|
+
# # drop_materialized_view "admin_users", force: :cascade
|
43
|
+
# #
|
44
|
+
# # With the `if_exists: true` option the operation won't fail
|
45
|
+
# # even when the view was absent in the database.
|
46
|
+
# #
|
47
|
+
# # drop_materialized_view "admin_users", if_exists: true
|
48
|
+
# #
|
49
|
+
# # Both options make a migration irreversible due to uncertainty
|
50
|
+
# # of the previous state of the database.
|
51
|
+
# def drop_materialized_view(name, **options, &block); end
|
31
52
|
# end
|
32
|
-
#
|
33
|
-
# You can also use a version-base SQL definition like:
|
34
|
-
#
|
35
|
-
# drop_materialized_view "admin_users", revert_to_version: 1
|
36
|
-
#
|
37
|
-
# With the `force: :cascade` option the operation would remove
|
38
|
-
# all the objects which depend on the view.
|
39
|
-
#
|
40
|
-
# drop_materialized_view "admin_users", force: :cascade
|
41
|
-
#
|
42
|
-
# With the `if_exists: true` option the operation won't fail
|
43
|
-
# even when the view was absent in the database.
|
44
|
-
#
|
45
|
-
# drop_materialized_view "admin_users", if_exists: true
|
46
|
-
#
|
47
|
-
# Both options make a migration irreversible due to uncertainty
|
48
|
-
# of the previous state of the database.
|
49
|
-
|
50
53
|
module PGTrunk::Operations::MaterializedViews
|
51
54
|
# @private
|
52
55
|
class DropMaterializedView < Base
|
@@ -1,29 +1,32 @@
|
|
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
|
-
#
|
21
|
-
#
|
22
|
-
# the
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
|
3
|
+
# @!parse
|
4
|
+
# class ActiveRecord::Migration
|
5
|
+
# # Refresh a materialized view
|
6
|
+
# #
|
7
|
+
# # @param [#to_s] name (nil) The qualified name of the view
|
8
|
+
# # @option [Boolean] :with_data (true) If the view should be populated after creation
|
9
|
+
# # @option [Symbol] :algorithm (nil) Makes the operation concurrent when set to :concurrently
|
10
|
+
# # @return [void]
|
11
|
+
# #
|
12
|
+
# # The operation enables refreshing a materialized view
|
13
|
+
# # by reloading its underlying SQL query:
|
14
|
+
# #
|
15
|
+
# # refresh_materialized_view "admin_users"
|
16
|
+
# #
|
17
|
+
# # The option `algorithm: :concurrently` acts exactly
|
18
|
+
# # like in the `create_index` definition. You should
|
19
|
+
# # possibly add the `disable_ddl_transaction!` command
|
20
|
+
# # to the migration as well.
|
21
|
+
# #
|
22
|
+
# # With option `with_data: false` the command won't
|
23
|
+
# # update the data. This option can't be used along with
|
24
|
+
# # the `:algorithm`.
|
25
|
+
# #
|
26
|
+
# # The operation is always reversible, though its
|
27
|
+
# # inversion does nothing.
|
28
|
+
# def refresh_materialized_view(name, **options); end
|
29
|
+
# end
|
27
30
|
module PGTrunk::Operations::MaterializedViews
|
28
31
|
# @private
|
29
32
|
class RefreshMaterializedView < Base
|