807353cbe4
RepositoryImportSource::copyToFolder() called putContent() on the generic return type of Node::get(), which doesn't declare that method -- only File does. Existing-file overwrite during a per-user restore would have fatally errored at runtime; added an instanceof check and a resource leak fix (finally-close) while there. Also guarded getFileAsStream() against fopen() returning false. Everything else Psalm (strict level) currently flags is mechanical (missing `final` on leaf classes -- applied everywhere safe) or pre-existing array-shape/type gaps, captured in psalm-baseline.xml so CI fails only on new issues from here on, not the whole backlog at once.
73 lines
3.6 KiB
PHP
73 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
// SPDX-FileCopyrightText: 2026 Dillard Blom
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
namespace OCA\NgBackup\Migration;
|
|
|
|
use Closure;
|
|
use OCP\DB\ISchemaWrapper;
|
|
use OCP\DB\Types;
|
|
use OCP\Migration\IOutput;
|
|
use OCP\Migration\SimpleMigrationStep;
|
|
|
|
final class Version000001Date20261002000000 extends SimpleMigrationStep {
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
|
|
/** @var ISchemaWrapper $schema */
|
|
$schema = $schemaClosure();
|
|
|
|
if (!$schema->hasTable('ngb_targets')) {
|
|
$t = $schema->createTable('ngb_targets');
|
|
$t->addColumn('id', Types::BIGINT, ['autoincrement' => true, 'notnull' => true, 'unsigned' => true]);
|
|
$t->addColumn('name', Types::STRING, ['notnull' => true, 'length' => 64]);
|
|
$t->addColumn('backend', Types::STRING, ['notnull' => true, 'length' => 64]);
|
|
$t->addColumn('auth', Types::STRING, ['notnull' => true, 'length' => 64]);
|
|
// Backend/auth options as JSON, encrypted with ICrypto (they contain credentials).
|
|
$t->addColumn('options', Types::TEXT, ['notnull' => true]);
|
|
$t->addColumn('base_path', Types::STRING, ['notnull' => false, 'length' => 255, 'default' => '']);
|
|
$t->addColumn('repository_id', Types::STRING, ['notnull' => false, 'length' => 32]);
|
|
$t->addColumn('created_at', Types::BIGINT, ['notnull' => true, 'unsigned' => true]);
|
|
$t->setPrimaryKey(['id']);
|
|
$t->addUniqueIndex(['name'], 'ngb_targets_name');
|
|
}
|
|
|
|
if (!$schema->hasTable('ngb_runs')) {
|
|
$t = $schema->createTable('ngb_runs');
|
|
$t->addColumn('id', Types::BIGINT, ['autoincrement' => true, 'notnull' => true, 'unsigned' => true]);
|
|
$t->addColumn('target_id', Types::BIGINT, ['notnull' => true, 'unsigned' => true]);
|
|
$t->addColumn('kind', Types::STRING, ['notnull' => true, 'length' => 16]);
|
|
$t->addColumn('status', Types::STRING, ['notnull' => true, 'length' => 16]);
|
|
$t->addColumn('phase', Types::STRING, ['notnull' => true, 'length' => 32]);
|
|
// Resumable state (JSON). Large lists live in the repository, not here.
|
|
$t->addColumn('state', Types::TEXT, ['notnull' => true]);
|
|
$t->addColumn('stats', Types::TEXT, ['notnull' => false]);
|
|
$t->addColumn('error', Types::TEXT, ['notnull' => false]);
|
|
$t->addColumn('snapshot_id', Types::STRING, ['notnull' => false, 'length' => 32]);
|
|
$t->addColumn('started_at', Types::BIGINT, ['notnull' => true, 'unsigned' => true]);
|
|
$t->addColumn('updated_at', Types::BIGINT, ['notnull' => true, 'unsigned' => true]);
|
|
$t->addColumn('finished_at', Types::BIGINT, ['notnull' => false, 'unsigned' => true]);
|
|
$t->setPrimaryKey(['id']);
|
|
$t->addIndex(['target_id', 'status'], 'ngb_runs_target_status');
|
|
}
|
|
|
|
if (!$schema->hasTable('ngb_snapshots')) {
|
|
// Cache of the snapshots in each repository, for listing without reading the target.
|
|
$t = $schema->createTable('ngb_snapshots');
|
|
$t->addColumn('id', Types::BIGINT, ['autoincrement' => true, 'notnull' => true, 'unsigned' => true]);
|
|
$t->addColumn('target_id', Types::BIGINT, ['notnull' => true, 'unsigned' => true]);
|
|
$t->addColumn('snapshot_id', Types::STRING, ['notnull' => true, 'length' => 32]);
|
|
$t->addColumn('kind', Types::STRING, ['notnull' => true, 'length' => 16]);
|
|
$t->addColumn('label', Types::STRING, ['notnull' => false, 'length' => 255]);
|
|
$t->addColumn('created_at', Types::BIGINT, ['notnull' => true, 'unsigned' => true]);
|
|
$t->addColumn('files', Types::BIGINT, ['notnull' => false, 'unsigned' => true]);
|
|
$t->addColumn('bytes', Types::BIGINT, ['notnull' => false, 'unsigned' => true]);
|
|
$t->setPrimaryKey(['id']);
|
|
$t->addUniqueIndex(['target_id', 'snapshot_id'], 'ngb_snap_target_snap');
|
|
}
|
|
|
|
return $schema;
|
|
}
|
|
}
|