<?php
namespace OCA\Chores\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
class Version000000Date20210212170000 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();
$teams = $schema->createTable('chores_teams');
$teams->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
]);
$teams->addColumn('team_name', 'string', [
'notnull' => true,
'length' => 200,
]);
$teams->addColumn('owner_user_id', 'string', [
'notnull' => true,
'length' => 200,
]);
$teams->addColumn('content', 'text', [
'notnull' => true,
'default' => '',
]);
$teams->setPrimaryKey(['id']);
$members = $schema->createTable('chores_team_members');
$members->addColumn('team_id', 'integer', [
'notnull' => true,
]);
$members->addColumn('member_user_id', 'string', [
'notnull' => true,
'length' => 200,
]);
$members->addColumn('points', 'integer', [
'notnull' => true,
'default' => 0,
]);
$members->setPrimaryKey(['team_id', 'member_user_id']);
$members->addForeignKeyConstraint($teams, ['team_id'], ['id'], ['onUpdate' => 'CASCADE']);
$chores = $schema->createTable('chores_chores');
$chores->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
]);
$chores->addColumn('name', 'string', [
'notnull' => true,
'length' => 200,
]);
$chores->addColumn('team_id', 'integer', [
'notnull' => true,
]);
$chores->addColumn('assignee_uid', 'string', [
'notnull' => true,
'length' => 200,
]);
$chores->addColumn('points', 'integer', [
'notnull' => true,
]);
$chores->addColumn('due', 'datetimetz_immutable', [
'notnull' => true,
]);
$chores->addColumn('repeat', 'string', [
'notnull' => true,
'length' => 200,
]);
$chores->setPrimaryKey(['id']);
$chores->addForeignKeyConstraint($teams, ['team_id'], ['id'], ['onUpdate' => 'CASCADE']);
$chores->addIndex(['team_id'], 'chores_chores_team_idx');
$worklog = $schema->createTable('chores_worklog');
$worklog->addColumn('id', 'guid', [
'notnull' => true,
]);
$worklog->addColumn('team_id', 'integer', [
'notnull' => true,
]);
$worklog->addColumn('chore_id', 'integer', [
'notnull' => true,
]);
$worklog->addColumn('done_timestamp', 'datetimetz_immutable', [
'notnull' => true,
]);
$worklog->addColumn('submit_timestamp', 'datetimetz_immutable', [
'notnull' => true,
]);
$worklog->addColumn('member_uid', 'string', [
'notnull' => true,
'length' => 200,
]);
$worklog->addColumn('points', 'integer', [
'notnull' => true,
]);
$worklog->setPrimaryKey(['id']);
$worklog->addForeignKeyConstraint($teams, ['team_id'], ['id'], ['onUpdate' => 'CASCADE']);
$worklog->addForeignKeyConstraint($chores, ['chore_id'], ['id'], ['onUpdate' => 'CASCADE']);
$worklog->addIndex(['team_id', 'submit_timestamp'], 'chores_worklog_team_ts_idx');
$invites = $schema->createTable('chores_invites');
$invites->addColumn('id', 'string', [
'notnull' => true,
]);
$invites->addColumn('team_id', 'integer', [
'notnull' => true,
]);
$invites->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 200,
]);
$invites->setPrimaryKey(['id']);
$invites->addForeignKeyConstraint($teams, ['team_id'], ['id'], ['onUpdate' => 'CASCADE']);
$invites->addIndex(['team_id'], 'chores_invites_team_idx');
$invites->addIndex(['user_id'], 'chores_invites_user_idx');
return $schema;
}
}