Skip to content

Commit 84568eb

Browse files
author
epriestley
committedSep 19, 2014
Generate expected schemata for Maniphest
Summary: Ref T1191. - Adds support for custom fields. - Adds support for partial indexes (indexes on a prefix of a column). - Drops old auxiliary storage table: this was moved to custom field storage about a year ago. - Drops old project table: this was moved to edges about two months ago. Test Plan: - Viewed web UI, saw fewer issues. - Used `grep` to verify no readers/writers for storage or project table. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T1191 Differential Revision: https://secure.phabricator.com/D10526
1 parent 7dabc21 commit 84568eb

16 files changed

+207
-7
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE {$NAMESPACE}_maniphest.maniphest_taskauxiliarystorage;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE {$NAMESPACE}_maniphest.maniphest_taskproject;

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@
918918
'ManiphestRemarkupRule' => 'applications/maniphest/remarkup/ManiphestRemarkupRule.php',
919919
'ManiphestReplyHandler' => 'applications/maniphest/mail/ManiphestReplyHandler.php',
920920
'ManiphestReportController' => 'applications/maniphest/controller/ManiphestReportController.php',
921+
'ManiphestSchemaSpec' => 'applications/maniphest/storage/ManiphestSchemaSpec.php',
921922
'ManiphestSearchIndexer' => 'applications/maniphest/search/ManiphestSearchIndexer.php',
922923
'ManiphestStatusConfigOptionType' => 'applications/maniphest/config/ManiphestStatusConfigOptionType.php',
923924
'ManiphestSubpriorityController' => 'applications/maniphest/controller/ManiphestSubpriorityController.php',
@@ -3800,6 +3801,7 @@
38003801
'ManiphestRemarkupRule' => 'PhabricatorObjectRemarkupRule',
38013802
'ManiphestReplyHandler' => 'PhabricatorMailReplyHandler',
38023803
'ManiphestReportController' => 'ManiphestController',
3804+
'ManiphestSchemaSpec' => 'PhabricatorConfigSchemaSpec',
38033805
'ManiphestSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
38043806
'ManiphestStatusConfigOptionType' => 'PhabricatorConfigJSONOptionType',
38053807
'ManiphestSubpriorityController' => 'ManiphestController',

‎src/applications/config/controller/PhabricatorConfigDatabaseStatusController.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ private function renderTable(
280280
$collation_issue = PhabricatorConfigStorageSchema::ISSUE_COLLATION;
281281
$nullable_issue = PhabricatorConfigStorageSchema::ISSUE_NULLABLE;
282282
$unique_issue = PhabricatorConfigStorageSchema::ISSUE_UNIQUE;
283+
$columns_issue = PhabricatorConfigStorageSchema::ISSUE_KEYCOLUMNS;
283284

284285
$database = $comp->getDatabase($database_name);
285286
if (!$database) {
@@ -377,13 +378,14 @@ private function renderTable(
377378
$status = $key->getStatus();
378379

379380
$size = 0;
380-
foreach ($key->getColumnNames() as $column_name) {
381+
foreach ($key->getColumnNames() as $column_spec) {
382+
list($column_name, $prefix) = $key->getKeyColumnAndPrefix($column_spec);
381383
$column = $table->getColumn($column_name);
382384
if (!$column) {
383385
$size = 0;
384386
break;
385387
}
386-
$size += $column->getKeyByteLength();
388+
$size += $column->getKeyByteLength($prefix);
387389
}
388390

389391
$size_formatted = null;
@@ -406,7 +408,9 @@ private function renderTable(
406408
$key_name.'/'),
407409
),
408410
$key_name),
409-
implode(', ', $key->getColumnNames()),
411+
$this->renderAttr(
412+
implode(', ', $key->getColumnNames()),
413+
$key->hasIssue($columns_issue)),
410414
$this->renderAttr(
411415
$this->renderBoolean($key->getUnique()),
412416
$key->hasIssue($unique_issue)),

‎src/applications/config/schema/PhabricatorConfigColumnSchema.php

+30-3
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,47 @@ public function getCharacterSet() {
5858
return $this->characterSet;
5959
}
6060

61-
public function getKeyByteLength() {
61+
public function getKeyByteLength($prefix = null) {
6262
$type = $this->getColumnType();
6363

6464
$matches = null;
6565
if (preg_match('/^varchar\((\d+)\)$/', $type, $matches)) {
6666
// For utf8mb4, each character requires 4 bytes.
67-
return ((int)$matches[1]) * 4;
67+
$size = (int)$matches[1];
68+
if ($prefix && $prefix < $size) {
69+
$size = $prefix;
70+
}
71+
return $size * 4;
6872
}
6973

7074
$matches = null;
7175
if (preg_match('/^char\((\d+)\)$/', $type, $matches)) {
7276
// We use char() only for fixed-length binary data, so its size
7377
// is always the column size.
74-
return ((int)$matches[1]);
78+
$size = (int)$matches[1];
79+
if ($prefix && $prefix < $size) {
80+
$size = $prefix;
81+
}
82+
return $size;
83+
}
84+
85+
// The "long..." types are arbitrarily long, so just use a big number to
86+
// get the point across. In practice, these should always index only a
87+
// prefix.
88+
if ($type == 'longtext') {
89+
$size = (1 << 16);
90+
if ($prefix && $prefix < $size) {
91+
$size = $prefix;
92+
}
93+
return $size * 4;
94+
}
95+
96+
if ($type == 'longblob') {
97+
$size = (1 << 16);
98+
if ($prefix && $prefix < $size) {
99+
$size = $prefix;
100+
}
101+
return $size * 1;
75102
}
76103

77104
switch ($type) {

‎src/applications/config/schema/PhabricatorConfigKeySchema.php

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ protected function getSubschemata() {
2828
return array();
2929
}
3030

31+
public function getKeyColumnAndPrefix($column_name) {
32+
$matches = null;
33+
if (preg_match('/^(.*)\((\d+)\)\z/', $column_name, $matches)) {
34+
return array($matches[1], (int)$matches[2]);
35+
} else {
36+
return array($column_name, null);
37+
}
38+
}
39+
3140
public function compareToSimilarSchema(
3241
PhabricatorConfigStorageSchema $expect) {
3342

‎src/applications/config/schema/PhabricatorConfigSchemaQuery.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,20 @@ public function loadActualSchema() {
115115
foreach ($keys as $key_name => $key_pieces) {
116116
$key_pieces = isort($key_pieces, 'Seq_in_index');
117117
$head = head($key_pieces);
118+
119+
// This handles string indexes which index only a prefix of a field.
120+
$column_names = array();
121+
foreach ($key_pieces as $piece) {
122+
$name = $piece['Column_name'];
123+
if ($piece['Sub_part']) {
124+
$name = $name.'('.$piece['Sub_part'].')';
125+
}
126+
$column_names[] = $name;
127+
}
128+
118129
$key_schema = id(new PhabricatorConfigKeySchema())
119130
->setName($key_name)
120-
->setColumnNames(ipull($key_pieces, 'Column_name'))
131+
->setColumnNames($column_names)
121132
->setUnique(!$head['Non_unique']);
122133

123134
$table_schema->addKey($key_schema);

‎src/applications/config/schema/PhabricatorConfigSchemaSpec.php

+18
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ protected function buildTransactionSchema(
5656
}
5757
}
5858

59+
protected function buildCustomFieldSchemata(
60+
PhabricatorLiskDAO $storage,
61+
array $indexes) {
62+
63+
$this->buildLiskObjectSchema($storage);
64+
foreach ($indexes as $index) {
65+
$this->buildLiskObjectSchema($index);
66+
}
67+
}
68+
5969
private function buildLiskObjectSchema(PhabricatorLiskDAO $object) {
6070
$this->buildRawSchema(
6171
$object->getApplicationName(),
@@ -123,6 +133,10 @@ protected function buildEdgeSchemata(PhabricatorLiskDAO $object) {
123133
array(
124134
'PRIMARY' => array(
125135
'columns' => array('src', 'type', 'dst'),
136+
'unique' => true,
137+
),
138+
'src' => array(
139+
'columns' => array('src', 'type', 'dateCreated', 'seq'),
126140
),
127141
));
128142

@@ -136,6 +150,7 @@ protected function buildEdgeSchemata(PhabricatorLiskDAO $object) {
136150
array(
137151
'PRIMARY' => array(
138152
'columns' => array('id'),
153+
'unique' => true,
139154
),
140155
));
141156
}
@@ -217,6 +232,9 @@ private function getDetailsForDataType($data_type) {
217232
case 'uint64':
218233
$column_type = 'bigint(20) unsigned';
219234
break;
235+
case 'sint64':
236+
$column_type = 'bigint(20)';
237+
break;
220238
case 'phid':
221239
case 'policy';
222240
$column_type = 'varchar(64)';

‎src/applications/maniphest/storage/ManiphestNameIndex.php

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ final class ManiphestNameIndex extends ManiphestDAO {
1212
public function getConfiguration() {
1313
return array(
1414
self::CONFIG_TIMESTAMPS => false,
15+
self::CONFIG_COLUMN_SCHEMA => array(
16+
'indexedObjectName' => 'text128',
17+
),
18+
self::CONFIG_KEY_SCHEMA => array(
19+
'key_phid' => array(
20+
'columns' => array('indexedObjectPHID'),
21+
'unique' => true,
22+
),
23+
'key_name' => array(
24+
'columns' => array('indexedObjectName'),
25+
),
26+
),
1527
) + parent::getConfiguration();
1628
}
1729

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
final class ManiphestSchemaSpec
4+
extends PhabricatorConfigSchemaSpec {
5+
6+
public function buildSchemata() {
7+
$this->buildLiskSchemata('ManiphestDAO');
8+
9+
$this->buildEdgeSchemata(new ManiphestTask());
10+
$this->buildTransactionSchema(
11+
new ManiphestTransaction(),
12+
new ManiphestTransactionComment());
13+
14+
$this->buildCustomFieldSchemata(
15+
new ManiphestCustomFieldStorage(),
16+
array(
17+
new ManiphestCustomFieldNumericIndex(),
18+
new ManiphestCustomFieldStringIndex(),
19+
));
20+
}
21+
22+
}

‎src/applications/maniphest/storage/ManiphestTask.php

+43
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,49 @@ public function getConfiguration() {
6767
'attached' => self::SERIALIZATION_JSON,
6868
'projectPHIDs' => self::SERIALIZATION_JSON,
6969
),
70+
self::CONFIG_COLUMN_SCHEMA => array(
71+
'ownerPHID' => 'phid?',
72+
'status' => 'text12',
73+
'priority' => 'uint32',
74+
'title' => 'text',
75+
'originalTitle' => 'text',
76+
'description' => 'text',
77+
'mailKey' => 'bytes20',
78+
'ownerOrdering' => 'text64?',
79+
'originalEmailSource' => 'text255?',
80+
'subpriority' => 'double',
81+
),
82+
self::CONFIG_KEY_SCHEMA => array(
83+
'key_phid' => null,
84+
'phid' => array(
85+
'columns' => array('phid'),
86+
'unique' => true,
87+
),
88+
'priority' => array(
89+
'columns' => array('priority', 'status'),
90+
),
91+
'status' => array(
92+
'columns' => array('status'),
93+
),
94+
'ownerPHID' => array(
95+
'columns' => array('ownerPHID', 'status'),
96+
),
97+
'authorPHID' => array(
98+
'columns' => array('authorPHID', 'status'),
99+
),
100+
'ownerOrdering' => array(
101+
'columns' => array('ownerOrdering'),
102+
),
103+
'priority_2' => array(
104+
'columns' => array('priority', 'subpriority'),
105+
),
106+
'key_dateCreated' => array(
107+
'columns' => array('dateCreated'),
108+
),
109+
'key_dateModified' => array(
110+
'columns' => array('dateModified'),
111+
),
112+
),
70113
) + parent::getConfiguration();
71114
}
72115

‎src/applications/transactions/storage/PhabricatorApplicationTransaction.php

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public function getConfiguration() {
113113
'contentSource' => 'text',
114114
'transactionType' => 'text32',
115115
),
116+
self::CONFIG_KEY_SCHEMA => array(
117+
'key_object' => array(
118+
'columns' => array('objectPHID'),
119+
),
120+
),
116121
) + parent::getConfiguration();
117122
}
118123

‎src/applications/transactions/storage/PhabricatorApplicationTransactionComment.php

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function getConfiguration() {
3838
self::CONFIG_KEY_SCHEMA => array(
3939
'key_version' => array(
4040
'columns' => array('transactionPHID', 'commentVersion'),
41+
'unique' => true,
4142
),
4243
),
4344
) + parent::getConfiguration();

‎src/infrastructure/customfield/storage/PhabricatorCustomFieldNumericIndexStorage.php

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
abstract class PhabricatorCustomFieldNumericIndexStorage
44
extends PhabricatorCustomFieldIndexStorage {
55

6+
public function getConfiguration() {
7+
return array(
8+
self::CONFIG_COLUMN_SCHEMA => array(
9+
'indexKey' => 'bytes12',
10+
'indexValue' => 'sint64',
11+
),
12+
self::CONFIG_KEY_SCHEMA => array(
13+
'key_join' => array(
14+
'columns' => array('objectPHID', 'indexKey', 'indexValue'),
15+
),
16+
'key_find' => array(
17+
'columns' => array('indexKey', 'indexValue'),
18+
),
19+
),
20+
) + parent::getConfiguration();
21+
}
22+
623
public function formatForInsert(AphrontDatabaseConnection $conn) {
724
return qsprintf(
825
$conn,

‎src/infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ abstract class PhabricatorCustomFieldStorage
1010
public function getConfiguration() {
1111
return array(
1212
self::CONFIG_TIMESTAMPS => false,
13+
self::CONFIG_COLUMN_SCHEMA => array(
14+
'fieldIndex' => 'bytes12',
15+
'fieldValue' => 'text',
16+
),
17+
self::CONFIG_KEY_SCHEMA => array(
18+
'objectPHID' => array(
19+
'columns' => array('objectPHID', 'fieldIndex'),
20+
'unique' => true,
21+
),
22+
),
1323
) + parent::getConfiguration();
1424
}
1525

‎src/infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
abstract class PhabricatorCustomFieldStringIndexStorage
44
extends PhabricatorCustomFieldIndexStorage {
55

6+
public function getConfiguration() {
7+
return array(
8+
self::CONFIG_COLUMN_SCHEMA => array(
9+
'indexKey' => 'bytes12',
10+
'indexValue' => 'text',
11+
),
12+
self::CONFIG_KEY_SCHEMA => array(
13+
'key_join' => array(
14+
'columns' => array('objectPHID', 'indexKey', 'indexValue(64)'),
15+
),
16+
'key_find' => array(
17+
'columns' => array('indexKey', 'indexValue(64)'),
18+
),
19+
),
20+
) + parent::getConfiguration();
21+
}
22+
623
public function formatForInsert(AphrontDatabaseConnection $conn) {
724
return qsprintf(
825
$conn,

0 commit comments

Comments
 (0)
Failed to load comments.