Creates an INDEX

@param string $name Index name
@param string|array $target Column name or collection of ones
@param boolean $unique Whether it should be unique or not
@param string $table Table name. By default it uses mapper's table
@return boolean
962438
public function createIndex($name, $target, $unique = false, $table = null)
    {
        return $this->db->createIndex($table, $name, $target, $unique)
                        ->execute();
    }
466184
public function addColumn($table, $name, $data)
    {

        $q = "ALTER TABLE {$table} ADD {$name}";
        $v = $data;

        if (isset($v['type'])) {
            $q .= " {$v['type']}";
            if (isset($v['length'])) {
                $q .= "({$v['length']})";
            } else {
                if ($v['type'] != 'int' && $v['type'] != 'datetime') {
                    die ("Please set length for table: {$name} - column: {$name}");
                }
            }

            if (isset($v['unsigned']) && $v['unsigned'] == true) {
                $q .= " UNSIGNED";
            }

            if (!isset($v['null']) || $v['null'] == false) {
                $q .= " NOT NULL";
            }

            if (isset($v['default'])) {
                if (is_string($v['default'])) {
                    $v['default'] = "'{$v['default']}'";
                }

                $q .= " DEFAULT {$v['default']}";
            }

            if (isset($v['ai']) && $v['ai'] == true) {
                $q .= " AUTO_INCREMENT";
            }

            if ((isset($v['unique']) && $v['unique'] == true) && (isset($v['primary']) && $v['primary'] == true)) {
                die ("Unique or Primary?");
            }

            if (isset($v['unique']) && $v['unique'] == true) {
                $q .= " UNIQUE";
            }

            if (isset($v['primary']) && $v['primary'] == true) {
                $q .= " PRIMARY KEY";
            }

            if (isset($v['after'])) {
                $q .= " AFTER {$v['after']}";
            }

        } else {
            die ("Please set type of column ");
        }

        return $this->executeQuery($q);
    }
390115
public static function addIndex($table, $type, $columns, $name)
    {
        $cols = static::buildIndexDeclare($name, $columns, $table);

        return static::build(
            'CREATE',
            strtoupper($type),
            $cols
        );
    }
50362
private function createMapping(AbstractTable $source, AbstractTable $target)
    {
        $mapping = [];
        foreach ($target->getColumns() as $name => $column) {
            if ($source->hasColumn($name)) {
                $mapping[$name] = $column->getName();
            }
        }

        return $mapping;
    }
595832
private void createUniqueIndexGFS(DBCollection coll, String id)
    {
        try
        {
            coll.createIndex(new BasicDBObject("metadata." + id, 1), new BasicDBObject("unique", true));
        }
        catch (MongoException ex)
        {
            throw new KunderaException("Error in creating unique indexes in " + coll.getFullName() + " collection on "
                    + id + " field");
        }
    }
6972
public function registerTable($name, $alias)
    {
        if (!empty($alias) && empty($name))
            return;

        if (!empty($alias) && !empty($this->parent_scope))
        {
            $table = $this->parent_scope->resolveAlias($alias); 
            if (!empty($table))
                throw new QueryException("Duplicate alias \"$alias\" - was already bound to \"$table\" in parent scope");
        }

        if (isset($this->tables[$name]))
        {
            if (empty($alias))
                throw new QueryException("Duplicate table without an alias: \"$name\"");
            if (isset($this->tables[$name][$alias]))
                throw new QueryException("Duplicate alias \"$alias\" for table \"$name\"");
            if (isset($this->tables[$name][$name]))
                throw new QueryException("All instances of a table reference must be aliased if used more than once");

            $this->tables[$name][$alias] = true;
            $this->aliases[$alias] = $name;
        }
        elseif (!empty($alias) && is_string($alias))
        {
            if (isset($this->aliases[$alias]))
                throw new QueryException("Duplicate alias \"$alias\" for table \"$name\" - also referring to \"{$this->aliases[$alias]}\"");
            $this->aliases[$alias] = $name;
            $this->tables[$name][$alias] = true;
        }
        else
        {
            $this->tables[$name][$name] = true;
        }
        return $this;
    }
411857
public function addUniqueKey($name, array $fields)
    {
        //Argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        $this->uniqueKeys[$name] = $fields;
        return $this;
    }
1017293
public static function exists($name, $target = '')
    {
        if ($target === true) {
            return isset(static::$_matchers[$name]);
        }
        return isset(static::$_matchers[$name][$target]);
    }
172935
public function addTarget(Target $target, string $name = null)
    {
        if ($name === null) {
            $this->_targets[] = $target;
        } else {
            $this->_targets[$name] = $target;
        }
    }
1015174
protected function getTableMigrationIndexes(array $output, array $table, string $tableName, array $new, array $old): array
    {
        if (empty($table['indexes'])) {
            return $output;
        }
        foreach ($table['indexes'] as $indexName => $indexSequences) {
            if (!isset($old['tables'][$tableName]['indexes'][$indexName])) {
                $output = $this->getIndexCreate($output, $new, $tableName, $indexName);
            } else {
                if ($this->neq($new, $old, ['tables', $tableName, 'indexes', $indexName])) {
                    $output = $this->getIndexCreate($output, $new, $tableName, $indexName);
                }
            }
        }

        // To delete
        if (!empty($old['tables'][$tableName]['indexes'])) {
            foreach ($old['tables'][$tableName]['indexes'] as $indexName => $indexSequences) {
                if (!isset($new['tables'][$tableName]['indexes'][$indexName])) {
                    $output = $this->getIndexRemove($indexName, $output);
                }
            }
        }

        return $output;
    }
1195541
function createIndex($name, $callback = false)
    {

        $index = new Index($name, $callback);

        $index->connection = $this->connection;

        return $index->create();
    }
220920
public function addIndex($columns, $unique = FALSE, $length = 20)
    {
        if (!is_array($columns))
            $columns = array($columns);
        $existingCol = $this->columns;
        foreach ($existingCol as &$col)
            $col = $col->getColumnArray();
        $allCols = array_merge($this->getCols(true), $existingCol);
        parent::_addIndex($columns, $allCols, $unique, $length);
    }
1322354
public final Index createAndAddExprIndexStructure(
            HsqlName name, int[] columns, Expression[] indexExprs, boolean unique, boolean migrating, boolean constraint) {

        Index newExprIndex = createIndexStructure(name, columns, null, null, unique, migrating, constraint, false);
        newExprIndex = newExprIndex.withExpressions(indexExprs);
        addIndex(newExprIndex);
        return newExprIndex;
    }
229231
public function addIndex($columns, $unique = FALSE, $length = 20)
    {
        if (!is_array($columns))
            $columns = array($columns);
        $cols = $this->columns;
        foreach ($cols as &$col)
            $col = $col->getColumnArray();
        parent::_addIndex($columns,$cols,$unique,$length);
    }
1280002
public function getCreateAutoincrementSql($name, $table, $start = 1)
    {
        $tableIdentifier   = $this->normalizeIdentifier($table);
        $quotedTableName   = $tableIdentifier->getQuotedName($this);
        $unquotedTableName = $tableIdentifier->getName();

        $nameIdentifier = $this->normalizeIdentifier($name);
        $quotedName     = $nameIdentifier->getQuotedName($this);
        $unquotedName   = $nameIdentifier->getName();

        $sql = [];

        $autoincrementIdentifierName = $this->getAutoincrementIdentifierName($tableIdentifier);

        $idx = new Index($autoincrementIdentifierName, [$quotedName], true, true);

        $sql[] = 'DECLARE
  constraints_Count NUMBER;
BEGIN
  SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = \'' . $unquotedTableName . '\' AND CONSTRAINT_TYPE = \'P\';
  IF constraints_Count = 0 OR constraints_Count = \'\' THEN
    EXECUTE IMMEDIATE \'' . $this->getCreateConstraintSQL($idx, $quotedTableName) . '\';
  END IF;
END;';

        $sequenceName = $this->getIdentitySequenceName(
            $tableIdentifier->isQuoted() ? $quotedTableName : $unquotedTableName,
            $nameIdentifier->isQuoted() ? $quotedName : $unquotedName
        );
        $sequence     = new Sequence($sequenceName, $start);
        $sql[]        = $this->getCreateSequenceSQL($sequence);

        $sql[] = 'CREATE TRIGGER ' . $autoincrementIdentifierName . '
   BEFORE INSERT
   ON ' . $quotedTableName . '
   FOR EACH ROW
DECLARE
   last_Sequence NUMBER;
   last_InsertID NUMBER;
BEGIN
   SELECT ' . $sequenceName . '.NEXTVAL INTO :NEW.' . $quotedName . ' FROM DUAL;
   IF (:NEW.' . $quotedName . ' IS NULL OR :NEW.' . $quotedName . ' = 0) THEN
      SELECT ' . $sequenceName . '.NEXTVAL INTO :NEW.' . $quotedName . ' FROM DUAL;
   ELSE
      SELECT NVL(Last_Number, 0) INTO last_Sequence
        FROM User_Sequences
       WHERE Sequence_Name = \'' . $sequence->getName() . '\';
      SELECT :NEW.' . $quotedName . ' INTO last_InsertID FROM DUAL;
      WHILE (last_InsertID > last_Sequence) LOOP
         SELECT ' . $sequenceName . '.NEXTVAL INTO last_Sequence FROM DUAL;
      END LOOP;
   END IF;
END;';

        return $sql;
    }
649141
public ColumnModel singleUnique(String uniqueName) {
		makeSureTableModelExist();
		DialectException.assureNotEmpty(uniqueName, "indexName can not be empty");
		this.tableModel.unique(uniqueName).columns(this.getColumnName());
		return this;
	}
29911
public static function buildFromName(Table $table, $name)
    {
        $index = new Index();
        $index->setName($name);

        return new static($table, $index);
    }