module Sequel::Plugins::ConstraintValidations

The constraint_validations plugin is designed to be used with databases that used the constraint_validations extension when creating their tables. The extension adds validation metadata for constraints created, and this plugin reads that metadata and automatically creates validations for all of the constraints. For example, if you used the extension and created your albums table like this:

DB.create_table(:albums) do
  primary_key :id
  String :name
  validate do
    min_length 5, :name
  end
end

Then when you went to save an album that uses this plugin:

Album.create(name: 'abc')
# raises Sequel::ValidationFailed: name is shorter than 5 characters

Usage:

# Make all model subclasses use constraint validations (called before loading subclasses)
Sequel::Model.plugin :constraint_validations

# Make the Album class use constraint validations
Album.plugin :constraint_validations