From ba49c33d302f3e987fb735f507dd2995bdcc756b Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 22 Feb 2023 00:58:08 +0100 Subject: [PATCH 1/2] fix(DB): Remove not supported column comments when using SQLite Signed-off-by: Ferdinand Thiessen --- lib/private/DB/SQLiteMigrator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/private/DB/SQLiteMigrator.php b/lib/private/DB/SQLiteMigrator.php index 76138fee54521..351b6f3764093 100644 --- a/lib/private/DB/SQLiteMigrator.php +++ b/lib/private/DB/SQLiteMigrator.php @@ -40,9 +40,13 @@ protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $conn $platform->registerDoctrineTypeMapping('smallint unsigned', 'integer'); $platform->registerDoctrineTypeMapping('varchar ', 'string'); - // with sqlite autoincrement columns is of type integer foreach ($targetSchema->getTables() as $table) { foreach ($table->getColumns() as $column) { + // column comments are not supported on SQLite + if ($column->getComment() !== null) { + $column->setComment(null); + } + // with sqlite autoincrement columns is of type integer if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) { $column->setType(Type::getType('integer')); } From d91f27b0bd12fea11ed4c18ad0d6a3c92d40eda6 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 28 Feb 2023 10:29:10 +0100 Subject: [PATCH 2/2] tests(db): Add test case to ensure column comments work Signed-off-by: Ferdinand Thiessen --- tests/lib/DB/MigratorTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index af56730f9f63d..6a2b113a796d3 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -237,6 +237,30 @@ public function testReservedKeywords() { $this->addToAssertionCount(1); } + /** + * Test for nextcloud/server#36803 + */ + public function testColumnCommentsInUpdate() { + $startSchema = new Schema([], [], $this->getSchemaConfig()); + $table = $startSchema->createTable($this->tableName); + $table->addColumn('id', 'integer', ['autoincrement' => true, 'comment' => 'foo']); + $table->setPrimaryKey(['id']); + + $endSchema = new Schema([], [], $this->getSchemaConfig()); + $table = $endSchema->createTable($this->tableName); + $table->addColumn('id', 'integer', ['autoincrement' => true, 'comment' => 'foo']); + // Assert adding comments on existing tables work (or at least does not throw) + $table->addColumn('time', 'integer', ['comment' => 'unix-timestamp', 'notnull' => false]); + $table->setPrimaryKey(['id']); + + $migrator = $this->getMigrator(); + $migrator->migrate($startSchema); + + $migrator->migrate($endSchema); + + $this->addToAssertionCount(1); + } + public function testAddingForeignKey() { $startSchema = new Schema([], [], $this->getSchemaConfig()); $table = $startSchema->createTable($this->tableName);