Module Sequel::ConstraintValidations
In: lib/sequel/extensions/constraint_validations.rb

Methods

Classes and Modules

Module Sequel::ConstraintValidations::AlterTableGeneratorMethods
Module Sequel::ConstraintValidations::CreateTableGeneratorMethods
Class Sequel::ConstraintValidations::Generator

Constants

DEFAULT_CONSTRAINT_VALIDATIONS_TABLE = :sequel_constraint_validations   The default table name used for the validation metadata.

Attributes

constraint_validations_table  [RW]  The name of the table storing the validation metadata. If modifying this from the default, this should be changed directly after loading the extension into the database

Public Class methods

Set the default validation metadata table name if it has not already been set.

[Source]

     # File lib/sequel/extensions/constraint_validations.rb, line 133
133:     def self.extended(db)
134:       db.constraint_validations_table ||= DEFAULT_CONSTRAINT_VALIDATIONS_TABLE
135:     end

Public Instance methods

Create the table storing the validation metadata for all of the constraints created by this extension.

[Source]

     # File lib/sequel/extensions/constraint_validations.rb, line 217
217:     def create_constraint_validations_table
218:       create_table(constraint_validations_table) do
219:         String :table, :null=>false
220:         String :constraint_name
221:         String :validation_type, :null=>false
222:         String :column, :null=>false
223:         String :argument
224:         String :message
225:         TrueClass :allow_nil
226:       end
227:     end

Delete validation metadata for specific constraints. At least one of the following options should be specified:

:table :The table containing the constraint
:column :The column affected by the constraint
:constraint :The name of the related constraint

The main reason for this method is when dropping tables or columns. If you have previously defined a constraint validation on the table or column, you should delete the related metadata when dropping the table or column. For a table, this isn‘t a big issue, as it will just result in some wasted space, but for columns, if you don‘t drop the related metadata, it could make it impossible to save rows, since a validation for a nonexistent column will be created.

[Source]

     # File lib/sequel/extensions/constraint_validations.rb, line 250
250:     def drop_constraint_validations_for(opts=OPTS)
251:       ds = from(constraint_validations_table)
252:       if table = opts[:table]
253:         ds = ds.where(:table=>constraint_validations_literal_table(table))
254:       end
255:       if column = opts[:column]
256:         ds = ds.where(:column=>column.to_s)
257:       end
258:       if constraint = opts[:constraint]
259:         ds = ds.where(:constraint_name=>constraint.to_s)
260:       end
261:       unless table || column || constraint
262:         raise Error, "must specify :table, :column, or :constraint when dropping constraint validations"
263:       end
264:       ds.delete
265:     end

Drop the constraint validations table.

[Source]

     # File lib/sequel/extensions/constraint_validations.rb, line 230
230:     def drop_constraint_validations_table
231:       drop_table(constraint_validations_table)
232:     end

[Validate]