2023-09-02 02:39:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\GroupfolderFilesystemSnapshots\Migration;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use OCP\DB\ISchemaWrapper;
|
|
|
|
use OCP\Migration\SimpleMigrationStep;
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
|
|
|
|
class Version100Date20230822153000 extends SimpleMigrationStep {
|
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
const TASKS_TABLE = "groupfolder_snapshots_tasks";
|
|
|
|
const RESULTS_TABLE = "groupfolder_snapshots_task_results";
|
2023-09-02 02:39:44 +02:00
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
/**
|
|
|
|
* @param IOutput $output
|
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
|
|
|
* @param array $options
|
|
|
|
* @return null|ISchemaWrapper
|
|
|
|
*/
|
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
|
|
|
|
/** @var ISchemaWrapper $schema */
|
|
|
|
$schema = $schemaClosure();
|
2023-09-02 02:39:44 +02:00
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
if (!$schema->hasTable(self::TASKS_TABLE)) {
|
|
|
|
$table = $schema->createTable(self::TASKS_TABLE);
|
|
|
|
$table->addColumn('id', 'integer', [
|
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$table->addColumn('user_id', 'string', [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 200,
|
|
|
|
]);
|
|
|
|
$table->addColumn('groupfolder_id', 'bigint', [
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$table->addColumn('relative_path', 'string', [
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$table->addColumn('snapshot_id', 'string', [
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$table->addColumn('timestamp', 'integer', [
|
2023-09-02 02:39:44 +02:00
|
|
|
'notnull' => true,
|
|
|
|
'default' => 0,
|
|
|
|
]);
|
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
$table->setPrimaryKey(['id']);
|
|
|
|
$table->addIndex(['user_id'], 'userid_index');
|
|
|
|
$table->addIndex(['groupfolder_id'], 'groupfolderid_index');
|
|
|
|
}
|
2023-09-02 02:39:44 +02:00
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
if (!$schema->hasTable(self::RESULTS_TABLE)) {
|
|
|
|
$table = $schema->createTable(self::RESULTS_TABLE);
|
|
|
|
$table->addColumn('id', 'integer', [
|
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$table->addColumn('task_id', 'integer', [
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
2023-09-02 02:39:44 +02:00
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
$table->addColumn('type', 'string', [
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
2023-09-02 02:39:44 +02:00
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
// Before
|
|
|
|
$table->addColumn('before_file_exists', 'boolean', [
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$table->addColumn('before_path', 'string', [
|
|
|
|
'notnull' => false,
|
|
|
|
'default' => '',
|
|
|
|
'length' => 200,
|
|
|
|
]);
|
|
|
|
$table->addColumn('before_size', 'integer', [
|
|
|
|
'notnull' => false,
|
|
|
|
'default' => 0
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Current
|
|
|
|
$table->addColumn('current_file_exists', 'boolean', [
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
|
|
|
$table->addColumn('current_path', 'string', [
|
|
|
|
'notnull' => false,
|
|
|
|
'default' => '',
|
|
|
|
'length' => 200,
|
|
|
|
]);
|
|
|
|
$table->addColumn('current_size', 'integer', [
|
|
|
|
'notnull' => false,
|
|
|
|
'default' => 0
|
|
|
|
]);
|
2023-09-02 02:39:44 +02:00
|
|
|
|
2024-01-24 20:22:02 +01:00
|
|
|
$table->addColumn('reverted', 'boolean', [
|
|
|
|
'default' => false,
|
|
|
|
]);
|
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
$table->setPrimaryKey(['id']);
|
|
|
|
$table->addIndex(['task_id'], 'taskid_index');
|
|
|
|
$table->addForeignKeyConstraint($schema->getTable(self::TASKS_TABLE), ['task_id'], ['id'], ['onDelete' => 'CASCADE'], 'results_taskid_fk');
|
|
|
|
}
|
2023-09-02 02:39:44 +02:00
|
|
|
|
2024-01-23 21:59:41 +01:00
|
|
|
return $schema;
|
|
|
|
}
|
2023-09-02 02:39:44 +02:00
|
|
|
}
|