Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/schema/PhabricatorConfigSchemaQuery.php
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | foreach ($tables as $database_name => $database_tables) { | ||||
} | } | ||||
$server_schema->addDatabase($database_schema); | $server_schema->addDatabase($database_schema); | ||||
} | } | ||||
return $server_schema; | return $server_schema; | ||||
} | } | ||||
public function loadExpectedSchema() { | public function loadExpectedSchema() { | ||||
$databases = $this->getDatabaseNames(); | $databases = $this->getDatabaseNames(); | ||||
$api = $this->getAPI(); | $api = $this->getAPI(); | ||||
if ($api->isCharacterSetAvailable('utf8mb4')) { | if ($api->isCharacterSetAvailable('utf8mb4')) { | ||||
// If utf8mb4 is available, we use it with the utf8mb4_unicode_ci | // If utf8mb4 is available, we use it with the utf8mb4_unicode_ci | ||||
// collation. This is most correct, and will sort properly. | // collation. This is most correct, and will sort properly. | ||||
Show All 10 Lines | if ($api->isCharacterSetAvailable('utf8mb4')) { | ||||
// It's possible that strings will be truncated in the middle of a | // It's possible that strings will be truncated in the middle of a | ||||
// character on insert. We encourage users to set STRICT_ALL_TABLES | // character on insert. We encourage users to set STRICT_ALL_TABLES | ||||
// to prevent this. | // to prevent this. | ||||
$utf8_charset = 'binary'; | $utf8_charset = 'binary'; | ||||
$utf8_collate = 'binary'; | $utf8_collate = 'binary'; | ||||
} | } | ||||
$specs = id(new PhutilSymbolLoader()) | |||||
->setAncestorClass('PhabricatorConfigSchemaSpec') | |||||
->loadObjects(); | |||||
$server_schema = new PhabricatorConfigServerSchema(); | $server_schema = new PhabricatorConfigServerSchema(); | ||||
foreach ($databases as $database_name) { | foreach ($specs as $spec) { | ||||
$database_schema = id(new PhabricatorConfigDatabaseSchema()) | $spec->setUTF8Charset($utf8_charset); | ||||
->setName($database_name) | $spec->setUTF8Collate($utf8_collate); | ||||
->setCharacterSet($utf8_charset) | |||||
->setCollation($utf8_collate); | |||||
$server_schema->addDatabase($database_schema); | $spec->buildSchemata($server_schema); | ||||
} | } | ||||
return $server_schema; | return $server_schema; | ||||
} | } | ||||
public function buildComparisonSchema( | |||||
PhabricatorConfigServerSchema $expect, | |||||
PhabricatorConfigServerSchema $actual) { | |||||
$comp_server = $actual->newEmptyClone(); | |||||
$all_databases = $actual->getDatabases() + $expect->getDatabases(); | |||||
foreach ($all_databases as $database_name => $database_template) { | |||||
$actual_database = $actual->getDatabase($database_name); | |||||
$expect_database = $expect->getDatabase($database_name); | |||||
$issues = $this->compareSchemata($expect_database, $actual_database); | |||||
$comp_database = $database_template->newEmptyClone() | |||||
->setIssues($issues); | |||||
if (!$actual_database) { | |||||
$actual_database = $expect_database->newEmptyClone(); | |||||
} | |||||
if (!$expect_database) { | |||||
btrahan: is it possible to have neither of these initialized? | |||||
Not Done Inline ActionsOne or the other will always exist, because $database_name will only exist if at least one map has a corresponding database. epriestley: One or the other will always exist, because `$database_name` will only exist if at least one… | |||||
$expect_database = $actual_database->newEmptyClone(); | |||||
} | |||||
$all_tables = | |||||
$actual_database->getTables() + | |||||
$expect_database->getTables(); | |||||
foreach ($all_tables as $table_name => $table_template) { | |||||
$actual_table = $actual_database->getTable($table_name); | |||||
$expect_table = $expect_database->getTable($table_name); | |||||
$issues = $this->compareSchemata($expect_table, $actual_table); | |||||
$comp_table = $table_template->newEmptyClone() | |||||
->setIssues($issues); | |||||
if (!$actual_table) { | |||||
$actual_table = $expect_table->newEmptyClone(); | |||||
} | |||||
if (!$expect_table) { | |||||
$expect_table = $actual_table->newEmptyClone(); | |||||
} | |||||
$all_columns = | |||||
$actual_table->getColumns() + | |||||
$expect_table->getColumns(); | |||||
foreach ($all_columns as $column_name => $column_template) { | |||||
$actual_column = $actual_table->getColumn($column_name); | |||||
$expect_column = $expect_table->getColumn($column_name); | |||||
$issues = $this->compareSchemata($expect_column, $actual_column); | |||||
$comp_column = $column_template->newEmptyClone() | |||||
->setIssues($issues); | |||||
$comp_table->addColumn($comp_column); | |||||
} | |||||
$comp_database->addTable($comp_table); | |||||
} | |||||
$comp_server->addDatabase($comp_database); | |||||
} | |||||
return $comp_server; | |||||
} | |||||
private function compareSchemata( | |||||
PhabricatorConfigStorageSchema $expect = null, | |||||
PhabricatorConfigStorageSchema $actual = null) { | |||||
if (!$expect && !$actual) { | |||||
throw new Exception(pht('Can not compare two missing schemata!')); | |||||
} else if ($expect && !$actual) { | |||||
$issues = array(PhabricatorConfigStorageSchema::ISSUE_MISSING); | |||||
} else if ($actual && !$expect) { | |||||
$issues = array(PhabricatorConfigStorageSchema::ISSUE_SURPLUS); | |||||
} else { | |||||
$issues = $actual->compareTo($expect); | |||||
} | |||||
return $issues; | |||||
} | |||||
} | } |
is it possible to have neither of these initialized?