148 lines
4.8 KiB
PHP
148 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\MailCalendarSync\Migration;
|
|
|
|
use Closure;
|
|
use OCP\DB\ISchemaWrapper;
|
|
use OCP\DB\Types;
|
|
use OCP\Migration\IOutput;
|
|
use OCP\Migration\SimpleMigrationStep;
|
|
|
|
/**
|
|
* Fresh migration that creates tables if they don't exist.
|
|
* Safe to run even if the original migration partially succeeded.
|
|
*/
|
|
class Version1003Date20250210000000 extends SimpleMigrationStep {
|
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
|
|
/** @var ISchemaWrapper $schema */
|
|
$schema = $schemaClosure();
|
|
|
|
if (!$schema->hasTable('mcs_config')) {
|
|
$table = $schema->createTable('mcs_config');
|
|
|
|
$table->addColumn('id', Types::BIGINT, [
|
|
'autoincrement' => true,
|
|
'notnull' => true,
|
|
'unsigned' => true,
|
|
]);
|
|
$table->addColumn('user_id', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 64,
|
|
]);
|
|
$table->addColumn('enabled', Types::SMALLINT, [
|
|
'notnull' => true,
|
|
'default' => 0,
|
|
'unsigned' => true,
|
|
]);
|
|
$table->addColumn('mail_account_id', Types::BIGINT, [
|
|
'notnull' => false,
|
|
'unsigned' => true,
|
|
]);
|
|
$table->addColumn('calendar_uri', Types::STRING, [
|
|
'notnull' => false,
|
|
'length' => 255,
|
|
]);
|
|
$table->addColumn('auto_accept', Types::SMALLINT, [
|
|
'notnull' => true,
|
|
'default' => 0,
|
|
'unsigned' => true,
|
|
]);
|
|
$table->addColumn('sync_interval', Types::INTEGER, [
|
|
'notnull' => true,
|
|
'default' => 600,
|
|
'unsigned' => true,
|
|
]);
|
|
$table->addColumn('created_at', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 32,
|
|
]);
|
|
$table->addColumn('updated_at', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 32,
|
|
]);
|
|
|
|
$table->setPrimaryKey(['id']);
|
|
$table->addUniqueIndex(['user_id'], 'mcs_config_user_idx');
|
|
}
|
|
|
|
if (!$schema->hasTable('mcs_log')) {
|
|
$table = $schema->createTable('mcs_log');
|
|
|
|
$table->addColumn('id', Types::BIGINT, [
|
|
'autoincrement' => true,
|
|
'notnull' => true,
|
|
'unsigned' => true,
|
|
]);
|
|
$table->addColumn('user_id', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 64,
|
|
]);
|
|
$table->addColumn('event_uid', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 512,
|
|
]);
|
|
$table->addColumn('event_summary', Types::STRING, [
|
|
'notnull' => false,
|
|
'length' => 512,
|
|
]);
|
|
$table->addColumn('action', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 64,
|
|
]);
|
|
$table->addColumn('attendee_email', Types::STRING, [
|
|
'notnull' => false,
|
|
'length' => 255,
|
|
]);
|
|
$table->addColumn('from_email', Types::STRING, [
|
|
'notnull' => false,
|
|
'length' => 255,
|
|
]);
|
|
$table->addColumn('message', Types::TEXT, [
|
|
'notnull' => false,
|
|
]);
|
|
$table->addColumn('created_at', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 32,
|
|
]);
|
|
|
|
$table->setPrimaryKey(['id']);
|
|
$table->addIndex(['user_id', 'created_at'], 'mcs_log_user_date_idx');
|
|
}
|
|
|
|
if (!$schema->hasTable('mcs_processed')) {
|
|
$table = $schema->createTable('mcs_processed');
|
|
|
|
$table->addColumn('id', Types::BIGINT, [
|
|
'autoincrement' => true,
|
|
'notnull' => true,
|
|
'unsigned' => true,
|
|
]);
|
|
$table->addColumn('user_id', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 64,
|
|
]);
|
|
$table->addColumn('mail_account_id', Types::BIGINT, [
|
|
'notnull' => true,
|
|
'unsigned' => true,
|
|
]);
|
|
$table->addColumn('message_id', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 512,
|
|
]);
|
|
$table->addColumn('processed_at', Types::STRING, [
|
|
'notnull' => true,
|
|
'length' => 32,
|
|
]);
|
|
|
|
$table->setPrimaryKey(['id']);
|
|
$table->addUniqueIndex(['user_id', 'mail_account_id', 'message_id'], 'mcs_proc_unique_idx');
|
|
$table->addIndex(['user_id'], 'mcs_proc_user_idx');
|
|
}
|
|
|
|
return $schema;
|
|
}
|
|
}
|