Nextcloud-App/lib/Migration/Version000000Date20210918151800.php

116 lines
3.2 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace OCA\UPschooling\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version000000Date20210918151800 extends SimpleMigrationStep {
/**
* @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();
if (!$schema->hasTable('upschooling_tickets')) {
$table = $schema->createTable('upschooling_tickets');
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('matrix_control_room', 'string', [
'notnull' => true,
2021-09-19 14:55:30 +00:00
'length' => 200,
]);
$table->addColumn('matrix_assisted_user', 'string', [
'notnull' => true,
'length' => 200,
]);
$table->addColumn('matrix_helper_user', 'string', [
'notnull' => false,
'length' => 200,
// could be optimized by having a "localUser" with foreign key to users.id,
// but that could create consistency issues
]);
$table->addColumn('status', 'string', [
'notnull' => true,
2021-09-19 14:55:30 +00:00
'length' => 63,
]);
$table->addColumn('version', 'integer', [
'notnull' => true,
]);
$table->setPrimaryKey(['id']);
$table->addUniqueConstraint(['matrix_control_room'], 'upschooling_mx_room_id_uniq');
$table->addIndex(['matrix_control_room'], 'upschooling_mx_room_id_idx');
}
if (!$schema->hasTable('upschooling_users')) {
$table = $schema->createTable('upschooling_users');
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('matrix_user', 'string', [
'notnull' => true,
'length' => 200,
]);
$table->addColumn('matrix_token', 'string', [
'notnull' => true,
'length' => 200,
]);
$table->setPrimaryKey(['id']);
$table->addUniqueConstraint(['user_id'], 'upschooling_mx_user_nc_uniq');
$table->addUniqueConstraint(['matrix_user'], 'upschooling_mx_user_mx_uniq');
$table->addForeignKeyConstraint('users', ['user_id'], ['uid'], [], 'upschooling_mx_user_nc_fk');
}
if (!$schema->hasTable('upschooling_chats')) {
$table = $schema->createTable('upschooling_chats');
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('ticket_id', 'integer', [
'notnull' => true,
]);
$table->addColumn('matrix_room_id', 'string', [
'notnull' => true,
'length' => 200,
]);
$table->addColumn('matrix_helper_user', 'string', [
'notnull' => true,
'length' => 200,
]);
$table->addColumn('date_start', 'datetimetz', [
'notnull' => true,
]);
$table->addColumn('date_end', 'datetimetz', [
'notnull' => false,
]);
$table->addColumn('version', 'integer', [
'notnull' => true,
]);
$table->setPrimaryKey(['id']);
$table->addForeignKeyConstraint('upschooling_tickets', ['ticket_id'], ['id'], [], 'upschooling_tckt_id_fk');
}
return $schema;
}
}