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

View File

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