fix missing value and run against empty tables in migration script

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2019-08-28 23:56:21 +02:00
parent 4c717884e3
commit 54bdc95cc1
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 17 additions and 15 deletions

View File

@ -58,7 +58,7 @@ class PopulateNewlyIntroducedDatabaseFields implements IRepairStep {
$qb = $this->dbc->getQueryBuilder(); $qb = $this->dbc->getQueryBuilder();
$qb->update('flow_operations') $qb->update('flow_operations')
->set('entity', File::class) ->set('entity', $qb->createNamedParameter(File::class))
->where($qb->expr()->emptyString('entity')) ->where($qb->expr()->emptyString('entity'))
->execute(); ->execute();
@ -70,8 +70,8 @@ class PopulateNewlyIntroducedDatabaseFields implements IRepairStep {
$insertQuery = $qb->insert('flow_operations_scope'); $insertQuery = $qb->insert('flow_operations_scope');
while($id = $ids->fetchColumn(0)) { while($id = $ids->fetchColumn(0)) {
$insertQuery->values(['operation_id' => $qb->createNamedParameter($id), 'type' => IManager::SCOPE_ADMIN]); $insertQuery->values(['operation_id' => $qb->createNamedParameter($id), 'type' => IManager::SCOPE_ADMIN]);
$insertQuery->execute();
} }
$insertQuery->execute();
} }
protected function getIdsWithoutScope(): Statement { protected function getIdsWithoutScope(): Statement {

View File

@ -70,13 +70,11 @@ class Version2019Date20190808074233 extends SimpleMigrationStep {
$table->addColumn('operation', Type::TEXT, [ $table->addColumn('operation', Type::TEXT, [
'notnull' => false, 'notnull' => false,
]); ]);
$this->addEntityColumns($table); $this->ensureEntityColumns($table);
$table->setPrimaryKey(['id']); $table->setPrimaryKey(['id']);
} else { } else {
$table = $schema->getTable('flow_operations'); $table = $schema->getTable('flow_operations');
if(!$table->hasColumn('entity')) { $this->ensureEntityColumns($table);
$this->addEntityColumns($table);
}
} }
if (!$schema->hasTable('flow_operations_scope')) { if (!$schema->hasTable('flow_operations_scope')) {
@ -105,14 +103,18 @@ class Version2019Date20190808074233 extends SimpleMigrationStep {
return $schema; return $schema;
} }
protected function addEntityColumns(Table $table) { protected function ensureEntityColumns(Table $table) {
$table->addColumn('entity', Type::STRING, [ if(!$table->hasColumn('entity')) {
'notnull' => true, $table->addColumn('entity', Type::STRING, [
'length' => 256, 'notnull' => true,
]); 'length' => 256,
$table->addColumn('events', Type::TEXT, [ ]);
'notnull' => true, }
'default' => '[]', if(!$table->hasColumn('events')) {
]); $table->addColumn('events', Type::TEXT, [
'notnull' => true,
'default' => '[]',
]);
}
} }
} }