Define the primary key in the database.

@param string $name The name of the column.
@param string $type The datatype for the column.
@return TableDef
3661
public function setPrimaryKey($name, $type = 'int') {
        $column = $this->createColumnDef($type, false);
        $column['autoIncrement'] = true;
        $column['primary'] = true;

        $this->columns[$name] = $column;

        // Add the pk index.
        $this->addIndex(Db::INDEX_PK, $name);

        return $this;
    }
300532
public function addType(Type $type, $name = '')
    {
        if (!$name) {
            $name = (string)$type;
        }

        $this->types[$name] = $type;
    }
1080000
public function createIndex(string $type, array $columnNames, ?string $name = null,
			?Table $refTable = null, ?array $refColumnNames = null): Index {
		$name = $name ?? $this->generateIndexKeyName($type);
		$this->triggerChangeListeners();
		
		if ($type !== IndexType::FOREIGN) {
			ArgUtils::assertTrue(empty($refColumnNames) && null === $refTable);
			$newIndex = CommonIndex::createFromColumnNames($this, $name, $type, $columnNames);
		} else {
			if (!$this->isForeignKeyAvailable()) {
				throw new UnavailableTypeException('Foreign keys are not Supported.');
			}
			$newIndex = ForeignIndex::createFromColumnNames($this, $name, $columnNames, $refTable, $refColumnNames);
		}
		$this->addIndex($newIndex);
		return $newIndex;
	}
1340037
public function modifyColumn(
        $name,
        $type = 'text',
        $signed = true,
        $allowNull = true,
        $default = '',
        $comment = '',
        $options = []
    ) {
        $column = $name;

        if ($column instanceof Column) {
            $name = $column->getName();
            $type = $column->getType();
            $length = $column->getLength();
            $allowNull = $column->getAllowNull();
            $default = $column->getDefault();
            $comment = $column->getComment();
        }

        if (!$this->hasColumn($name)) {
            return $this;
        }

        $type = PostgresqlType::getType($type);
        $length = isset($length) ? $length : PostgresqlType::getLength($type);
        $length = PostgresqlType::noLength($type) ? null : $length;
        $length = $length ? '(' . $length . ')' : null;

        $query = $this->db->getQuery(true);

        // Type
        $sql = PostgresqlGrammar::build(
            'ALTER TABLE ' . $query->quoteName($this->getName()),
            'ALTER COLUMN',
            $query->quoteName($name),
            'TYPE',
            $type . $length,
            $this->usingTextToNumeric($name, $type)
        );

        $sql .= ";\n" . PostgresqlGrammar::build(
            'ALTER TABLE ' . $query->quoteName($this->getName()),
            'ALTER COLUMN',
            $query->quoteName($name),
            $allowNull ? 'DROP' : 'SET',
            'NOT NULL'
        );

        if ($default !== false) {
            $sql .= ";\n" . PostgresqlGrammar::build(
                'ALTER TABLE ' . $query->quoteName($this->getName()),
                'ALTER COLUMN',
                $query->quoteName($name),
                'SET DEFAULT ' . $query->validValue($default)
            );
        }

        $sql .= ";\n" . PostgresqlGrammar::comment(
            'COLUMN',
            $this->getName(),
            $name,
            $comment
        );

        DatabaseHelper::batchQuery($this->db, $sql);

        return $this->reset();
    }
723141
public function argument($type, $name) {
        $argument = new Argument($type, $name);
        $this->addArgument($argument);

        return $argument;
    }
710736
protected function addColumn($type, $name, array $parameters = array())
    {
        $this->getColumns();
        $attributes = array_merge(compact('type', 'name'), $parameters);
        $column = new VextFluent($attributes, $this);

        $this->columns[] = $this->current_column = $column;
        $this->current_name = $name;

        $column->validation(function (VextValidate $validate) use ($column) {
            $type = $column->getType();

            if ($length = $column->length) {
                if ($type === 'string') {
                    $validate->maxLength($length);
                }
            }
        });

        return $this->current_column;
    }
555829
public function addColumn($name, $type, $size = false) {
        return $this->table ? $this->table->column($name, $type, $size) : false;
    }
857839
public function setColumnType($name, $type)
    {
        $this->_columns[$name]['type'] = $type;
        $this->_typeMap[$name] = $type;

        return $this;
    }
408031
public function relationFieldName($type, $name) {
		$fieldName = Inflector::camelize($name, false);
		if (preg_match('/Many$/', $type)) {
			$fieldName = Inflector::pluralize($fieldName);
		} else {
			$fieldName = Inflector::singularize($fieldName);
		}
		return $fieldName;
	}
711227
public function primary($columns, $name = null)
    {
        $this->addCachePrimary($columns);

        return parent::primary($columns, $name);
    }
453013
private function generateIntFieldInput($name, $type, $column)
    {
        $fieldInput = "$name:$type";

        if ($column->getAutoincrement()) {
            $fieldInput .= ',true';
        }

        if ($column->getUnsigned()) {
            $fieldInput .= ',true';
        }

        return $fieldInput;
    }
401573
public function primary($columns, $name = null)
    {
        $columns = is_array($columns) ? $columns : [$columns];

        return $this->table->setPrimaryKey($columns, $name);
    }
1319326
public function get(string $name) : Type
    {
        if (! isset($this->instances[$name])) {
            throw DBALException::unknownColumnType($name);
        }

        return $this->instances[$name];
    }
1305278
public function getForeignKey($name)
    {
        if (!$this->hasForeignKey($name)) {
            throw SchemaException::tableForeignKeyDoesNotExist($this->getName(), $name);
        }

        return $this->foreignKeys[$name];
    }
152561
protected function getForeignKey($name)
    {
        if (strpos($name, '\\')) {
            $name = basename(str_replace('\\', '/', $name));
        }

        return Db::parseName($name) . '_id';
    }
250677
protected function loadTable($name)
	{
		$table=new CPgsqlTableSchema;
		$this->resolveTableNames($table,$name);
		if(!$this->findColumns($table))
			return null;
		$this->findConstraints($table);

		if(is_string($table->primaryKey) && isset($this->_sequences[$table->rawName.'.'.$table->primaryKey]))
			$table->sequenceName=$this->_sequences[$table->rawName.'.'.$table->primaryKey];
		elseif(is_array($table->primaryKey))
		{
			foreach($table->primaryKey as $pk)
			{
				if(isset($this->_sequences[$table->rawName.'.'.$pk]))
				{
					$table->sequenceName=$this->_sequences[$table->rawName.'.'.$pk];
					break;
				}
			}
		}

		return $table;
	}
543837
public function resolveDatabase($type, $name = null, $user = null, $pass = null, $host = null)
    {
        $database = $this->resolveDatabaseType($type);

        if ($name !== null) {
            $database->name = $name;
        }
        if ($user !== null) {
            $database->user = $user;
        }
        if ($pass !== null) {
            $database->pass = $pass;
        }
        if ($host !== null) {
            $database->host = $host;
        }

        return $database;
    }