mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 13:30:55 +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',
|
'PhabricatorCacheManagementPurgeWorkflow' => 'applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php',
|
||||||
'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php',
|
'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php',
|
||||||
'PhabricatorCacheMarkupGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php',
|
'PhabricatorCacheMarkupGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php',
|
||||||
|
'PhabricatorCacheSchemaSpec' => 'applications/cache/storage/PhabricatorCacheSchemaSpec.php',
|
||||||
'PhabricatorCacheTTLGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php',
|
'PhabricatorCacheTTLGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php',
|
||||||
'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php',
|
'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php',
|
||||||
'PhabricatorCalendarApplication' => 'applications/calendar/application/PhabricatorCalendarApplication.php',
|
'PhabricatorCalendarApplication' => 'applications/calendar/application/PhabricatorCalendarApplication.php',
|
||||||
|
@ -4161,6 +4162,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorCacheManagementWorkflow',
|
'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorCacheManagementWorkflow',
|
||||||
'PhabricatorCacheManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
'PhabricatorCacheManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||||
'PhabricatorCacheMarkupGarbageCollector' => 'PhabricatorGarbageCollector',
|
'PhabricatorCacheMarkupGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||||
|
'PhabricatorCacheSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||||
'PhabricatorCacheTTLGarbageCollector' => 'PhabricatorGarbageCollector',
|
'PhabricatorCacheTTLGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||||
'PhabricatorCalendarApplication' => 'PhabricatorApplication',
|
'PhabricatorCalendarApplication' => 'PhabricatorApplication',
|
||||||
'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController',
|
'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(
|
self::CONFIG_BINARY => array(
|
||||||
'cacheData' => true,
|
'cacheData' => true,
|
||||||
),
|
),
|
||||||
|
self::CONFIG_COLUMN_SCHEMA => array(
|
||||||
|
'cacheKey' => 'text128',
|
||||||
|
),
|
||||||
|
self::CONFIG_KEY_SCHEMA => array(
|
||||||
|
'cacheKey' => array(
|
||||||
|
'columns' => array('cacheKey'),
|
||||||
|
),
|
||||||
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,13 @@ final class PhabricatorConfigColumnSchema
|
||||||
return ((int)$matches[1]) * 4;
|
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) {
|
switch ($type) {
|
||||||
case 'int(10) unsigned':
|
case 'int(10) unsigned':
|
||||||
return 4;
|
return 4;
|
||||||
|
|
|
@ -57,12 +57,23 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildLiskObjectSchema(PhabricatorLiskDAO $object) {
|
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();
|
$table = $this->newTable($table_name);
|
||||||
foreach ($cols as $name => $type) {
|
|
||||||
|
foreach ($columns as $name => $type) {
|
||||||
$details = $this->getDetailsForDataType($type);
|
$details = $this->getDetailsForDataType($type);
|
||||||
list($column_type, $charset, $collation, $nullable) = $details;
|
list($column_type, $charset, $collation, $nullable) = $details;
|
||||||
|
|
||||||
|
@ -76,7 +87,6 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
||||||
$table->addColumn($column);
|
$table->addColumn($column);
|
||||||
}
|
}
|
||||||
|
|
||||||
$keys = $object->getSchemaKeys();
|
|
||||||
foreach ($keys as $key_name => $key_spec) {
|
foreach ($keys as $key_name => $key_spec) {
|
||||||
$key = $this->newKey($key_name)
|
$key = $this->newKey($key_name)
|
||||||
->setColumnNames(idx($key_spec, 'columns', array()));
|
->setColumnNames(idx($key_spec, 'columns', array()));
|
||||||
|
@ -147,13 +157,21 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
||||||
case 'uint32':
|
case 'uint32':
|
||||||
$column_type = 'int(10) unsigned';
|
$column_type = 'int(10) unsigned';
|
||||||
break;
|
break;
|
||||||
|
case 'id64':
|
||||||
|
$column_type = 'bigint(20) unsigned';
|
||||||
|
break;
|
||||||
case 'phid':
|
case 'phid':
|
||||||
case 'policy';
|
case 'policy';
|
||||||
$column_type = 'varchar(64)';
|
$column_type = 'varchar(64)';
|
||||||
$charset = 'binary';
|
$charset = 'binary';
|
||||||
$collation = 'binary';
|
$collation = 'binary';
|
||||||
break;
|
break;
|
||||||
case 'blob':
|
case 'bytes12':
|
||||||
|
$column_type = 'char(12)';
|
||||||
|
$charset = 'binary';
|
||||||
|
$collation = 'binary';
|
||||||
|
break;
|
||||||
|
case 'bytes':
|
||||||
$column_type = 'longblob';
|
$column_type = 'longblob';
|
||||||
$charset = 'binary';
|
$charset = 'binary';
|
||||||
$collation = 'binary';
|
$collation = 'binary';
|
||||||
|
@ -173,6 +191,11 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
||||||
$charset = $this->getUTF8Charset();
|
$charset = $this->getUTF8Charset();
|
||||||
$collation = $this->getUTF8Collation();
|
$collation = $this->getUTF8Collation();
|
||||||
break;
|
break;
|
||||||
|
case 'text16':
|
||||||
|
$column_type = 'varchar(16)';
|
||||||
|
$charset = $this->getUTF8Charset();
|
||||||
|
$collation = $this->getUTF8Collation();
|
||||||
|
break;
|
||||||
case 'text12':
|
case 'text12':
|
||||||
$column_type = 'varchar(12)';
|
$column_type = 'varchar(12)';
|
||||||
$charset = $this->getUTF8Charset();
|
$charset = $this->getUTF8Charset();
|
||||||
|
|
|
@ -1734,7 +1734,7 @@ abstract class LiskDAO {
|
||||||
|
|
||||||
$serialization_map = array(
|
$serialization_map = array(
|
||||||
self::SERIALIZATION_JSON => 'text',
|
self::SERIALIZATION_JSON => 'text',
|
||||||
self::SERIALIZATION_PHP => 'blob',
|
self::SERIALIZATION_PHP => 'bytes',
|
||||||
);
|
);
|
||||||
|
|
||||||
$builtin = array(
|
$builtin = array(
|
||||||
|
|
Loading…
Reference in a new issue