Skip to content

Commit

Permalink
use $schemaClosure in migration
Browse files Browse the repository at this point in the history
Signed-off-by: notEvil <[email protected]>
  • Loading branch information
notEvil committed Jul 9, 2023
1 parent ec0ab03 commit f5d5bbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/Db/TableManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,22 @@ public function resetWatch(): array {
*
* @psalm-return non-empty-list<string>
*/
public function createTables(): array {
public function createTables(?Schema $schema = null): array {
if ($schema === null) {
$schema = &$this->schema;

Check failure on line 161 in lib/Db/TableManager.php

View workflow job for this annotation

GitHub Actions / Psalm (stable27, 8.1)

UnsupportedPropertyReferenceUsage

lib/Db/TableManager.php:161:4: UnsupportedPropertyReferenceUsage: This reference cannot be analyzed by Psalm. (see https://psalm.dev/321)
}

$messages = [];

foreach (TableSchema::TABLES as $tableName => $columns) {
$tableName = $this->dbPrefix . $tableName;

if ($this->schema->hasTable($tableName)) {
$table = $this->schema->getTable($tableName);
if ($schema->hasTable($tableName)) {
$table = $schema->getTable($tableName);
$messages[] = 'Validating table ' . $table->getName();
$tableCreated = false;
} else {
$table = $this->schema->createTable($tableName);
$table = $schema->createTable($tableName);
$tableCreated = true;
$messages[] = 'Creating table ' . $table->getName();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Migration/Version050100Date20230515083001.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public function __construct(
*/
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
// Create tables, as defined in TableSchema or fix column definitions
$messages = $this->tableManager->createTables();
$this->tableManager->migrate();
$schema = $schemaClosure();
$messages = $this->tableManager->createTables($schema->getWrappedSchema());

Check failure on line 51 in lib/Migration/Version050100Date20230515083001.php

View workflow job for this annotation

GitHub Actions / Psalm (stable27, 8.1)

UndefinedInterfaceMethod

lib/Migration/Version050100Date20230515083001.php:51:58: UndefinedInterfaceMethod: Method OCP\DB\ISchemaWrapper::getWrappedSchema does not exist (see https://psalm.dev/181)

foreach ($messages as $message) {
$output->info('Polls - ' . $message);
};

return null;
return $schema;
}

/**
Expand Down

0 comments on commit f5d5bbf

Please sign in to comment.