|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace OCA\TimeTracker\Migration; |
| 6 | + |
| 7 | +use Closure; |
| 8 | +use OCP\DB\ISchemaWrapper; |
| 9 | +use OCP\DB\QueryBuilder\IQueryBuilder; |
| 10 | +use OCP\DB\Types; |
| 11 | +use OCP\Migration\IOutput; |
| 12 | +use OCP\Migration\SimpleMigrationStep; |
| 13 | + |
| 14 | +class Version000001Date20210719192031 extends SimpleMigrationStep { |
| 15 | + /** |
| 16 | + * @param IOutput $output |
| 17 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
| 18 | + * @param array $options |
| 19 | + * @return null|ISchemaWrapper |
| 20 | + */ |
| 21 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
| 22 | + /** @var ISchemaWrapper $schema */ |
| 23 | + $schema = $schemaClosure(); |
| 24 | + |
| 25 | + if ($schema->hasTable('timetracker_project')) { |
| 26 | + $table = $schema->getTable('timetracker_project'); |
| 27 | + if ($table->hasColumn('created_by_user_id')) { |
| 28 | + $schema->dropTable('timetracker_project'); |
| 29 | + $table = $schema->createTable('timetracker_project'); |
| 30 | + $table->addColumn('id', 'integer', [ |
| 31 | + 'autoincrement' => true, |
| 32 | + 'notnull' => true, |
| 33 | + ]); |
| 34 | + $table->addColumn('name', 'string', [ |
| 35 | + 'notnull' => true, |
| 36 | + 'length' => 64, |
| 37 | + ]); |
| 38 | + $table->addColumn('client_id', 'integer', [ |
| 39 | + 'notnull' => false, |
| 40 | + 'length' => 4, |
| 41 | + ]); |
| 42 | + $table->addColumn('created_by_user_uid', 'string', [ |
| 43 | + 'notnull' => true, |
| 44 | + 'length' => 128, |
| 45 | + ]); |
| 46 | + $table->addColumn('locked', 'integer', [ |
| 47 | + 'notnull' => false, |
| 48 | + 'default' => 0, |
| 49 | + 'length' => 4, |
| 50 | + ]); |
| 51 | + $table->addColumn('archived', 'integer', [ |
| 52 | + 'notnull' => false, |
| 53 | + 'default' => 0, |
| 54 | + 'length' => 4, |
| 55 | + ]); |
| 56 | + $table->addColumn('created_at', 'integer', [ |
| 57 | + 'notnull' => true, |
| 58 | + 'length' => 4, |
| 59 | + ]); |
| 60 | + $table->addColumn('color', 'string', [ |
| 61 | + 'notnull' => true, |
| 62 | + 'default' => '#ffffff', |
| 63 | + 'length' => 7, |
| 64 | + ]); |
| 65 | + |
| 66 | + $table->setPrimaryKey(['id']); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + if ($schema->hasTable('timetracker_timeline_entry')) { |
| 71 | + $table = $schema->getTable('timetracker_timeline_entry'); |
| 72 | + if ($table->hasColumn('user_id')) { |
| 73 | + $schema->dropTable('timetracker_timeline_entry'); |
| 74 | + $table = $schema->createTable('timetracker_timeline_entry'); |
| 75 | + $table->addColumn('id', 'integer', [ |
| 76 | + 'autoincrement' => true, |
| 77 | + 'notnull' => true, |
| 78 | + ]); |
| 79 | + $table->addColumn('timeline_id', 'integer', [ |
| 80 | + 'notnull' => false, |
| 81 | + 'length' => 4, |
| 82 | + ]); |
| 83 | + $table->addColumn('user_uid', 'text', [ |
| 84 | + 'notnull' => true, |
| 85 | + 'length' => 128, |
| 86 | + ]); |
| 87 | + $table->addColumn('name', 'text', [ |
| 88 | + 'notnull' => true, |
| 89 | + 'length' => 64, |
| 90 | + ]); |
| 91 | + $table->addColumn('project_name', 'text', [ |
| 92 | + 'notnull' => true, |
| 93 | + 'length' => 64, |
| 94 | + ]); |
| 95 | + $table->addColumn('client_name', 'text', [ |
| 96 | + 'notnull' => true, |
| 97 | + 'length' => 64, |
| 98 | + ]); |
| 99 | + $table->addColumn('time_interval', 'text', [ |
| 100 | + 'notnull' => true, |
| 101 | + 'length' => 64, |
| 102 | + ]); |
| 103 | + $table->addColumn('total_duration', 'text', [ |
| 104 | + 'notnull' => true, |
| 105 | + 'length' => 64, |
| 106 | + ]); |
| 107 | + $table->addColumn('created_at', 'integer', [ |
| 108 | + 'notnull' => true, |
| 109 | + 'length' => 4, |
| 110 | + ]); |
| 111 | + |
| 112 | + $table->setPrimaryKey(['id'], 'tt_t_e_id_idx'); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + return $schema; |
| 117 | + } |
| 118 | +} |
0 commit comments