~cypheon/nextcloud-chores-app

ref: d19a6603c01e63c7545582e5ff313ef4aec0bf9f nextcloud-chores-app/lib/Migration/Version000000Date20210212170000.php -rw-r--r-- 4.4 KiB
d19a6603 — Johann Rudloff Make overdue sidebar badge dynamic, switch badges to `CounterBubble` component 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?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;
    }
}