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,27 +1,30 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
            #  
     | 
| 
       23 
     | 
    
         
            -
            # 
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # @!parse
         
     | 
| 
      
 4 
     | 
    
         
            +
            #   class ActiveRecord::Migration
         
     | 
| 
      
 5 
     | 
    
         
            +
            #     # Change the name and/or schema of a materialized view
         
     | 
| 
      
 6 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #     # @param [#to_s] :name (nil) The qualified name of the view
         
     | 
| 
      
 8 
     | 
    
         
            +
            #     # @option [#to_s] :to (nil) The new qualified name for the view
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     # @option [Boolean] :if_exists (false) Suppress the error when the view is absent
         
     | 
| 
      
 10 
     | 
    
         
            +
            #     # @return [void]
         
     | 
| 
      
 11 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 12 
     | 
    
         
            +
            #     # A materialized view can be renamed by changing both the name
         
     | 
| 
      
 13 
     | 
    
         
            +
            #     # and the schema (namespace) it belongs to.
         
     | 
| 
      
 14 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 15 
     | 
    
         
            +
            #     #   rename_materialized_view "views.admin_users", to: "admins"
         
     | 
| 
      
 16 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 17 
     | 
    
         
            +
            #     # With the `if_exists: true` option, the operation won't fail
         
     | 
| 
      
 18 
     | 
    
         
            +
            #     # even when the view wasn't existed.
         
     | 
| 
      
 19 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 20 
     | 
    
         
            +
            #     #   rename_materialized_view "admin_users",
         
     | 
| 
      
 21 
     | 
    
         
            +
            #     #                            to: "admins",
         
     | 
| 
      
 22 
     | 
    
         
            +
            #     #                            if_exists: true
         
     | 
| 
      
 23 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 24 
     | 
    
         
            +
            #     # At the same time, the option makes a migration irreversible
         
     | 
| 
      
 25 
     | 
    
         
            +
            #     # due to uncertainty of the previous state of the database.
         
     | 
| 
      
 26 
     | 
    
         
            +
            #     def rename_materialized_view(name, **options); end
         
     | 
| 
      
 27 
     | 
    
         
            +
            #   end
         
     | 
| 
       25 
28 
     | 
    
         
             
            module PGTrunk::Operations::MaterializedViews
         
     | 
| 
       26 
29 
     | 
    
         
             
              # @private
         
     | 
| 
       27 
30 
     | 
    
         
             
              class RenameMaterializedView < Base
         
     | 
| 
         @@ -1,51 +1,54 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
            #     SQL
         
     | 
| 
       22 
     | 
    
         
            -
            #      
     | 
| 
       23 
     | 
    
         
            -
            #      
     | 
| 
       24 
     | 
    
         
            -
            # 
     | 
| 
       25 
     | 
    
         
            -
            #
         
     | 
| 
       26 
     | 
    
         
            -
            # 
     | 
| 
       27 
     | 
    
         
            -
            # 
     | 
| 
       28 
     | 
    
         
            -
            #  
     | 
| 
       29 
     | 
    
         
            -
            #
         
     | 
| 
       30 
     | 
    
         
            -
            # 
     | 
| 
       31 
     | 
    
         
            -
            #      
     | 
| 
       32 
     | 
    
         
            -
            # 
     | 
| 
       33 
     | 
    
         
            -
            #     SQL
         
     | 
| 
       34 
     | 
    
         
            -
            #       SET foo =  
     | 
| 
       35 
     | 
    
         
            -
            #     SQL
         
     | 
| 
       36 
     | 
    
         
            -
            #      
     | 
| 
       37 
     | 
    
         
            -
            # 
     | 
| 
       38 
     | 
    
         
            -
            #     MSG
         
     | 
| 
       39 
     | 
    
         
            -
            #       Multiplies  
     | 
| 
       40 
     | 
    
         
            -
            #     MSG
         
     | 
| 
       41 
     | 
    
         
            -
            #      
     | 
| 
       42 
     | 
    
         
            -
            # 
     | 
| 
       43 
     | 
    
         
            -
            #
         
     | 
| 
       44 
     | 
    
         
            -
            # 
     | 
| 
       45 
     | 
    
         
            -
            # 
     | 
| 
       46 
     | 
    
         
            -
            #  
     | 
| 
       47 
     | 
    
         
            -
            #  
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # @!parse
         
     | 
| 
      
 4 
     | 
    
         
            +
            #   class ActiveRecord::Migration
         
     | 
| 
      
 5 
     | 
    
         
            +
            #     # Modify a procedure
         
     | 
| 
      
 6 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #     # @param [#to_s] name (nil) The qualified name of the procedure
         
     | 
| 
      
 8 
     | 
    
         
            +
            #     # @option [Boolean] :if_exists (false) Suppress the error when the procedure is absent
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     # @yield [p] the block with the procedure's definition
         
     | 
| 
      
 10 
     | 
    
         
            +
            #     # @yieldparam Object receiver of methods specifying the procedure
         
     | 
| 
      
 11 
     | 
    
         
            +
            #     # @return [void]
         
     | 
| 
      
 12 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 13 
     | 
    
         
            +
            #     # The operation changes the procedure without dropping it
         
     | 
| 
      
 14 
     | 
    
         
            +
            #     # (which is useful when there are other objects
         
     | 
| 
      
 15 
     | 
    
         
            +
            #     # using the function and you don't want to change them all).
         
     | 
| 
      
 16 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 17 
     | 
    
         
            +
            #     # You can change any property except for the name
         
     | 
| 
      
 18 
     | 
    
         
            +
            #     # (use `rename_function` instead) and `language`.
         
     | 
| 
      
 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"
         
     | 
| 
      
 26 
     | 
    
         
            +
            #     #   SQL
         
     | 
| 
      
 27 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 28 
     | 
    
         
            +
            #     # The example above is not invertible because of uncertainty
         
     | 
| 
      
 29 
     | 
    
         
            +
            #     # about the previous state of body and comment.
         
     | 
| 
      
 30 
     | 
    
         
            +
            #     # To define them, use a from options (available in a block syntax only):
         
     | 
| 
      
 31 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 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
         
     | 
| 
      
 44 
     | 
    
         
            +
            #     #   SQL
         
     | 
| 
      
 45 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 46 
     | 
    
         
            +
            #     # Like in the other operations, the procedure can be
         
     | 
| 
      
 47 
     | 
    
         
            +
            #     # identified by a qualified name (with types of arguments).
         
     | 
| 
      
 48 
     | 
    
         
            +
            #     # If it has no overloaded implementations,
         
     | 
| 
      
 49 
     | 
    
         
            +
            #     # the plain name is supported as well.
         
     | 
| 
      
 50 
     | 
    
         
            +
            #     def change_procedure(name, **options, &block); end
         
     | 
| 
      
 51 
     | 
    
         
            +
            #   end
         
     | 
| 
       49 
52 
     | 
    
         
             
            module PGTrunk::Operations::Procedures
         
     | 
| 
       50 
53 
     | 
    
         
             
              # @private
         
     | 
| 
       51 
54 
     | 
    
         
             
              class ChangeProcedure < Base
         
     | 
| 
         @@ -1,58 +1,61 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: false
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            # @! 
     | 
| 
       4 
     | 
    
         
            -
            #  
     | 
| 
       5 
     | 
    
         
            -
            #
         
     | 
| 
       6 
     | 
    
         
            -
            # 
     | 
| 
       7 
     | 
    
         
            -
            # 
     | 
| 
       8 
     | 
    
         
            -
            #  
     | 
| 
       9 
     | 
    
         
            -
            # @option [ 
     | 
| 
       10 
     | 
    
         
            -
            # @option [#to_s] : 
     | 
| 
       11 
     | 
    
         
            -
            # @option [ 
     | 
| 
       12 
     | 
    
         
            -
            # 
     | 
| 
       13 
     | 
    
         
            -
            # 
     | 
| 
       14 
     | 
    
         
            -
            # @ 
     | 
| 
       15 
     | 
    
         
            -
            # @ 
     | 
| 
       16 
     | 
    
         
            -
            #
         
     | 
| 
       17 
     | 
    
         
            -
            #  
     | 
| 
       18 
     | 
    
         
            -
            # 
     | 
| 
       19 
     | 
    
         
            -
            #  
     | 
| 
       20 
     | 
    
         
            -
            #  
     | 
| 
       21 
     | 
    
         
            -
            #
         
     | 
| 
       22 
     | 
    
         
            -
            #  
     | 
| 
       23 
     | 
    
         
            -
            #
         
     | 
| 
       24 
     | 
    
         
            -
            # 
     | 
| 
       25 
     | 
    
         
            -
            # 
     | 
| 
       26 
     | 
    
         
            -
            # 
     | 
| 
       27 
     | 
    
         
            -
            #                     
     | 
| 
       28 
     | 
    
         
            -
            #
         
     | 
| 
       29 
     | 
    
         
            -
            #  
     | 
| 
       30 
     | 
    
         
            -
            #
         
     | 
| 
       31 
     | 
    
         
            -
            # 
     | 
| 
       32 
     | 
    
         
            -
            #      
     | 
| 
       33 
     | 
    
         
            -
            #      
     | 
| 
       34 
     | 
    
         
            -
            # 
     | 
| 
       35 
     | 
    
         
            -
            #     SQL
         
     | 
| 
       36 
     | 
    
         
            -
            #      
     | 
| 
       37 
     | 
    
         
            -
            #      
     | 
| 
       38 
     | 
    
         
            -
            # 
     | 
| 
       39 
     | 
    
         
            -
            #
         
     | 
| 
       40 
     | 
    
         
            -
            # 
     | 
| 
       41 
     | 
    
         
            -
            # 
     | 
| 
       42 
     | 
    
         
            -
            #  
     | 
| 
       43 
     | 
    
         
            -
            #  
     | 
| 
       44 
     | 
    
         
            -
            #
         
     | 
| 
       45 
     | 
    
         
            -
            # 
     | 
| 
       46 
     | 
    
         
            -
            # 
     | 
| 
       47 
     | 
    
         
            -
            # 
     | 
| 
       48 
     | 
    
         
            -
            #
         
     | 
| 
       49 
     | 
    
         
            -
            #  
     | 
| 
       50 
     | 
    
         
            -
            #
         
     | 
| 
       51 
     | 
    
         
            -
            # 
     | 
| 
       52 
     | 
    
         
            -
            # 
     | 
| 
       53 
     | 
    
         
            -
            #     #  
     | 
| 
      
 3 
     | 
    
         
            +
            # @!parse
         
     | 
| 
      
 4 
     | 
    
         
            +
            #   class ActiveRecord::Migration
         
     | 
| 
      
 5 
     | 
    
         
            +
            #     # Create a procedure
         
     | 
| 
      
 6 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #     # @param [#to_s] name (nil)
         
     | 
| 
      
 8 
     | 
    
         
            +
            #     #   The qualified name of the procedure with arguments and returned value type
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     # @option [Boolean] :replace_existing (false) If the procedure should overwrite an existing one
         
     | 
| 
      
 10 
     | 
    
         
            +
            #     # @option [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
         
     | 
| 
      
 11 
     | 
    
         
            +
            #     # @option [#to_s] :body (nil) The body of the procedure
         
     | 
| 
      
 12 
     | 
    
         
            +
            #     # @option [Symbol] :security (:invoker) Define the role under which the procedure is invoked
         
     | 
| 
      
 13 
     | 
    
         
            +
            #     #   Supported values: :invoker (default), :definer
         
     | 
| 
      
 14 
     | 
    
         
            +
            #     # @option [#to_s] :comment The description of the procedure
         
     | 
| 
      
 15 
     | 
    
         
            +
            #     # @yield [p] the block with the procedure's definition
         
     | 
| 
      
 16 
     | 
    
         
            +
            #     # @yieldparam Object receiver of methods specifying the procedure
         
     | 
| 
      
 17 
     | 
    
         
            +
            #     # @return [void]
         
     | 
| 
      
 18 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 19 
     | 
    
         
            +
            #     # The syntax of the operation is the same as for `create_function`,
         
     | 
| 
      
 20 
     | 
    
         
            +
            #     # but with only `security` option available. Notice, that
         
     | 
| 
      
 21 
     | 
    
         
            +
            #     # procedures cannot return values so you're expected not to
         
     | 
| 
      
 22 
     | 
    
         
            +
            #     # define a returned value as well.
         
     | 
| 
      
 23 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 24 
     | 
    
         
            +
            #     # The procedure can be created either using inline syntax
         
     | 
| 
      
 25 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 26 
     | 
    
         
            +
            #     #   create_procedure "metadata.set_foo(a int)",
         
     | 
| 
      
 27 
     | 
    
         
            +
            #     #                    language: :sql,
         
     | 
| 
      
 28 
     | 
    
         
            +
            #     #                    body: "SET foo = a",
         
     | 
| 
      
 29 
     | 
    
         
            +
            #     #                    comment: "Sets foo value"
         
     | 
| 
      
 30 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 31 
     | 
    
         
            +
            #     # or using a block:
         
     | 
| 
      
 32 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 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"
         
     | 
| 
      
 40 
     | 
    
         
            +
            #     #   SQL
         
     | 
| 
      
 41 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 42 
     | 
    
         
            +
            #     # With a `replace_existing: true` option,
         
     | 
| 
      
 43 
     | 
    
         
            +
            #     # it will be created using the `CREATE OR REPLACE` clause.
         
     | 
| 
      
 44 
     | 
    
         
            +
            #     # In this case the migration is irreversible because we
         
     | 
| 
      
 45 
     | 
    
         
            +
            #     # don't know if and how to restore its previous definition.
         
     | 
| 
      
 46 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 47 
     | 
    
         
            +
            #     #   create_procedure "set_foo(a int)",
         
     | 
| 
      
 48 
     | 
    
         
            +
            #     #                    body: "SET foo = a",
         
     | 
| 
      
 49 
     | 
    
         
            +
            #     #                    replace_existing: true
         
     | 
| 
      
 50 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 51 
     | 
    
         
            +
            #     # A procedure without arguments is supported as well
         
     | 
| 
      
 52 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 53 
     | 
    
         
            +
            #     #   # the same as "do_something()"
         
     | 
| 
      
 54 
     | 
    
         
            +
            #     #   create_procedure "do_something" do |p|
         
     | 
| 
      
 55 
     | 
    
         
            +
            #     #     # ...
         
     | 
| 
      
 56 
     | 
    
         
            +
            #     #   end
         
     | 
| 
      
 57 
     | 
    
         
            +
            #     def create_procedure(name, **options, &block); end
         
     | 
| 
       54 
58 
     | 
    
         
             
            #   end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
59 
     | 
    
         
             
            module PGTrunk::Operations::Procedures
         
     | 
| 
       57 
60 
     | 
    
         
             
              # @private
         
     | 
| 
       58 
61 
     | 
    
         
             
              class CreateProcedure < Base
         
     | 
| 
         @@ -1,50 +1,53 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: false
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            # @! 
     | 
| 
       4 
     | 
    
         
            -
            #  
     | 
| 
       5 
     | 
    
         
            -
            #
         
     | 
| 
       6 
     | 
    
         
            -
            # 
     | 
| 
       7 
     | 
    
         
            -
            # 
     | 
| 
       8 
     | 
    
         
            -
            #  
     | 
| 
       9 
     | 
    
         
            -
            # @option [ 
     | 
| 
       10 
     | 
    
         
            -
            # @option [#to_s] : 
     | 
| 
       11 
     | 
    
         
            -
            # @option [ 
     | 
| 
       12 
     | 
    
         
            -
            # 
     | 
| 
       13 
     | 
    
         
            -
            # 
     | 
| 
       14 
     | 
    
         
            -
            # @ 
     | 
| 
       15 
     | 
    
         
            -
            # @ 
     | 
| 
       16 
     | 
    
         
            -
            #
         
     | 
| 
       17 
     | 
    
         
            -
            #  
     | 
| 
       18 
     | 
    
         
            -
            #
         
     | 
| 
       19 
     | 
    
         
            -
            # 
     | 
| 
       20 
     | 
    
         
            -
            #
         
     | 
| 
       21 
     | 
    
         
            -
            #  
     | 
| 
       22 
     | 
    
         
            -
            # 
     | 
| 
       23 
     | 
    
         
            -
            #  
     | 
| 
       24 
     | 
    
         
            -
            #
         
     | 
| 
       25 
     | 
    
         
            -
            # 
     | 
| 
       26 
     | 
    
         
            -
            #
         
     | 
| 
       27 
     | 
    
         
            -
            #  
     | 
| 
       28 
     | 
    
         
            -
            # 
     | 
| 
       29 
     | 
    
         
            -
            #  
     | 
| 
       30 
     | 
    
         
            -
            #
         
     | 
| 
       31 
     | 
    
         
            -
            # 
     | 
| 
       32 
     | 
    
         
            -
            #      
     | 
| 
       33 
     | 
    
         
            -
            #      
     | 
| 
       34 
     | 
    
         
            -
            # 
     | 
| 
       35 
     | 
    
         
            -
            #     SQL
         
     | 
| 
       36 
     | 
    
         
            -
            #      
     | 
| 
       37 
     | 
    
         
            -
            #      
     | 
| 
       38 
     | 
    
         
            -
            # 
     | 
| 
       39 
     | 
    
         
            -
            #
         
     | 
| 
       40 
     | 
    
         
            -
            # 
     | 
| 
       41 
     | 
    
         
            -
            # 
     | 
| 
       42 
     | 
    
         
            -
            #
         
     | 
| 
       43 
     | 
    
         
            -
            # 
     | 
| 
       44 
     | 
    
         
            -
            #
         
     | 
| 
       45 
     | 
    
         
            -
            #  
     | 
| 
       46 
     | 
    
         
            -
            # 
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # @!parse
         
     | 
| 
      
 4 
     | 
    
         
            +
            #   class ActiveRecord::Migration
         
     | 
| 
      
 5 
     | 
    
         
            +
            #     # Drop a procedure
         
     | 
| 
      
 6 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #     # @param [#to_s] name (nil)
         
     | 
| 
      
 8 
     | 
    
         
            +
            #     #   The qualified name of the procedure with arguments and returned value type
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     # @option [Boolean] :if_exists (false) Suppress the error when the procedure is absent
         
     | 
| 
      
 10 
     | 
    
         
            +
            #     # @option [#to_s] :language ("sql") The language (like "sql" or "plpgsql")
         
     | 
| 
      
 11 
     | 
    
         
            +
            #     # @option [#to_s] :body (nil) The body of the procedure
         
     | 
| 
      
 12 
     | 
    
         
            +
            #     # @option [Symbol] :security (:invoker) Define the role under which the procedure is invoked
         
     | 
| 
      
 13 
     | 
    
         
            +
            #     #   Supported values: :invoker (default), :definer
         
     | 
| 
      
 14 
     | 
    
         
            +
            #     # @option [#to_s] :comment The description of the procedure
         
     | 
| 
      
 15 
     | 
    
         
            +
            #     # @yield [p] the block with the procedure's definition
         
     | 
| 
      
 16 
     | 
    
         
            +
            #     # @yieldparam Object receiver of methods specifying the procedure
         
     | 
| 
      
 17 
     | 
    
         
            +
            #     # @return [void]
         
     | 
| 
      
 18 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 19 
     | 
    
         
            +
            #     # A procedure can be dropped by a plain name:
         
     | 
| 
      
 20 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 21 
     | 
    
         
            +
            #     #   drop_procedure "set_foo"
         
     | 
| 
      
 22 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 23 
     | 
    
         
            +
            #     # If several overloaded procedures have the name,
         
     | 
| 
      
 24 
     | 
    
         
            +
            #     # then you must specify the signature having
         
     | 
| 
      
 25 
     | 
    
         
            +
            #     # types of attributes at least:
         
     | 
| 
      
 26 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 27 
     | 
    
         
            +
            #     #   drop_procedure "set_foo(int)"
         
     | 
| 
      
 28 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 29 
     | 
    
         
            +
            #     # In both cases above the operation is irreversible. To make it
         
     | 
| 
      
 30 
     | 
    
         
            +
            #     # inverted you have to provide a full signature along with
         
     | 
| 
      
 31 
     | 
    
         
            +
            #     # the body definition. The other options are supported as well:
         
     | 
| 
      
 32 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 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"
         
     | 
| 
      
 40 
     | 
    
         
            +
            #     #   SQL
         
     | 
| 
      
 41 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 42 
     | 
    
         
            +
            #     # The operation can be called with `if_exists` option. In this case
         
     | 
| 
      
 43 
     | 
    
         
            +
            #     # it would do nothing when no procedure existed.
         
     | 
| 
      
 44 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 45 
     | 
    
         
            +
            #     #   drop_procedure "metadata.set_foo(a int)", if_exists: true
         
     | 
| 
      
 46 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 47 
     | 
    
         
            +
            #     # Notice, that this option make the operation irreversible because of
         
     | 
| 
      
 48 
     | 
    
         
            +
            #     # uncertainty about the previous state of the database.
         
     | 
| 
      
 49 
     | 
    
         
            +
            #     def drop_procedure(name, **options, &block); end
         
     | 
| 
      
 50 
     | 
    
         
            +
            #   end
         
     | 
| 
       48 
51 
     | 
    
         
             
            module PGTrunk::Operations::Procedures
         
     | 
| 
       49 
52 
     | 
    
         
             
              # @private
         
     | 
| 
       50 
53 
     | 
    
         
             
              class DropProcedure < 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 procedure
         
     | 
| 
      
 6 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #     # @param [#to_s] :name (nil) The qualified name of the procedure
         
     | 
| 
      
 8 
     | 
    
         
            +
            #     # @option [#to_s] :to (nil) The new qualified name for the procedure
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     # @return [void]
         
     | 
| 
      
 10 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 11 
     | 
    
         
            +
            #     # A procedure can be renamed by changing both the name
         
     | 
| 
      
 12 
     | 
    
         
            +
            #     # and the schema (namespace) it belongs to.
         
     | 
| 
      
 13 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 14 
     | 
    
         
            +
            #     # If there are no overloaded procedures, then you can use a plain name:
         
     | 
| 
      
 15 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 16 
     | 
    
         
            +
            #     #   rename_procedure "math.set_foo", to: "public.foo_setup"
         
     | 
| 
      
 17 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 18 
     | 
    
         
            +
            #     # otherwise the types of attributes must be explicitly specified.
         
     | 
| 
      
 19 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 20 
     | 
    
         
            +
            #     #   rename_procedure "math.set_foo(int)", to: "public.foo_setup"
         
     | 
| 
      
 21 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 22 
     | 
    
         
            +
            #     # Any specification of attributes in `to:` option
         
     | 
| 
      
 23 
     | 
    
         
            +
            #     # is ignored because they cannot be changed anyway.
         
     | 
| 
      
 24 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 25 
     | 
    
         
            +
            #     # The operation is always reversible.
         
     | 
| 
      
 26 
     | 
    
         
            +
            #     def rename_procedure(name, to:); end
         
     | 
| 
      
 27 
     | 
    
         
            +
            #   end
         
     | 
| 
       25 
28 
     | 
    
         
             
            module PGTrunk::Operations::Procedures
         
     | 
| 
       26 
29 
     | 
    
         
             
              # @private
         
     | 
| 
       27 
30 
     | 
    
         
             
              class RenameProcedure < 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 
     | 
    
         
            -
            #
         
     | 
| 
       20 
     | 
    
         
            -
            # 
     | 
| 
       21 
     | 
    
         
            -
            #      
     | 
| 
       22 
     | 
    
         
            -
            #      
     | 
| 
       23 
     | 
    
         
            -
            #     s. 
     | 
| 
       24 
     | 
    
         
            -
            #     s. 
     | 
| 
       25 
     | 
    
         
            -
            # 
     | 
| 
       26 
     | 
    
         
            -
            #
         
     | 
| 
       27 
     | 
    
         
            -
            # 
     | 
| 
       28 
     | 
    
         
            -
            #
         
     | 
| 
       29 
     | 
    
         
            -
            # 
     | 
| 
       30 
     | 
    
         
            -
            #      
     | 
| 
       31 
     | 
    
         
            -
            #      
     | 
| 
       32 
     | 
    
         
            -
            #     s. 
     | 
| 
       33 
     | 
    
         
            -
            #     s. 
     | 
| 
       34 
     | 
    
         
            -
            # 
     | 
| 
       35 
     | 
    
         
            -
            #
         
     | 
| 
       36 
     | 
    
         
            -
            # 
     | 
| 
       37 
     | 
    
         
            -
            #
         
     | 
| 
       38 
     | 
    
         
            -
            # 
     | 
| 
       39 
     | 
    
         
            -
            #      
     | 
| 
       40 
     | 
    
         
            -
            #      
     | 
| 
       41 
     | 
    
         
            -
            #     s. 
     | 
| 
       42 
     | 
    
         
            -
            #     s. 
     | 
| 
       43 
     | 
    
         
            -
            #     s. 
     | 
| 
       44 
     | 
    
         
            -
            # 
     | 
| 
       45 
     | 
    
         
            -
            #
         
     | 
| 
       46 
     | 
    
         
            -
            # 
     | 
| 
       47 
     | 
    
         
            -
            # 
     | 
| 
       48 
     | 
    
         
            -
            #
         
     | 
| 
       49 
     | 
    
         
            -
            # 
     | 
| 
       50 
     | 
    
         
            -
            #      
     | 
| 
       51 
     | 
    
         
            -
            #      
     | 
| 
       52 
     | 
    
         
            -
            #     s. 
     | 
| 
       53 
     | 
    
         
            -
            # 
     | 
| 
       54 
     | 
    
         
            -
            #
         
     | 
| 
       55 
     | 
    
         
            -
            # 
     | 
| 
       56 
     | 
    
         
            -
            # 
     | 
| 
       57 
     | 
    
         
            -
            #  
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # @!parse
         
     | 
| 
      
 4 
     | 
    
         
            +
            #   class ActiveRecord::Migration
         
     | 
| 
      
 5 
     | 
    
         
            +
            #     # Create a custom statistics
         
     | 
| 
      
 6 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #     # @param [#to_s] name (nil) The qualified name of the statistics
         
     | 
| 
      
 8 
     | 
    
         
            +
            #     # @option [Boolean] :if_not_exists (false)
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     #   Suppress the error when the statistics is already exist
         
     | 
| 
      
 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 
     | 
    
         
            +
            #     # The statistics can be created with explicit name:
         
     | 
| 
      
 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
         
     | 
| 
      
 28 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 29 
     | 
    
         
            +
            #     # The name can be generated as well:
         
     | 
| 
      
 30 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 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
         
     | 
| 
      
 37 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 38 
     | 
    
         
            +
            #     # Since v14 PostgreSQL have supported expressions in addition to columns:
         
     | 
| 
      
 39 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 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
         
     | 
| 
      
 47 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 48 
     | 
    
         
            +
            #     # as well as statistics for the sole expression (kinds must be blank)
         
     | 
| 
      
 49 
     | 
    
         
            +
            #     # by columns of some table.
         
     | 
| 
      
 50 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 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
         
     | 
| 
      
 56 
     | 
    
         
            +
            #     #
         
     | 
| 
      
 57 
     | 
    
         
            +
            #     # Use `if_not_exists: true` to suppress error in case the statistics
         
     | 
| 
      
 58 
     | 
    
         
            +
            #     # has already been created. This option, though, makes the migration
         
     | 
| 
      
 59 
     | 
    
         
            +
            #     # irreversible due to uncertainty of the previous state of the database.
         
     | 
| 
      
 60 
     | 
    
         
            +
            #     def create_statistics(name, **options, &block); end
         
     | 
| 
      
 61 
     | 
    
         
            +
            #   end
         
     | 
| 
       59 
62 
     | 
    
         
             
            module PGTrunk::Operations::Statistics
         
     | 
| 
       60 
63 
     | 
    
         
             
              # SQL snippet to fetch statistics in v10-13
         
     | 
| 
       61 
64 
     | 
    
         
             
              SQL_V10 = <<~SQL.freeze
         
     |