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

Migration to delete entries in properties table with null value for fileid column and restrict null value in properties table #36084

Merged
merged 1 commit into from Sep 6, 2019
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
62 changes: 62 additions & 0 deletions apps/dav/appinfo/Migrations/Version20190823065724.php
@@ -0,0 +1,62 @@
<?php
/**
* @author Sujith Haridasan <sharidasan@owncloud.com>
*
* @copyright Copyright (c) 2019, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\dav\Migrations;

use Doctrine\DBAL\Schema\Schema;
use OCP\IDBConnection;
use OCP\Migration\ISchemaMigration;

/**
* Add NULL constraint to fileid column for properties table.
* The fileid column should not accept null values in the properties table.
*/
class Version20190823065724 implements ISchemaMigration {
/** @var IDBConnection */
private $dbConnection;

public function __construct(IDBConnection $dbConnection) {
$this->dbConnection = $dbConnection;
}

public function changeSchema(Schema $schema, array $options) {
$prefix = $options['tablePrefix'];

$table = $schema->getTable("${prefix}properties");
$column = $table->getColumn('fileid');
/**
* If the fileid column's notnull is set to false then
* make sure before altering the column, that no entry
* in the table has fileid with null. Else the migration
* would fail. The below check does the same.
*/
if ($column->getNotnull() !== true) {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('properties')
->where($qb->expr()->isNull('fileid'));
$qb->execute();

$table->changeColumn('fileid', [
'notnull' => true,
]);
}
}
}
2 changes: 1 addition & 1 deletion apps/dav/appinfo/info.xml
Expand Up @@ -5,7 +5,7 @@
<description>ownCloud WebDAV endpoint</description>
<licence>AGPL</licence>
<author>owncloud.org</author>
<version>0.4.0</version>
<version>0.5.0</version>
<default_enable/>
<use-migrations>true</use-migrations>
<types>
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/Command/Apps/AppsListTest.php
Expand Up @@ -58,9 +58,9 @@ public function testCommandInput($input, $expectedOutput) {
public function providesAppIds() {
return [
[[], '- files: 1.5'],
[['--shipped' => 'true'], '- dav: 0.4.0'],
[['--shipped' => 'true'], '- dav: 0.5.0'],
[['--shipped' => 'false'], '- comments:'],
[['search-pattern' => 'dav'], '- dav: 0.4.0']
[['search-pattern' => 'dav'], '- dav: 0.5.0']
];
}
}