mail_calendar_sync/lib/Migration/Version1000Date20250209000000.php
Thomas Faour a9023d29d9 Working
2026-02-10 23:31:24 -05:00

149 lines
5.0 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;
class Version1000Date20250209000000 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
// User configuration table
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');
}
// Activity log table
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,
'comment' => 'ACCEPTED, DECLINED, TENTATIVE, CREATED, UPDATED, CANCELLED, ERROR',
]);
$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');
}
// Track which messages we have already processed
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,
'comment' => 'IMAP message-id header value',
]);
$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;
}
}