Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable24] [db]: Remove not supported column comments for SQLite #37004

Merged
merged 2 commits into from Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/private/DB/SQLiteMigrator.php
Expand Up @@ -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'));
}
Expand Down
24 changes: 24 additions & 0 deletions tests/lib/DB/MigratorTest.php
Expand Up @@ -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);
Expand Down