Sha256: ad1332fce343c6ba5eabcb1c89cdc18acddc52fb819c5516f64c73520644943c

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: false

# @!parse
#   class ActiveRecord::Migration
#     # Validate an invalid check constraint
#     #
#     # @param [#to_s] table (nil) The qualified name of the table
#     # @param [#to_s] expression (nil) The SQL expression
#     # @option options [#to_s] :name (nil) The optional name of the constraint
#     # @yield [c] the block with the constraint's definition
#     # @yieldparam Object receiver of methods specifying the constraint
#     # @return [void]
#     #
#     # The invalid constraint can be identified by table and explicit name:
#     #
#     # ```ruby
#     # validate_check_constraint :users, name: "phone_is_long_enough"
#     # ```
#     #
#     # Alternatively it can be specified by expression. In this case
#     # you must ensure the expression has the same form as it is stored
#     # in the database (after parsing the source).
#     #
#     # ```ruby
#     # validate_check_constraint :users, "length((phone::text) > 10)"
#     # ```
#     #
#     # Notice that it is invertible but the inverted operation does nothing.
#     def validate_check_constraint(table, expression = nil, **options, &block); end
#   end
module PGTrunk::Operations::CheckConstraints
  # @private
  class ValidateCheckConstraint < Base
    validates :if_exists, :force, :new_name, :comment, :new_name, :inherit,
              absence: true

    def to_sql(_version)
      <<~SQL.squish
        ALTER TABLE #{table.to_sql} VALIDATE CONSTRAINT #{name.name.inspect};
      SQL
    end

    # The operation is invertible but the inversion does nothing
    def invert; end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_trunk-0.2.0 lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb
pg_trunk-0.1.3 lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb