Skip to content

Commit ea6b4c6

Browse files
authored
Merge pull request #37004 from nextcloud/backport/36803/stable24
[stable24] [db]: Remove not supported column comments for SQLite
2 parents 5af2aa1 + 2f0c60d commit ea6b4c6

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

lib/private/DB/SQLiteMigrator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $conn
4040
$platform->registerDoctrineTypeMapping('smallint unsigned', 'integer');
4141
$platform->registerDoctrineTypeMapping('varchar ', 'string');
4242

43-
// with sqlite autoincrement columns is of type integer
4443
foreach ($targetSchema->getTables() as $table) {
4544
foreach ($table->getColumns() as $column) {
45+
// column comments are not supported on SQLite
46+
if ($column->getComment() !== null) {
47+
$column->setComment(null);
48+
}
49+
// with sqlite autoincrement columns is of type integer
4650
if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) {
4751
$column->setType(Type::getType('integer'));
4852
}

tests/lib/DB/MigratorTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,30 @@ public function testReservedKeywords() {
237237
$this->addToAssertionCount(1);
238238
}
239239

240+
/**
241+
* Test for nextcloud/server#36803
242+
*/
243+
public function testColumnCommentsInUpdate() {
244+
$startSchema = new Schema([], [], $this->getSchemaConfig());
245+
$table = $startSchema->createTable($this->tableName);
246+
$table->addColumn('id', 'integer', ['autoincrement' => true, 'comment' => 'foo']);
247+
$table->setPrimaryKey(['id']);
248+
249+
$endSchema = new Schema([], [], $this->getSchemaConfig());
250+
$table = $endSchema->createTable($this->tableName);
251+
$table->addColumn('id', 'integer', ['autoincrement' => true, 'comment' => 'foo']);
252+
// Assert adding comments on existing tables work (or at least does not throw)
253+
$table->addColumn('time', 'integer', ['comment' => 'unix-timestamp', 'notnull' => false]);
254+
$table->setPrimaryKey(['id']);
255+
256+
$migrator = $this->getMigrator();
257+
$migrator->migrate($startSchema);
258+
259+
$migrator->migrate($endSchema);
260+
261+
$this->addToAssertionCount(1);
262+
}
263+
240264
public function testAddingForeignKey() {
241265
$startSchema = new Schema([], [], $this->getSchemaConfig());
242266
$table = $startSchema->createTable($this->tableName);

0 commit comments

Comments
 (0)