Skip to content

Commit c5f722d

Browse files
committed
Check table consistency in migration that might cause issues during upgrades from very old versions
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent bedbe30 commit c5f722d

5 files changed

Lines changed: 92 additions & 48 deletions

File tree

lib/Db/Card.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
use Sabre\VObject\Component\VCalendar;
2929

3030
class Card extends RelationalEntity {
31+
public const TITLE_MAX_LENGTH = 255;
32+
3133
protected $title;
3234
protected $description;
3335
protected $descriptionPrev;

lib/Migration/Version1000Date20200306161713.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,7 @@
1010
use OCP\Migration\SimpleMigrationStep;
1111

1212
class Version1000Date20200306161713 extends SimpleMigrationStep {
13-
14-
/**
15-
* @param IOutput $output
16-
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
17-
* @param array $options
18-
*/
19-
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
20-
}
21-
22-
/**
23-
* @param IOutput $output
24-
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
25-
* @param array $options
26-
* @return null|ISchemaWrapper
27-
*/
28-
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
13+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
2914
/** @var ISchemaWrapper $schema */
3015
$schema = $schemaClosure();
3116

lib/Migration/Version1000Date20200308073933.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,7 @@
1313
* Auto-generated migration step: Please modify to your needs!
1414
*/
1515
class Version1000Date20200308073933 extends SimpleMigrationStep {
16-
17-
/**
18-
* @param IOutput $output
19-
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20-
* @param array $options
21-
*/
22-
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
23-
}
24-
25-
/**
26-
* @param IOutput $output
27-
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
28-
* @param array $options
29-
* @return null|ISchemaWrapper
30-
*/
31-
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
16+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
3217
/** @var ISchemaWrapper $schema */
3318
$schema = $schemaClosure();
3419

@@ -44,12 +29,4 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
4429

4530
return $schema;
4631
}
47-
48-
/**
49-
* @param IOutput $output
50-
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
51-
* @param array $options
52-
*/
53-
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
54-
}
5532
}

lib/Migration/Version10200Date20201111150114.php

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
use OCP\Migration\SimpleMigrationStep;
1111

1212
class Version10200Date20201111150114 extends SimpleMigrationStep {
13-
14-
15-
function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
16-
}
17-
1813
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
1914
/** @var ISchemaWrapper $schema */
2015
$schema = $schemaClosure();
@@ -28,9 +23,82 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
2823
}
2924
}
3025

31-
return $schema;
32-
}
26+
// Check consistency of the labels table when updating from a version < 0.6
27+
// git commit for database.xml change at b0eaae6705dbfb9ce834d4047912d3e34eaa157f
28+
$table = $schema->getTable('deck_labels');
29+
if (!$table->hasColumn('last_modified')) {
30+
$table->addColumn('last_modified', 'integer', [
31+
'notnull' => false,
32+
'default' => 0,
33+
'unsigned' => true,
34+
]);
35+
}
36+
37+
// Check consistency of the cards table when updating from a version < 0.5.1
38+
// git commit for database.xml change at dd104466d61e32f59552da183034522e04effe35
39+
$table = $schema->getTable('deck_cards');
40+
if (!$table->hasColumn('description_prev')) {
41+
$table->addColumn('description_prev', 'text', [
42+
'notnull' => false,
43+
]);
44+
}
45+
if (!$table->hasColumn('last_editor')) {
46+
$table->addColumn('last_editor', 'string', [
47+
'notnull' => false,
48+
'length' => 64,
49+
]);
50+
}
3351

34-
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
52+
// Check consistency of the cards table when updating from a version < 0.5.0
53+
// git commit for database.xml change at a068d6e1c6588662f0ea131e57f974238538eda6
54+
$table = $schema->getTable('deck_boards');
55+
if (!$table->hasColumn('last_modified')) {
56+
$table->addColumn('last_modified', 'integer', [
57+
'notnull' => false,
58+
'default' => 0,
59+
'unsigned' => true,
60+
]);
61+
}
62+
$table = $schema->getTable('deck_stacks');
63+
if (!$table->hasColumn('last_modified')) {
64+
$table->addColumn('last_modified', 'integer', [
65+
'notnull' => false,
66+
'default' => 0,
67+
'unsigned' => true,
68+
]);
69+
}
70+
71+
// Check consistency of the cards table when updating from a version < 0.5.0
72+
// git commit for database.xml change at ef4ce31c47a5ef70d1a4d00f2d4cd182ac067f2c
73+
$table = $schema->getTable('deck_stacks');
74+
if (!$table->hasColumn('deleted_at')) {
75+
$table->addColumn('deleted_at', 'bigint', [
76+
'notnull' => false,
77+
'length' => 8,
78+
'default' => 0,
79+
'unsigned' => true,
80+
]);
81+
}
82+
83+
// Check consistency of the cards table when updating from a version < 0.5.0
84+
// git commit for database.xml change at 2ef4b55af427d90412544e77916e9449db7dbbcd
85+
$table = $schema->getTable('deck_cards');
86+
if (!$table->hasColumn('deleted_at')) {
87+
$table->addColumn('deleted_at', 'bigint', [
88+
'notnull' => false,
89+
'length' => 8,
90+
'default' => 0,
91+
'unsigned' => true,
92+
]);
93+
}
94+
95+
$table = $schema->getTable('deck_cards');
96+
if ($table->getColumn('title')->getLength() !== 255) {
97+
$table->changeColumn('title', [
98+
'length' => 255
99+
]);
100+
}
101+
102+
return $schema;
35103
}
36104
}

lib/Service/CardService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ public function create($title, $stackId, $type, $order, $owner, $description = '
172172
throw new BadRequestException('title must be provided');
173173
}
174174

175+
if (mb_strlen($title) > Card::TITLE_MAX_LENGTH) {
176+
throw new BadRequestException('The title cannot exceed 255 characters');
177+
}
178+
175179
if (is_numeric($stackId) === false) {
176180
throw new BadRequestException('stack id must be a number');
177181
}
@@ -270,6 +274,10 @@ public function update($id, $title, $stackId, $type, $order = 0, $description =
270274
throw new BadRequestException('title must be provided');
271275
}
272276

277+
if (mb_strlen($title) > Card::TITLE_MAX_LENGTH) {
278+
throw new BadRequestException('The title cannot exceed 255 characters');
279+
}
280+
273281
if (is_numeric($stackId) === false) {
274282
throw new BadRequestException('stack id must be a number $$$');
275283
}
@@ -361,6 +369,10 @@ public function rename($id, $title) {
361369
throw new BadRequestException('title must be provided');
362370
}
363371

372+
if (mb_strlen($title) > Card::TITLE_MAX_LENGTH) {
373+
throw new BadRequestException('The title cannot exceed 255 characters');
374+
}
375+
364376
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
365377
if ($this->boardService->isArchived($this->cardMapper, $id)) {
366378
throw new StatusException('Operation not allowed. This board is archived.');

0 commit comments

Comments
 (0)