Creates and adds a new check.

@param string $constraint The check constraint.
@param string $name       The check name.

@return \Fridge\DBAL\Schema\Check The new index.
493867
public function createCheck($constraint, $name = null)
    {
        $check = new Check($name, $constraint);
        $this->addCheck($check);

        return $check;
    }
1167949
public function setConstraint($fieldName, $constraint)
    {
        $class = get_class($constraint);
        // remove existing constraint if it already exists
        if ($this->getConstraint($fieldName, $class)) {
            $this->removeConstraint($fieldName, $class);
        }

        $this->constraints[$fieldName][$class] = $constraint;

        if ($this->form) {
            $dataField = $this->form->Fields()->dataFieldByName($fieldName);
            $constraint->setField($dataField);
            if ($this->parsleyEnabled) {
                // If there is no field, output a clear error message before trying to apply parsley
                if (!$dataField) {
                    throw new Exception("You have set a constraint on '$fieldName' but it does not exist in the FieldList.");
                }
                $constraint->applyParsley();
            }
        }

        return $this;
    }
45
public function checks($name, $arg = null) {
        if (empty($arg)) {
            $this->checks[] = $name;
        } else {
            $this->checks[$name] = $arg;
        }
        return $this;
    }
419947
public function addUniqueConstraint(array $columns, $name)
    {
        if ( ! isset($this->cm->table['uniqueConstraints'])) {
            $this->cm->table['uniqueConstraints'] = array();
        }

        $this->cm->table['uniqueConstraints'][$name] = array('columns' => $columns);

        return $this;
    }
531543
public function checkIntegrity($check=true,$schema='')
	{
		if($schema==='')
			$schema=$this->getDefaultSchema();
		$mode=$check ? 'ENABLE' : 'DISABLE';
		foreach($this->getTableNames($schema) as $table)
		{
			$constraints=$this->getDbConnection()
				->createCommand("SELECT CONSTRAINT_NAME FROM USER_CONSTRAINTS WHERE TABLE_NAME=:t AND OWNER=:o")
				->queryColumn(array(':t'=>$table,':o'=>$schema));
			foreach($constraints as $constraint)
				$this->getDbConnection()
					->createCommand("ALTER TABLE \"{$schema}\".\"{$table}\" {$mode} CONSTRAINT \"{$constraint}\"")
					->execute();
		}
	}
313718
public function validate($password, Constraint $constraint)
    {
        if (null === $password || '' === $password) {
            $this->context->addViolation($constraint->message);

            return;
        }

        $user = $this->tokenStorage->getToken()->getUser()->getAPIUser();

        if (!$user instanceof User) {
            throw new ConstraintDefinitionException('The User object must implement the UserReference interface.');
        }

        try {
            $this->userService->loadUserByCredentials($user->login, $password);
        } catch (NotFoundException | InvalidArgumentException $e) {
            $this->context->buildViolation($constraint->message)->addViolation();
        }
    }
42447
private function createDocFromConstraint(Constraint $constraint) : ?TypeDoc
    {
        $doc = null;

        if (null !== ($stringType = $this->getStringType($constraint))) {
            $doc = $this->normalizeType($stringType);
        } elseif ($constraint instanceof Assert\Callback) {
            $doc = $this->getTypeFromCallbackConstraint($constraint);
        } elseif ($constraint instanceof Assert\Existence && count($constraint->constraints) > 0) {
            $doc = $this->guess($constraint->constraints);
        }

        return $doc;
    }
526047
final public function findIndexColumnByName(string $name): ? IndexColumn
    {
        /** @var IndexColumn $indexColumn */
        foreach ($this->columns as $indexColumn) {
            $column = $indexColumn->getColumn();
            if ($column::getName() === $name) {
                return $indexColumn;
            }
        }

        return null;
    }
1059069
public function matching($constraint)
    {
        $this->constraint = $constraint;
        $this->queryBuilder->where($constraint);
        return $this;
    }
557389
public function addIndex($name)
    {
        if ($this->scope == 'alter') {
            $command = 'ADD INDEX';
        } else {
            $command = 'INDEX';
        }

        $this->sqls[] = sprintf('%s `%s`', $command, $name);

        return $this;
    }
998077
protected function validateEnclosure(Constraint $constraint)
    {
        if (strlen($constraint->enclosure) > 2) {
            throw new ConstraintDefinitionException(sprintf('"%s" is not a valid enclosure', $constraint->enclosure));
        }
    }
755532
public static function dropConstraint($table, $name, $ifExists = false, $action = null)
    {
        $query = static::getQuery();

        return static::build(
            'ALTER TABLE',
            $query->quoteName($table),
            'DROP CONSTRAINT',
            $ifExists ? 'IF EXISTS' : null,
            $query->quoteName($name),
            $action
        );
    }
459759
public function unique($name, array $colmuns)
    {
        if (is_array($colmuns)) {
            $query = "CONSTRAINT $name UNIQUE (";
            //
            for ($i = 0; $i < Collection::count($colmuns); $i++) {
                if ($i == Collection::count($colmuns) - 1) {
                    $query .= $colmuns[$i];
                } else {
                    $query .= $colmuns[$i].',';
                }
            }
            $query .= ')';
            //
            self::$colmuns[] = $query;
        }
        //
        return $this;
    }
573335
public function checkIntegrity($check=true,$schema='')
	{
		$enable=$check ? 'CHECK' : 'NOCHECK';
		if(!isset($this->_normalTables[$schema]))
			$this->_normalTables[$schema]=$this->findTableNames($schema,false);
		$db=$this->getDbConnection();
		foreach($this->_normalTables[$schema] as $tableName)
		{
			$tableName=$this->quoteTableName($tableName);
			$db->createCommand("ALTER TABLE $tableName $enable CONSTRAINT ALL")->execute();
		}
	}
826412
public function createInstanceFor($constraintName)
    {
        if (!isset($this->constraintMap[$constraintName])) {
            throw new InvalidArgumentException('Unknown constraint ' . $constraintName);
        }

        if (!isset($this->instanceCache[$constraintName])) {
            $this->instanceCache[$constraintName] = new $this->constraintMap[$constraintName]($this);
        }

        return clone $this->instanceCache[$constraintName];
    }
90395
public function add($field, Constraint $constraint)
    {
        if (!isset($this->constraints[$field])) {
            $this->constraints['fields'][$field] = [];
        }

        $this->constraints['fields'][$field][] = $constraint;

        return $this;
    }
187473
public function addConstraint($name, $attrs)
    {
        if (is_string($attrs)) {
            $attrs = ['type' => $attrs];
        }
        $attrs = array_intersect_key($attrs, static::$_indexKeys);
        $attrs += static::$_indexKeys;
        if (!in_array($attrs['type'], static::$_validConstraintTypes, true)) {
            throw new Exception(sprintf('Invalid constraint type "%s" in table "%s".', $attrs['type'], $this->_table));
        }
        if (empty($attrs['columns'])) {
            throw new Exception(sprintf('Constraints in table "%s" must have at least one column.', $this->_table));
        }
        $attrs['columns'] = (array)$attrs['columns'];
        foreach ($attrs['columns'] as $field) {
            if (empty($this->_columns[$field])) {
                $msg = sprintf(
                    'Columns used in constraints must be added to the Table schema first. ' .
                    'The column "%s" was not found in table "%s".',
                    $field,
                    $this->_table
                );
                throw new Exception($msg);
            }
        }

        if ($attrs['type'] === static::CONSTRAINT_FOREIGN) {
            $attrs = $this->_checkForeignKey($attrs);

            if (isset($this->_constraints[$name])) {
                $this->_constraints[$name]['columns'] = array_unique(array_merge(
                    $this->_constraints[$name]['columns'],
                    $attrs['columns']
                ));

                if (isset($this->_constraints[$name]['references'])) {
                    $this->_constraints[$name]['references'][1] = array_unique(array_merge(
                        (array)$this->_constraints[$name]['references'][1],
                        [$attrs['references'][1]]
                    ));
                }

                return $this;
            }
        } else {
            unset($attrs['references'], $attrs['update'], $attrs['delete']);
        }

        $this->_constraints[$name] = $attrs;

        return $this;
    }