2014-09-18 17:22:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhabricatorConfigStorageSchema extends Phobject {
|
|
|
|
|
|
|
|
const ISSUE_MISSING = 'missing';
|
Generate expected schemata for User/People tables
Summary:
Ref T1191. Some notes here:
- Drops the old LDAP and OAuth info tables. These were migrated to the ExternalAccount table a very long time ago.
- Separates surplus/missing keys from other types of surplus/missing things. In the long run, my plan is to have only two notice levels:
- Error: something we can't fix (missing database, table, or column; overlong key).
- Warning: something we can fix (surplus anything, missing key, bad column type, bad key columns, bad uniqueness, bad collation or charset).
- For now, retaining three levels is helpful in generating all the expected scheamta.
Test Plan:
- Saw ~200 issues resolve, leaving ~1,300.
- Grepped for removed tables.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T1191
Differential Revision: https://secure.phabricator.com/D10580
2014-10-01 16:36:47 +02:00
|
|
|
const ISSUE_MISSINGKEY = 'missingkey';
|
2014-09-18 17:22:54 +02:00
|
|
|
const ISSUE_SURPLUS = 'surplus';
|
Generate expected schemata for User/People tables
Summary:
Ref T1191. Some notes here:
- Drops the old LDAP and OAuth info tables. These were migrated to the ExternalAccount table a very long time ago.
- Separates surplus/missing keys from other types of surplus/missing things. In the long run, my plan is to have only two notice levels:
- Error: something we can't fix (missing database, table, or column; overlong key).
- Warning: something we can fix (surplus anything, missing key, bad column type, bad key columns, bad uniqueness, bad collation or charset).
- For now, retaining three levels is helpful in generating all the expected scheamta.
Test Plan:
- Saw ~200 issues resolve, leaving ~1,300.
- Grepped for removed tables.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T1191
Differential Revision: https://secure.phabricator.com/D10580
2014-10-01 16:36:47 +02:00
|
|
|
const ISSUE_SURPLUSKEY = 'surpluskey';
|
2014-09-18 17:22:54 +02:00
|
|
|
const ISSUE_CHARSET = 'charset';
|
|
|
|
const ISSUE_COLLATION = 'collation';
|
|
|
|
const ISSUE_COLUMNTYPE = 'columntype';
|
2014-09-18 17:32:21 +02:00
|
|
|
const ISSUE_NULLABLE = 'nullable';
|
|
|
|
const ISSUE_KEYCOLUMNS = 'keycolumns';
|
2014-09-19 20:46:30 +02:00
|
|
|
const ISSUE_UNIQUE = 'unique';
|
Fix almost all remaining schemata issues
Summary:
Ref T1191. This fixes nearly every remaining blocker for utf8mb4 -- primarily, overlong keys.
Remaining issue is https://secure.phabricator.com/T1191#77467
Test Plan: I'll annotate inline.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley, hach-que
Maniphest Tasks: T6099, T6129, T6133, T6134, T6150, T6148, T6147, T6146, T6105, T1191
Differential Revision: https://secure.phabricator.com/D10601
2014-10-01 17:18:36 +02:00
|
|
|
const ISSUE_LONGKEY = 'longkey';
|
2014-09-18 17:22:54 +02:00
|
|
|
const ISSUE_SUBWARN = 'subwarn';
|
|
|
|
const ISSUE_SUBFAIL = 'subfail';
|
2014-10-01 17:24:51 +02:00
|
|
|
const ISSUE_AUTOINCREMENT = 'autoincrement';
|
2014-11-04 13:42:05 +01:00
|
|
|
const ISSUE_UNKNOWN = 'unknown';
|
2016-01-21 21:59:19 +01:00
|
|
|
const ISSUE_ACCESSDENIED = 'accessdenied';
|
2016-11-24 18:00:53 +01:00
|
|
|
const ISSUE_ENGINE = 'engine';
|
2014-09-18 17:22:54 +02:00
|
|
|
|
|
|
|
const STATUS_OKAY = 'okay';
|
|
|
|
const STATUS_WARN = 'warn';
|
|
|
|
const STATUS_FAIL = 'fail';
|
|
|
|
|
|
|
|
private $issues = array();
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
abstract public function newEmptyClone();
|
|
|
|
abstract protected function compareToSimilarSchema(
|
|
|
|
PhabricatorConfigStorageSchema $expect);
|
|
|
|
abstract protected function getSubschemata();
|
|
|
|
|
|
|
|
public function compareTo(PhabricatorConfigStorageSchema $expect) {
|
|
|
|
if (get_class($expect) != get_class($this)) {
|
|
|
|
throw new Exception(pht('Classes must match to compare schemata!'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->getName() != $expect->getName()) {
|
|
|
|
throw new Exception(pht('Names must match to compare schemata!'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->compareToSimilarSchema($expect);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setName($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setIssues(array $issues) {
|
|
|
|
$this->issues = array_fuse($issues);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIssues() {
|
|
|
|
$issues = $this->issues;
|
|
|
|
|
|
|
|
foreach ($this->getSubschemata() as $sub) {
|
|
|
|
switch ($sub->getStatus()) {
|
|
|
|
case self::STATUS_WARN:
|
|
|
|
$issues[self::ISSUE_SUBWARN] = self::ISSUE_SUBWARN;
|
|
|
|
break;
|
|
|
|
case self::STATUS_FAIL:
|
|
|
|
$issues[self::ISSUE_SUBFAIL] = self::ISSUE_SUBFAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $issues;
|
|
|
|
}
|
|
|
|
|
2014-09-19 20:46:30 +02:00
|
|
|
public function getLocalIssues() {
|
|
|
|
return $this->issues;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:22:54 +02:00
|
|
|
public function hasIssue($issue) {
|
|
|
|
return (bool)idx($this->getIssues(), $issue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllIssues() {
|
|
|
|
$issues = $this->getIssues();
|
|
|
|
foreach ($this->getSubschemata() as $sub) {
|
|
|
|
$issues += $sub->getAllIssues();
|
|
|
|
}
|
|
|
|
return $issues;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStatus() {
|
|
|
|
$status = self::STATUS_OKAY;
|
|
|
|
foreach ($this->getAllIssues() as $issue) {
|
|
|
|
$issue_status = self::getIssueStatus($issue);
|
|
|
|
$status = self::getStrongestStatus($status, $issue_status);
|
|
|
|
}
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getIssueName($issue) {
|
|
|
|
switch ($issue) {
|
|
|
|
case self::ISSUE_MISSING:
|
|
|
|
return pht('Missing');
|
Generate expected schemata for User/People tables
Summary:
Ref T1191. Some notes here:
- Drops the old LDAP and OAuth info tables. These were migrated to the ExternalAccount table a very long time ago.
- Separates surplus/missing keys from other types of surplus/missing things. In the long run, my plan is to have only two notice levels:
- Error: something we can't fix (missing database, table, or column; overlong key).
- Warning: something we can fix (surplus anything, missing key, bad column type, bad key columns, bad uniqueness, bad collation or charset).
- For now, retaining three levels is helpful in generating all the expected scheamta.
Test Plan:
- Saw ~200 issues resolve, leaving ~1,300.
- Grepped for removed tables.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T1191
Differential Revision: https://secure.phabricator.com/D10580
2014-10-01 16:36:47 +02:00
|
|
|
case self::ISSUE_MISSINGKEY:
|
|
|
|
return pht('Missing Key');
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_SURPLUS:
|
|
|
|
return pht('Surplus');
|
Generate expected schemata for User/People tables
Summary:
Ref T1191. Some notes here:
- Drops the old LDAP and OAuth info tables. These were migrated to the ExternalAccount table a very long time ago.
- Separates surplus/missing keys from other types of surplus/missing things. In the long run, my plan is to have only two notice levels:
- Error: something we can't fix (missing database, table, or column; overlong key).
- Warning: something we can fix (surplus anything, missing key, bad column type, bad key columns, bad uniqueness, bad collation or charset).
- For now, retaining three levels is helpful in generating all the expected scheamta.
Test Plan:
- Saw ~200 issues resolve, leaving ~1,300.
- Grepped for removed tables.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T1191
Differential Revision: https://secure.phabricator.com/D10580
2014-10-01 16:36:47 +02:00
|
|
|
case self::ISSUE_SURPLUSKEY:
|
|
|
|
return pht('Surplus Key');
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_CHARSET:
|
2014-09-18 17:32:44 +02:00
|
|
|
return pht('Better Character Set Available');
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_COLLATION:
|
2014-09-18 17:32:44 +02:00
|
|
|
return pht('Better Collation Available');
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_COLUMNTYPE:
|
|
|
|
return pht('Wrong Column Type');
|
2014-09-18 17:32:21 +02:00
|
|
|
case self::ISSUE_NULLABLE:
|
|
|
|
return pht('Wrong Nullable Setting');
|
|
|
|
case self::ISSUE_KEYCOLUMNS:
|
|
|
|
return pht('Key on Wrong Columns');
|
2014-09-19 20:46:30 +02:00
|
|
|
case self::ISSUE_UNIQUE:
|
|
|
|
return pht('Key has Wrong Uniqueness');
|
Fix almost all remaining schemata issues
Summary:
Ref T1191. This fixes nearly every remaining blocker for utf8mb4 -- primarily, overlong keys.
Remaining issue is https://secure.phabricator.com/T1191#77467
Test Plan: I'll annotate inline.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley, hach-que
Maniphest Tasks: T6099, T6129, T6133, T6134, T6150, T6148, T6147, T6146, T6105, T1191
Differential Revision: https://secure.phabricator.com/D10601
2014-10-01 17:18:36 +02:00
|
|
|
case self::ISSUE_LONGKEY:
|
|
|
|
return pht('Key is Too Long');
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_SUBWARN:
|
|
|
|
return pht('Subschemata Have Warnings');
|
|
|
|
case self::ISSUE_SUBFAIL:
|
|
|
|
return pht('Subschemata Have Failures');
|
2014-10-01 17:24:51 +02:00
|
|
|
case self::ISSUE_AUTOINCREMENT:
|
|
|
|
return pht('Column has Wrong Autoincrement');
|
2014-11-04 13:42:05 +01:00
|
|
|
case self::ISSUE_UNKNOWN:
|
|
|
|
return pht('Column Has No Specification');
|
2016-01-21 21:59:19 +01:00
|
|
|
case self::ISSUE_ACCESSDENIED:
|
|
|
|
return pht('Access Denied');
|
2016-11-24 18:00:53 +01:00
|
|
|
case self::ISSUE_ENGINE:
|
|
|
|
return pht('Better Table Engine Available');
|
2014-09-18 17:22:54 +02:00
|
|
|
default:
|
|
|
|
throw new Exception(pht('Unknown schema issue "%s"!', $issue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getIssueDescription($issue) {
|
|
|
|
switch ($issue) {
|
|
|
|
case self::ISSUE_MISSING:
|
|
|
|
return pht('This schema is expected to exist, but does not.');
|
Generate expected schemata for User/People tables
Summary:
Ref T1191. Some notes here:
- Drops the old LDAP and OAuth info tables. These were migrated to the ExternalAccount table a very long time ago.
- Separates surplus/missing keys from other types of surplus/missing things. In the long run, my plan is to have only two notice levels:
- Error: something we can't fix (missing database, table, or column; overlong key).
- Warning: something we can fix (surplus anything, missing key, bad column type, bad key columns, bad uniqueness, bad collation or charset).
- For now, retaining three levels is helpful in generating all the expected scheamta.
Test Plan:
- Saw ~200 issues resolve, leaving ~1,300.
- Grepped for removed tables.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T1191
Differential Revision: https://secure.phabricator.com/D10580
2014-10-01 16:36:47 +02:00
|
|
|
case self::ISSUE_MISSINGKEY:
|
|
|
|
return pht('This key is expected to exist, but does not.');
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_SURPLUS:
|
|
|
|
return pht('This schema is not expected to exist.');
|
Generate expected schemata for User/People tables
Summary:
Ref T1191. Some notes here:
- Drops the old LDAP and OAuth info tables. These were migrated to the ExternalAccount table a very long time ago.
- Separates surplus/missing keys from other types of surplus/missing things. In the long run, my plan is to have only two notice levels:
- Error: something we can't fix (missing database, table, or column; overlong key).
- Warning: something we can fix (surplus anything, missing key, bad column type, bad key columns, bad uniqueness, bad collation or charset).
- For now, retaining three levels is helpful in generating all the expected scheamta.
Test Plan:
- Saw ~200 issues resolve, leaving ~1,300.
- Grepped for removed tables.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T1191
Differential Revision: https://secure.phabricator.com/D10580
2014-10-01 16:36:47 +02:00
|
|
|
case self::ISSUE_SURPLUSKEY:
|
|
|
|
return pht('This key is not expected to exist.');
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_CHARSET:
|
|
|
|
return pht('This schema can use a better character set.');
|
|
|
|
case self::ISSUE_COLLATION:
|
|
|
|
return pht('This schema can use a better collation.');
|
|
|
|
case self::ISSUE_COLUMNTYPE:
|
|
|
|
return pht('This schema can use a better column type.');
|
2014-09-18 17:32:21 +02:00
|
|
|
case self::ISSUE_NULLABLE:
|
|
|
|
return pht('This schema has the wrong nullable setting.');
|
|
|
|
case self::ISSUE_KEYCOLUMNS:
|
Fix almost all remaining schemata issues
Summary:
Ref T1191. This fixes nearly every remaining blocker for utf8mb4 -- primarily, overlong keys.
Remaining issue is https://secure.phabricator.com/T1191#77467
Test Plan: I'll annotate inline.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley, hach-que
Maniphest Tasks: T6099, T6129, T6133, T6134, T6150, T6148, T6147, T6146, T6105, T1191
Differential Revision: https://secure.phabricator.com/D10601
2014-10-01 17:18:36 +02:00
|
|
|
return pht('This key is on the wrong columns.');
|
2014-09-19 20:46:30 +02:00
|
|
|
case self::ISSUE_UNIQUE:
|
|
|
|
return pht('This key has the wrong uniqueness setting.');
|
Fix almost all remaining schemata issues
Summary:
Ref T1191. This fixes nearly every remaining blocker for utf8mb4 -- primarily, overlong keys.
Remaining issue is https://secure.phabricator.com/T1191#77467
Test Plan: I'll annotate inline.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley, hach-que
Maniphest Tasks: T6099, T6129, T6133, T6134, T6150, T6148, T6147, T6146, T6105, T1191
Differential Revision: https://secure.phabricator.com/D10601
2014-10-01 17:18:36 +02:00
|
|
|
case self::ISSUE_LONGKEY:
|
|
|
|
return pht('This key is too long for utf8mb4.');
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_SUBWARN:
|
|
|
|
return pht('Subschemata have setup warnings.');
|
|
|
|
case self::ISSUE_SUBFAIL:
|
|
|
|
return pht('Subschemata have setup failures.');
|
2014-10-01 17:24:51 +02:00
|
|
|
case self::ISSUE_AUTOINCREMENT:
|
|
|
|
return pht('This column has the wrong autoincrement setting.');
|
2014-11-04 13:42:05 +01:00
|
|
|
case self::ISSUE_UNKNOWN:
|
|
|
|
return pht('This column is missing a type specification.');
|
2016-11-24 18:00:53 +01:00
|
|
|
case self::ISSUE_ENGINE:
|
|
|
|
return pht('This table can use a better table engine.');
|
2014-09-18 17:22:54 +02:00
|
|
|
default:
|
|
|
|
throw new Exception(pht('Unknown schema issue "%s"!', $issue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getIssueStatus($issue) {
|
|
|
|
switch ($issue) {
|
|
|
|
case self::ISSUE_MISSING:
|
2016-01-21 21:59:19 +01:00
|
|
|
case self::ISSUE_ACCESSDENIED:
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_SURPLUS:
|
2014-10-01 16:59:44 +02:00
|
|
|
case self::ISSUE_NULLABLE:
|
2014-10-01 17:00:11 +02:00
|
|
|
case self::ISSUE_SUBFAIL:
|
2014-11-04 13:42:05 +01:00
|
|
|
case self::ISSUE_UNKNOWN:
|
2014-10-01 16:53:50 +02:00
|
|
|
return self::STATUS_FAIL;
|
2014-09-18 17:22:54 +02:00
|
|
|
case self::ISSUE_SUBWARN:
|
Generate expected schemata for User/People tables
Summary:
Ref T1191. Some notes here:
- Drops the old LDAP and OAuth info tables. These were migrated to the ExternalAccount table a very long time ago.
- Separates surplus/missing keys from other types of surplus/missing things. In the long run, my plan is to have only two notice levels:
- Error: something we can't fix (missing database, table, or column; overlong key).
- Warning: something we can fix (surplus anything, missing key, bad column type, bad key columns, bad uniqueness, bad collation or charset).
- For now, retaining three levels is helpful in generating all the expected scheamta.
Test Plan:
- Saw ~200 issues resolve, leaving ~1,300.
- Grepped for removed tables.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T1191
Differential Revision: https://secure.phabricator.com/D10580
2014-10-01 16:36:47 +02:00
|
|
|
case self::ISSUE_COLUMNTYPE:
|
2014-09-18 20:15:49 +02:00
|
|
|
case self::ISSUE_CHARSET:
|
|
|
|
case self::ISSUE_COLLATION:
|
2014-10-01 16:53:50 +02:00
|
|
|
case self::ISSUE_MISSINGKEY:
|
|
|
|
case self::ISSUE_SURPLUSKEY:
|
|
|
|
case self::ISSUE_UNIQUE:
|
2014-10-01 16:55:09 +02:00
|
|
|
case self::ISSUE_KEYCOLUMNS:
|
Fix almost all remaining schemata issues
Summary:
Ref T1191. This fixes nearly every remaining blocker for utf8mb4 -- primarily, overlong keys.
Remaining issue is https://secure.phabricator.com/T1191#77467
Test Plan: I'll annotate inline.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley, hach-que
Maniphest Tasks: T6099, T6129, T6133, T6134, T6150, T6148, T6147, T6146, T6105, T1191
Differential Revision: https://secure.phabricator.com/D10601
2014-10-01 17:18:36 +02:00
|
|
|
case self::ISSUE_LONGKEY:
|
2014-10-01 17:24:51 +02:00
|
|
|
case self::ISSUE_AUTOINCREMENT:
|
2016-11-24 18:00:53 +01:00
|
|
|
case self::ISSUE_ENGINE:
|
2014-10-01 17:00:11 +02:00
|
|
|
return self::STATUS_WARN;
|
2014-09-18 17:22:54 +02:00
|
|
|
default:
|
|
|
|
throw new Exception(pht('Unknown schema issue "%s"!', $issue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getStatusSeverity($status) {
|
|
|
|
switch ($status) {
|
|
|
|
case self::STATUS_FAIL:
|
2014-09-18 20:15:49 +02:00
|
|
|
return 2;
|
2014-10-01 17:00:11 +02:00
|
|
|
case self::STATUS_WARN:
|
2014-09-18 17:22:54 +02:00
|
|
|
return 1;
|
|
|
|
case self::STATUS_OKAY:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
throw new Exception(pht('Unknown schema status "%s"!', $status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getStrongestStatus($u, $v) {
|
|
|
|
$u_sev = self::getStatusSeverity($u);
|
|
|
|
$v_sev = self::getStatusSeverity($v);
|
|
|
|
|
|
|
|
if ($u_sev >= $v_sev) {
|
|
|
|
return $u;
|
|
|
|
} else {
|
|
|
|
return $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|