Path: blob/master/src/applications/config/schema/PhabricatorConfigColumnSchema.php
12256 views
<?php12final class PhabricatorConfigColumnSchema3extends PhabricatorConfigStorageSchema {45private $characterSet;6private $collation;7private $columnType;8private $dataType;9private $nullable;10private $autoIncrement;1112public function setAutoIncrement($auto_increment) {13$this->autoIncrement = $auto_increment;14return $this;15}1617public function getAutoIncrement() {18return $this->autoIncrement;19}2021public function setNullable($nullable) {22$this->nullable = $nullable;23return $this;24}2526public function getNullable() {27return $this->nullable;28}2930public function setColumnType($column_type) {31$this->columnType = $column_type;32return $this;33}3435public function getColumnType() {36return $this->columnType;37}3839protected function getSubschemata() {40return array();41}4243public function setDataType($data_type) {44$this->dataType = $data_type;45return $this;46}4748public function getDataType() {49return $this->dataType;50}5152public function setCollation($collation) {53$this->collation = $collation;54return $this;55}5657public function getCollation() {58return $this->collation;59}6061public function setCharacterSet($character_set) {62$this->characterSet = $character_set;63return $this;64}6566public function getCharacterSet() {67return $this->characterSet;68}6970public function hasSameColumnTypeAs(PhabricatorConfigColumnSchema $other) {71$u_type = $this->getColumnType();72$v_type = $other->getColumnType();7374if ($u_type === $v_type) {75return true;76}7778// See T13536. Display widths for integers were deprecated in MySQL 8.0.1779// and removed from some display contexts in or around 8.0.19. Older80// MySQL versions will report "int(10)"; newer versions will report "int".81// Accept these as equivalent.8283static $map = array(84'int(10) unsigned' => 'int unsigned',85'int(10)' => 'int',86'bigint(20) unsigned' => 'bigint unsigned',87'bigint(20)' => 'bigint',88);8990if (isset($map[$u_type])) {91$u_type = $map[$u_type];92}9394if (isset($map[$v_type])) {95$v_type = $map[$v_type];96}9798return ($u_type === $v_type);99}100101public function getKeyByteLength($prefix = null) {102$type = $this->getColumnType();103104$matches = null;105if (preg_match('/^(?:var)?char\((\d+)\)$/', $type, $matches)) {106// For utf8mb4, each character requires 4 bytes.107$size = (int)$matches[1];108if ($prefix && $prefix < $size) {109$size = $prefix;110}111return $size * 4;112}113114$matches = null;115if (preg_match('/^(?:var)?binary\((\d+)\)$/', $type, $matches)) {116// binary()/varbinary() store fixed-length binary data, so their size117// is always the column size.118$size = (int)$matches[1];119if ($prefix && $prefix < $size) {120$size = $prefix;121}122return $size;123}124125// The "long..." types are arbitrarily long, so just use a big number to126// get the point across. In practice, these should always index only a127// prefix.128if ($type == 'longtext') {129$size = (1 << 16);130if ($prefix && $prefix < $size) {131$size = $prefix;132}133return $size * 4;134}135136if ($type == 'longblob') {137$size = (1 << 16);138if ($prefix && $prefix < $size) {139$size = $prefix;140}141return $size * 1;142}143144switch ($type) {145case 'int(10) unsigned':146return 4;147}148149// TODO: Build this out to catch overlong indexes.150151return 0;152}153154protected function compareToSimilarSchema(155PhabricatorConfigStorageSchema $expect) {156157$issues = array();158159$type_unknown = PhabricatorConfigSchemaSpec::DATATYPE_UNKNOWN;160if ($expect->getColumnType() == $type_unknown) {161$issues[] = self::ISSUE_UNKNOWN;162} else {163if ($this->getCharacterSet() != $expect->getCharacterSet()) {164$issues[] = self::ISSUE_CHARSET;165}166167if ($this->getCollation() != $expect->getCollation()) {168$issues[] = self::ISSUE_COLLATION;169}170171if (!$this->hasSameColumnTypeAs($expect)) {172$issues[] = self::ISSUE_COLUMNTYPE;173}174175if ($this->getNullable() !== $expect->getNullable()) {176$issues[] = self::ISSUE_NULLABLE;177}178179if ($this->getAutoIncrement() !== $expect->getAutoIncrement()) {180$issues[] = self::ISSUE_AUTOINCREMENT;181}182}183184return $issues;185}186187public function newEmptyClone() {188$clone = clone $this;189return $clone;190}191192}193194195