Sha256: 00b48acc17ca9fef72e5b6686570c87cbddafbd6fa042c62600bbbc95f7662de

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 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 [#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:
#     #
#     #   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).
#     #
#     #   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

1 entries across 1 versions & 1 rubygems

Version Path
pg_trunk-0.1.1 lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb