mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 21:10:56 +01:00
Generate reasonable expected schemata for Cache tables
Summary: Ref T1191. Notable: - Rename `blob` to `bytes` for clarity. - Introduce raw schema specs. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T1191 Differential Revision: https://secure.phabricator.com/D10501
This commit is contained in:
parent
0f73b15a70
commit
9b63f84ff9
6 changed files with 78 additions and 7 deletions
|
@ -1277,6 +1277,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCacheManagementPurgeWorkflow' => 'applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php',
|
||||
'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php',
|
||||
'PhabricatorCacheMarkupGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php',
|
||||
'PhabricatorCacheSchemaSpec' => 'applications/cache/storage/PhabricatorCacheSchemaSpec.php',
|
||||
'PhabricatorCacheTTLGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php',
|
||||
'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php',
|
||||
'PhabricatorCalendarApplication' => 'applications/calendar/application/PhabricatorCalendarApplication.php',
|
||||
|
@ -4161,6 +4162,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorCacheManagementWorkflow',
|
||||
'PhabricatorCacheManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'PhabricatorCacheMarkupGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||
'PhabricatorCacheSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'PhabricatorCacheTTLGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||
'PhabricatorCalendarApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController',
|
||||
|
|
31
src/applications/cache/storage/PhabricatorCacheSchemaSpec.php
vendored
Normal file
31
src/applications/cache/storage/PhabricatorCacheSchemaSpec.php
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCacheSchemaSpec extends PhabricatorConfigSchemaSpec {
|
||||
|
||||
public function buildSchemata() {
|
||||
$this->buildLiskSchemata('PhabricatorCacheDAO');
|
||||
|
||||
$this->buildRawSchema(
|
||||
'cache',
|
||||
id(new PhabricatorKeyValueDatabaseCache())->getTableName(),
|
||||
array(
|
||||
'id' => 'id64',
|
||||
'cacheKeyHash' => 'bytes12',
|
||||
'cacheKey' => 'text128',
|
||||
'cacheFormat' => 'text16',
|
||||
'cacheData' => 'bytes',
|
||||
'cacheCreated' => 'epoch',
|
||||
'cacheExpires' => 'epoch?',
|
||||
),
|
||||
array(
|
||||
'PRIMARY' => array(
|
||||
'columns' => array('id'),
|
||||
),
|
||||
'key_cacheKeyHash' => array(
|
||||
'columns' => array('cacheKeyHash'),
|
||||
),
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,14 @@ final class PhabricatorMarkupCache extends PhabricatorCacheDAO {
|
|||
self::CONFIG_BINARY => array(
|
||||
'cacheData' => true,
|
||||
),
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'cacheKey' => 'text128',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'cacheKey' => array(
|
||||
'columns' => array('cacheKey'),
|
||||
),
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,13 @@ final class PhabricatorConfigColumnSchema
|
|||
return ((int)$matches[1]) * 4;
|
||||
}
|
||||
|
||||
$matches = null;
|
||||
if (preg_match('/^char\((\d+)\)$/', $type, $matches)) {
|
||||
// We use char() only for fixed-length binary data, so its size
|
||||
// is always the column size.
|
||||
return ((int)$matches[1]);
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'int(10) unsigned':
|
||||
return 4;
|
||||
|
|
|
@ -57,12 +57,23 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
|||
}
|
||||
|
||||
private function buildLiskObjectSchema(PhabricatorLiskDAO $object) {
|
||||
$database = $this->getDatabase($object->getApplicationName());
|
||||
$this->buildRawSchema(
|
||||
$object->getApplicationName(),
|
||||
$object->getTableName(),
|
||||
$object->getSchemaColumns(),
|
||||
$object->getSchemaKeys());
|
||||
}
|
||||
|
||||
$table = $this->newTable($object->getTableName());
|
||||
protected function buildRawSchema(
|
||||
$database_name,
|
||||
$table_name,
|
||||
array $columns,
|
||||
array $keys) {
|
||||
$database = $this->getDatabase($database_name);
|
||||
|
||||
$cols = $object->getSchemaColumns();
|
||||
foreach ($cols as $name => $type) {
|
||||
$table = $this->newTable($table_name);
|
||||
|
||||
foreach ($columns as $name => $type) {
|
||||
$details = $this->getDetailsForDataType($type);
|
||||
list($column_type, $charset, $collation, $nullable) = $details;
|
||||
|
||||
|
@ -76,7 +87,6 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
|||
$table->addColumn($column);
|
||||
}
|
||||
|
||||
$keys = $object->getSchemaKeys();
|
||||
foreach ($keys as $key_name => $key_spec) {
|
||||
$key = $this->newKey($key_name)
|
||||
->setColumnNames(idx($key_spec, 'columns', array()));
|
||||
|
@ -147,13 +157,21 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
|||
case 'uint32':
|
||||
$column_type = 'int(10) unsigned';
|
||||
break;
|
||||
case 'id64':
|
||||
$column_type = 'bigint(20) unsigned';
|
||||
break;
|
||||
case 'phid':
|
||||
case 'policy';
|
||||
$column_type = 'varchar(64)';
|
||||
$charset = 'binary';
|
||||
$collation = 'binary';
|
||||
break;
|
||||
case 'blob':
|
||||
case 'bytes12':
|
||||
$column_type = 'char(12)';
|
||||
$charset = 'binary';
|
||||
$collation = 'binary';
|
||||
break;
|
||||
case 'bytes':
|
||||
$column_type = 'longblob';
|
||||
$charset = 'binary';
|
||||
$collation = 'binary';
|
||||
|
@ -173,6 +191,11 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
|||
$charset = $this->getUTF8Charset();
|
||||
$collation = $this->getUTF8Collation();
|
||||
break;
|
||||
case 'text16':
|
||||
$column_type = 'varchar(16)';
|
||||
$charset = $this->getUTF8Charset();
|
||||
$collation = $this->getUTF8Collation();
|
||||
break;
|
||||
case 'text12':
|
||||
$column_type = 'varchar(12)';
|
||||
$charset = $this->getUTF8Charset();
|
||||
|
|
|
@ -1734,7 +1734,7 @@ abstract class LiskDAO {
|
|||
|
||||
$serialization_map = array(
|
||||
self::SERIALIZATION_JSON => 'text',
|
||||
self::SERIALIZATION_PHP => 'blob',
|
||||
self::SERIALIZATION_PHP => 'bytes',
|
||||
);
|
||||
|
||||
$builtin = array(
|
||||
|
|
Loading…
Reference in a new issue