pg_trunk 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/README.md +1 -1
  4. data/lib/pg_trunk/core/railtie/custom_types.rb +5 -6
  5. data/lib/pg_trunk/operations/check_constraints/add_check_constraint.rb +18 -12
  6. data/lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb +18 -10
  7. data/lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb +12 -6
  8. data/lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb +6 -2
  9. data/lib/pg_trunk/operations/composite_types/change_composite_type.rb +24 -18
  10. data/lib/pg_trunk/operations/composite_types/create_composite_type.rb +10 -9
  11. data/lib/pg_trunk/operations/composite_types/drop_composite_type.rb +25 -23
  12. data/lib/pg_trunk/operations/composite_types/rename_composite_type.rb +3 -3
  13. data/lib/pg_trunk/operations/domains/change_domain.rb +27 -24
  14. data/lib/pg_trunk/operations/domains/create_domain.rb +11 -11
  15. data/lib/pg_trunk/operations/domains/drop_domain.rb +19 -13
  16. data/lib/pg_trunk/operations/domains/rename_domain.rb +3 -1
  17. data/lib/pg_trunk/operations/enums/change_enum.rb +13 -11
  18. data/lib/pg_trunk/operations/enums/create_enum.rb +9 -9
  19. data/lib/pg_trunk/operations/enums/drop_enum.rb +18 -10
  20. data/lib/pg_trunk/operations/enums/rename_enum.rb +3 -1
  21. data/lib/pg_trunk/operations/foreign_keys/add_foreign_key.rb +23 -17
  22. data/lib/pg_trunk/operations/foreign_keys/drop_foreign_key.rb +17 -11
  23. data/lib/pg_trunk/operations/foreign_keys/rename_foreign_key.rb +11 -5
  24. data/lib/pg_trunk/operations/functions/change_function.rb +24 -21
  25. data/lib/pg_trunk/operations/functions/create_function.rb +34 -26
  26. data/lib/pg_trunk/operations/functions/drop_function.rb +28 -18
  27. data/lib/pg_trunk/operations/functions/rename_function.rb +6 -2
  28. data/lib/pg_trunk/operations/materialized_views/change_materialized_view.rb +24 -17
  29. data/lib/pg_trunk/operations/materialized_views/create_materialized_view.rb +37 -29
  30. data/lib/pg_trunk/operations/materialized_views/drop_materialized_view.rb +20 -10
  31. data/lib/pg_trunk/operations/materialized_views/refresh_materialized_view.rb +3 -1
  32. data/lib/pg_trunk/operations/materialized_views/rename_materialized_view.rb +8 -4
  33. data/lib/pg_trunk/operations/procedures/change_procedure.rb +22 -18
  34. data/lib/pg_trunk/operations/procedures/create_procedure.rb +26 -18
  35. data/lib/pg_trunk/operations/procedures/drop_procedure.rb +18 -10
  36. data/lib/pg_trunk/operations/procedures/rename_procedure.rb +6 -2
  37. data/lib/pg_trunk/operations/statistics/create_statistics.rb +32 -24
  38. data/lib/pg_trunk/operations/statistics/drop_statistics.rb +26 -18
  39. data/lib/pg_trunk/operations/statistics/rename_statistics.rb +3 -1
  40. data/lib/pg_trunk/operations/triggers/change_trigger.rb +9 -7
  41. data/lib/pg_trunk/operations/triggers/create_trigger.rb +26 -20
  42. data/lib/pg_trunk/operations/triggers/drop_trigger.rb +16 -10
  43. data/lib/pg_trunk/operations/views/change_view.rb +20 -14
  44. data/lib/pg_trunk/operations/views/create_view.rb +18 -10
  45. data/lib/pg_trunk/operations/views/drop_view.rb +19 -9
  46. data/lib/pg_trunk/operations/views/rename_view.rb +6 -2
  47. data/lib/pg_trunk/version.rb +1 -1
  48. metadata +1 -1
@@ -12,14 +12,18 @@
12
12
  # # A materialized view can be renamed by changing both the name
13
13
  # # and the schema (namespace) it belongs to.
14
14
  # #
15
- # # rename_materialized_view "views.admin_users", to: "admins"
15
+ # # ```ruby
16
+ # # rename_materialized_view "views.admin_users", to: "admins"
17
+ # # ```
16
18
  # #
17
19
  # # With the `if_exists: true` option, the operation won't fail
18
20
  # # even when the view wasn't existed.
19
21
  # #
20
- # # rename_materialized_view "admin_users",
21
- # # to: "admins",
22
- # # if_exists: true
22
+ # # ```ruby
23
+ # # rename_materialized_view "admin_users",
24
+ # # to: "admins",
25
+ # # if_exists: true
26
+ # # ```
23
27
  # #
24
28
  # # At the same time, the option makes a migration irreversible
25
29
  # # due to uncertainty of the previous state of the database.
@@ -17,31 +17,35 @@
17
17
  # # You can change any property except for the name
18
18
  # # (use `rename_function` instead) and `language`.
19
19
  # #
20
- # # change_procedure "metadata.set_foo(a int)" do |p|
21
- # # p.body <<~SQL
22
- # # SET foo = a
23
- # # SQL
24
- # # p.security :invoker
25
- # # p.comment "Multiplies 2 integers"
20
+ # # ```ruby
21
+ # # change_procedure "metadata.set_foo(a int)" do |p|
22
+ # # p.body <<~SQL
23
+ # # SET foo = a
26
24
  # # SQL
25
+ # # p.security :invoker
26
+ # # p.comment "Multiplies 2 integers"
27
+ # # SQL
28
+ # # ```
27
29
  # #
28
30
  # # The example above is not invertible because of uncertainty
29
31
  # # about the previous state of body and comment.
30
32
  # # To define them, use a from options (available in a block syntax only):
31
33
  # #
32
- # # change_procedure "metadata.set_foo(a int)" do |p|
33
- # # p.body <<~SQL, from: <<~SQL
34
- # # SET foo = a
35
- # # SQL
36
- # # SET foo = -a
37
- # # SQL
38
- # # p.comment <<~MSG, from: <<~MSG
39
- # # Multiplies 2 integers
40
- # # MSG
41
- # # Multiplies ints
42
- # # MSG
43
- # # p.security :invoker
34
+ # # ```ruby
35
+ # # change_procedure "metadata.set_foo(a int)" do |p|
36
+ # # p.body <<~SQL, from: <<~SQL
37
+ # # SET foo = a
44
38
  # # SQL
39
+ # # SET foo = -a
40
+ # # SQL
41
+ # # p.comment <<~MSG, from: <<~MSG
42
+ # # Multiplies 2 integers
43
+ # # MSG
44
+ # # Multiplies ints
45
+ # # MSG
46
+ # # p.security :invoker
47
+ # # SQL
48
+ # # ```
45
49
  # #
46
50
  # # Like in the other operations, the procedure can be
47
51
  # # identified by a qualified name (with types of arguments).
@@ -23,37 +23,45 @@
23
23
  # #
24
24
  # # The procedure can be created either using inline syntax
25
25
  # #
26
- # # create_procedure "metadata.set_foo(a int)",
27
- # # language: :sql,
28
- # # body: "SET foo = a",
29
- # # comment: "Sets foo value"
26
+ # # ```ruby
27
+ # # create_procedure "metadata.set_foo(a int)",
28
+ # # language: :sql,
29
+ # # body: "SET foo = a",
30
+ # # comment: "Sets foo value"
31
+ # # ```
30
32
  # #
31
33
  # # or using a block:
32
34
  # #
33
- # # create_procedure "metadata.set_foo(a int)" do |p|
34
- # # p.language "sql" # (default)
35
- # # p.body <<~SQL
36
- # # SET foo = a
37
- # # SQL
38
- # # p.security :invoker # (default), also :definer
39
- # # p.comment "Multiplies 2 integers"
35
+ # # ```ruby
36
+ # # create_procedure "metadata.set_foo(a int)" do |p|
37
+ # # p.language "sql" # (default)
38
+ # # p.body <<~SQL
39
+ # # SET foo = a
40
40
  # # SQL
41
+ # # p.security :invoker # (default), also :definer
42
+ # # p.comment "Multiplies 2 integers"
43
+ # # SQL
44
+ # # ```
41
45
  # #
42
46
  # # With a `replace_existing: true` option,
43
47
  # # it will be created using the `CREATE OR REPLACE` clause.
44
48
  # # In this case the migration is irreversible because we
45
49
  # # don't know if and how to restore its previous definition.
46
50
  # #
47
- # # create_procedure "set_foo(a int)",
48
- # # body: "SET foo = a",
49
- # # replace_existing: true
51
+ # # ```ruby
52
+ # # create_procedure "set_foo(a int)",
53
+ # # body: "SET foo = a",
54
+ # # replace_existing: true
55
+ # # ```
50
56
  # #
51
57
  # # A procedure without arguments is supported as well
52
58
  # #
53
- # # # the same as "do_something()"
54
- # # create_procedure "do_something" do |p|
55
- # # # ...
56
- # # end
59
+ # # ```ruby
60
+ # # # the same as "do_something()"
61
+ # # create_procedure "do_something" do |p|
62
+ # # # ...
63
+ # # end
64
+ # # ```
57
65
  # def create_procedure(name, **options, &block); end
58
66
  # end
59
67
  module PGTrunk::Operations::Procedures
@@ -18,31 +18,39 @@
18
18
  # #
19
19
  # # A procedure can be dropped by a plain name:
20
20
  # #
21
- # # drop_procedure "set_foo"
21
+ # # ```ruby
22
+ # # drop_procedure "set_foo"
23
+ # # ```
22
24
  # #
23
25
  # # If several overloaded procedures have the name,
24
26
  # # then you must specify the signature having
25
27
  # # types of attributes at least:
26
28
  # #
27
- # # drop_procedure "set_foo(int)"
29
+ # # ```ruby
30
+ # # drop_procedure "set_foo(int)"
31
+ # # ```
28
32
  # #
29
33
  # # In both cases above the operation is irreversible. To make it
30
34
  # # inverted you have to provide a full signature along with
31
35
  # # the body definition. The other options are supported as well:
32
36
  # #
33
- # # drop_procedure "metadata.set_foo(a int)" do |p|
34
- # # p.language "sql" # (default)
35
- # # p.body <<~SQL
36
- # # SET foo = a
37
- # # SQL
38
- # # p.security :invoker # (default), also :definer
39
- # # p.comment "Multiplies 2 integers"
37
+ # # ```ruby
38
+ # # drop_procedure "metadata.set_foo(a int)" do |p|
39
+ # # p.language "sql" # (default)
40
+ # # p.body <<~SQL
41
+ # # SET foo = a
40
42
  # # SQL
43
+ # # p.security :invoker # (default), also :definer
44
+ # # p.comment "Multiplies 2 integers"
45
+ # # SQL
46
+ # # ```
41
47
  # #
42
48
  # # The operation can be called with `if_exists` option. In this case
43
49
  # # it would do nothing when no procedure existed.
44
50
  # #
45
- # # drop_procedure "metadata.set_foo(a int)", if_exists: true
51
+ # # ```ruby
52
+ # # drop_procedure "metadata.set_foo(a int)", if_exists: true
53
+ # # ```
46
54
  # #
47
55
  # # Notice, that this option make the operation irreversible because of
48
56
  # # uncertainty about the previous state of the database.
@@ -13,11 +13,15 @@
13
13
  # #
14
14
  # # If there are no overloaded procedures, then you can use a plain name:
15
15
  # #
16
- # # rename_procedure "math.set_foo", to: "public.foo_setup"
16
+ # # ```ruby
17
+ # # rename_procedure "math.set_foo", to: "public.foo_setup"
18
+ # # ```
17
19
  # #
18
20
  # # otherwise the types of attributes must be explicitly specified.
19
21
  # #
20
- # # rename_procedure "math.set_foo(int)", to: "public.foo_setup"
22
+ # # ```ruby
23
+ # # rename_procedure "math.set_foo(int)", to: "public.foo_setup"
24
+ # # ```
21
25
  # #
22
26
  # # Any specification of attributes in `to:` option
23
27
  # # is ignored because they cannot be changed anyway.
@@ -19,40 +19,48 @@
19
19
  # #
20
20
  # # The statistics can be created with explicit name:
21
21
  # #
22
- # # create_statistics "users_stats" do |s|
23
- # # s.table "users"
24
- # # s.columns "family", "name"
25
- # # s.kinds :dependencies, :mcv, :ndistinct
26
- # # s.comment "Statistics for users' names and families"
27
- # # SQL
22
+ # # ```ruby
23
+ # # create_statistics "users_stats" do |s|
24
+ # # s.table "users"
25
+ # # s.columns "family", "name"
26
+ # # s.kinds :dependencies, :mcv, :ndistinct
27
+ # # s.comment "Statistics for users' names and families"
28
+ # # SQL
29
+ # # ```
28
30
  # #
29
31
  # # The name can be generated as well:
30
32
  # #
31
- # # create_statistics do |s|
32
- # # s.table "users"
33
- # # s.columns "family", "name"
34
- # # s.kinds :dependencies, :mcv, :ndistinct
35
- # # s.comment "Statistics for users' names and families"
36
- # # SQL
33
+ # # ```ruby
34
+ # # create_statistics do |s|
35
+ # # s.table "users"
36
+ # # s.columns "family", "name"
37
+ # # s.kinds :dependencies, :mcv, :ndistinct
38
+ # # s.comment "Statistics for users' names and families"
39
+ # # SQL
40
+ # # ```
37
41
  # #
38
42
  # # Since v14 PostgreSQL have supported expressions in addition to columns:
39
43
  # #
40
- # # create_statistics "users_stats" do |s|
41
- # # s.table "users"
42
- # # s.columns "family"
43
- # # s.expression "length(name)"
44
- # # s.kinds :dependencies, :mcv, :ndistinct
45
- # # s.comment "Statistics for users' name lengths and families"
46
- # # SQL
44
+ # # ```ruby
45
+ # # create_statistics "users_stats" do |s|
46
+ # # s.table "users"
47
+ # # s.columns "family"
48
+ # # s.expression "length(name)"
49
+ # # s.kinds :dependencies, :mcv, :ndistinct
50
+ # # s.comment "Statistics for users' name lengths and families"
51
+ # # SQL
52
+ # # ```
47
53
  # #
48
54
  # # as well as statistics for the sole expression (kinds must be blank)
49
55
  # # by columns of some table.
50
56
  # #
51
- # # create_statistics "users_stats" do |s|
52
- # # s.table "users"
53
- # # s.expression "length(name || ' ' || family)"
54
- # # s.comment "Statistics for full name lengths"
55
- # # SQL
57
+ # # ```ruby
58
+ # # create_statistics "users_stats" do |s|
59
+ # # s.table "users"
60
+ # # s.expression "length(name || ' ' || family)"
61
+ # # s.comment "Statistics for full name lengths"
62
+ # # SQL
63
+ # # ```
56
64
  # #
57
65
  # # Use `if_not_exists: true` to suppress error in case the statistics
58
66
  # # has already been created. This option, though, makes the migration
@@ -19,38 +19,46 @@
19
19
  # #
20
20
  # # A statistics can be dropped by its name only:
21
21
  # #
22
- # # drop_statistics "my_stats"
22
+ # # ```ruby
23
+ # # drop_statistics "my_stats"
24
+ # # ```
23
25
  # #
24
26
  # # Such operation is irreversible. To make it inverted
25
27
  # # you have to provide a full definition:
26
28
  # #
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"
29
+ # # ```ruby
30
+ # # drop_statistics "users_stat" do |s|
31
+ # # s.table "users"
32
+ # # s.columns "firstname", "name"
33
+ # # s.expression <<~SQL
34
+ # # round(age, 10)
35
35
  # # SQL
36
+ # # s.kinds :dependency, :mcv, :ndistinct
37
+ # # s.comment "Statistics for name, firstname, and rough age"
38
+ # # SQL
39
+ # # ```
36
40
  # #
37
41
  # # If the statistics was anonymous (used the generated name),
38
42
  # # it can be dropped without defining the name as well:
39
43
  # #
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"
44
+ # # ```ruby
45
+ # # drop_statistics do |s|
46
+ # # s.table "users"
47
+ # # s.columns "firstname", "name"
48
+ # # s.expression <<~SQL
49
+ # # round(age, 10)
48
50
  # # SQL
51
+ # # s.kinds :dependency, :mcv, :ndistinct
52
+ # # s.comment "Statistics for name, firstname, and rough age"
53
+ # # SQL
54
+ # # ```
49
55
  # #
50
56
  # # The operation can be called with `if_exists` option. In this case
51
57
  # # it would do nothing when no statistics existed.
52
58
  # #
53
- # # drop_procedure "unknown_statistics", if_exists: true
59
+ # # ```ruby
60
+ # # drop_statistics "unknown_statistics", if_exists: true
61
+ # # ```
54
62
  # #
55
63
  # # Notice, that this option make the operation irreversible because of
56
64
  # # uncertainty about the previous state of the database.
@@ -11,7 +11,9 @@
11
11
  # # A custom statistics can be renamed by changing both the name
12
12
  # # and the schema (namespace) it belongs to.
13
13
  # #
14
- # # rename_statistics "math.my_stat", to: "public.my_stats"
14
+ # # ```ruby
15
+ # # rename_statistics "math.my_stat", to: "public.my_stats"
16
+ # # ```
15
17
  # #
16
18
  # # The operation is always reversible.
17
19
  # def rename_statistics(name, to:); end
@@ -13,13 +13,15 @@
13
13
  # #
14
14
  # # The trigger can be changed using `CREATE OR REPLACE TRIGGER` command:
15
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
16
+ # # ```ruby
17
+ # # change_trigger "users", "do_something" do |t|
18
+ # # t.function "do_something()", from: "do_something_different()"
19
+ # # t.for_each :row # from: :statement
20
+ # # t.type :after, from: :before
21
+ # # t.events %i[insert update], from: %i[insert]
22
+ # # t.comment "Does something useful", from: ""
23
+ # # end
24
+ # # ```
23
25
  # def create_trigger(table, name = nil, **options, &block); end
24
26
  # end
25
27
  module PGTrunk::Operations::Triggers
@@ -25,34 +25,40 @@
25
25
  # #
26
26
  # # The trigger can be created either using inline syntax
27
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"
28
+ # # ```ruby
29
+ # # create_trigger "users", "do_something",
30
+ # # function: "do_something()",
31
+ # # for_each: :row,
32
+ # # type: :after,
33
+ # # events: %i[insert update],
34
+ # # comment: "Does something useful"
35
+ # # ```
34
36
  # #
35
37
  # # or using a block:
36
38
  # #
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
39
+ # # ```ruby
40
+ # # create_trigger do |t|
41
+ # # t.table "users"
42
+ # # t.name "do_something"
43
+ # # t.function "do_something()"
44
+ # # t.for_each :row
45
+ # # t.type :after
46
+ # # t.events %i[insert update]
47
+ # # t.comment "Does something useful"
48
+ # # end
49
+ # # ```
46
50
  # #
47
51
  # # With a `replace_existing: true` option,
48
52
  # # it will be created using the `CREATE OR REPLACE` clause.
49
53
  # # (Available in PostgreSQL v14+).
50
54
  # #
51
- # # create_trigger "users", "do_something",
52
- # # function: "do_something()",
53
- # # type: :after,
54
- # # events: %i[insert update],
55
- # # replace_previous: true
55
+ # # ```ruby
56
+ # # create_trigger "users", "do_something",
57
+ # # function: "do_something()",
58
+ # # type: :after,
59
+ # # events: %i[insert update],
60
+ # # replace_previous: true
61
+ # # ```
56
62
  # #
57
63
  # # In this case the migration is irreversible because we
58
64
  # # don't know if and how to restore its previous definition.
@@ -25,18 +25,22 @@
25
25
  # #
26
26
  # # A trigger can be dropped by a table and name:
27
27
  # #
28
- # # drop_trigger "users", "do_something"
28
+ # # ```ruby
29
+ # # drop_trigger "users", "do_something"
30
+ # # ```
29
31
  # #
30
32
  # # the default name can be restored from its attributes as well.
31
33
  # #
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
34
+ # # ```ruby
35
+ # # drop_trigger "users" do |t|
36
+ # # t.function "send_notifications()"
37
+ # # t.for_each :row
38
+ # # t.type :after
39
+ # # t.events %i[update]
40
+ # # t.columns %w[email phone]
41
+ # # t.comment "Does something"
42
+ # # end
43
+ # # ```
40
44
  # #
41
45
  # # Notice, that you have to specify all attributes to make
42
46
  # # the operation reversible.
@@ -44,7 +48,9 @@
44
48
  # # The operation can be called with `if_exists` option. In this case
45
49
  # # it would do nothing when no trigger existed.
46
50
  # #
47
- # # drop_trigger "users", "unknown_trigger", if_exists: true
51
+ # # ```ruby
52
+ # # drop_trigger "users", "unknown_trigger", if_exists: true
53
+ # # ```
48
54
  # #
49
55
  # # This option, though, makes the operation irreversible because of
50
56
  # # uncertainty of the previous state of the database.
@@ -12,20 +12,24 @@
12
12
  # #
13
13
  # # The operation replaces the view with a new definition(s):
14
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
15
+ # # ```ruby
16
+ # # change_view "admin_users" do |v|
17
+ # # v.sql_definition: <<~SQL, from: <<~SQL
18
+ # # SELECT id, name FROM users WHERE admin;
19
+ # # SQL
20
+ # # SELECT * FROM users WHERE admin;
21
+ # # SQL
22
+ # # end
23
+ # # ```
22
24
  # #
23
25
  # # For some compatibility to the `scenic` gem, we also support
24
26
  # # adding a definition via its version:
25
27
  # #
26
- # # change_view "admin_users" do |v|
27
- # # v.version 2, from: 1
28
- # # end
28
+ # # ```ruby
29
+ # # change_view "admin_users" do |v|
30
+ # # v.version 2, from: 1
31
+ # # end
32
+ # # ```
29
33
  # #
30
34
  # # It is expected, that both `db/views/admin_users_v01.sql`
31
35
  # # and `db/views/admin_users_v02.sql` to contain SQL snippets.
@@ -36,10 +40,12 @@
36
40
  # # You can also (re)set a comment describing the view,
37
41
  # # and the check option (either `:local` or `:cascaded`):
38
42
  # #
39
- # # change_view "admin_users" do |v|
40
- # # v.check :local, from: :cascaded
41
- # # v.comment "Admin users only", from: ""
42
- # # end
43
+ # # ```ruby
44
+ # # change_view "admin_users" do |v|
45
+ # # v.check :local, from: :cascaded
46
+ # # v.comment "Admin users only", from: ""
47
+ # # end
48
+ # # ```
43
49
  # def change_view(name, **options, &block); end
44
50
  # end
45
51
  module PGTrunk::Operations::Views
@@ -18,14 +18,18 @@
18
18
  # #
19
19
  # # The operation creates the view using its `sql_definition`:
20
20
  # #
21
- # # create_view("views.admin_users", sql_definition: <<~SQL)
22
- # # SELECT id, name FROM users WHERE admin;
23
- # # SQL
21
+ # # ```ruby
22
+ # # create_view("views.admin_users", sql_definition: <<~SQL)
23
+ # # SELECT id, name FROM users WHERE admin;
24
+ # # SQL
25
+ # # ```
24
26
  # #
25
27
  # # For compatibility to the `scenic` gem, we also support
26
28
  # # adding a definition via its version:
27
29
  # #
28
- # # create_view "admin_users", version: 1
30
+ # # ```ruby
31
+ # # create_view "admin_users", version: 1
32
+ # # ```
29
33
  # #
30
34
  # # It is expected, that a `db/views/admin_users_v01.sql`
31
35
  # # to contain the SQL snippet.
@@ -33,17 +37,21 @@
33
37
  # # You can also set a comment describing the view, and the check option
34
38
  # # (either `:local` or `:cascaded`):
35
39
  # #
36
- # # create_view "admin_users" do |v|
37
- # # v.sql_definition "SELECT id, name FROM users WHERE admin;"
38
- # # v.check :local
39
- # # v.comment "Admin users only"
40
- # # end
40
+ # # ```ruby
41
+ # # create_view "admin_users" do |v|
42
+ # # v.sql_definition "SELECT id, name FROM users WHERE admin;"
43
+ # # v.check :local
44
+ # # v.comment "Admin users only"
45
+ # # end
46
+ # # ```
41
47
  # #
42
48
  # # With the `replace_existing: true` option the operation
43
49
  # # would use `CREATE OR REPLACE VIEW` command, so it
44
50
  # # can be used to "update" (or reload) the existing view.
45
51
  # #
46
- # # create_view "admin_users", version: 1, replace_existing: true
52
+ # # ```ruby
53
+ # # create_view "admin_users", version: 1, replace_existing: true
54
+ # # ```
47
55
  # #
48
56
  # # This option makes an operation irreversible due to uncertainty
49
57
  # # of the previous state of the database.
@@ -21,30 +21,40 @@
21
21
  # # The operation drops the existing view identified by its
22
22
  # # qualified name (it can include a schema).
23
23
  # #
24
- # # drop_view "views.admin_users"
24
+ # # ```ruby
25
+ # # drop_view "views.admin_users"
26
+ # # ```
25
27
  # #
26
28
  # # To make the operation invertible, use the same options
27
29
  # # as in the `create_view` operation.
28
30
  # #
29
- # # drop_view "views.admin_users" do |v|
30
- # # v.sql_definition "SELECT name, email FROM users WHERE admin;"
31
- # # v.check :local
32
- # # v.comment "Admin users only"
33
- # # end
31
+ # # ```ruby
32
+ # # drop_view "views.admin_users" do |v|
33
+ # # v.sql_definition "SELECT name, email FROM users WHERE admin;"
34
+ # # v.check :local
35
+ # # v.comment "Admin users only"
36
+ # # end
37
+ # # ```
34
38
  # #
35
39
  # # You can also use a version-base SQL definition like:
36
40
  # #
37
- # # drop_view "views.admin_users", revert_to_version: 1
41
+ # # ```ruby
42
+ # # drop_view "views.admin_users", revert_to_version: 1
43
+ # # ```
38
44
  # #
39
45
  # # With the `force: :cascade` option the operation would remove
40
46
  # # all the objects which depend on the view.
41
47
  # #
42
- # # drop_view "views.admin_users", force: :cascade
48
+ # # ```ruby
49
+ # # drop_view "views.admin_users", force: :cascade
50
+ # # ```
43
51
  # #
44
52
  # # With the `if_exists: true` option the operation won't fail
45
53
  # # even when the view was absent in the database.
46
54
  # #
47
- # # drop_view "views.admin_users", if_exists: true
55
+ # # ```ruby
56
+ # # drop_view "views.admin_users", if_exists: true
57
+ # # ```
48
58
  # #
49
59
  # # Both options make an operation irreversible due to uncertainty
50
60
  # # of the previous state of the database.