|
1
|
|
|
<?php |
|
2
|
|
|
namespace OC\Migrations; |
|
3
|
|
|
|
|
4
|
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform; |
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
6
|
|
|
use Doctrine\DBAL\Types\Type; |
|
7
|
|
|
use OCP\Migration\ISchemaMigration; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Add new table for persistent locks |
|
11
|
|
|
*/ |
|
12
|
|
|
class Version20180607072706 implements ISchemaMigration { |
|
13
|
|
|
public function changeSchema(Schema $schema, array $options) { |
|
14
|
|
|
$prefix = $options['tablePrefix']; |
|
15
|
|
|
$table = $schema->createTable("{$prefix}persistent_locks"); |
|
16
|
|
|
$table->addColumn('id', Type::BIGINT, [ |
|
17
|
|
|
'autoincrement' => true, |
|
18
|
|
|
'unsigned' => true, |
|
19
|
|
|
'notnull' => true, |
|
20
|
|
|
]); |
|
21
|
|
|
$table->addColumn('file_id', Type::BIGINT, [ |
|
22
|
|
|
'notnull' => true, |
|
23
|
|
|
'length' => 20, |
|
24
|
|
|
'comment' => 'FK to fileid in table oc_file_cache' |
|
25
|
|
|
]); |
|
26
|
|
|
$table->addColumn('owner', Type::STRING, [ |
|
27
|
|
|
'notnull' => false, |
|
28
|
|
|
'length' => 100, |
|
29
|
|
|
'comment' => 'owner of the lock - just a human readable string' |
|
30
|
|
|
]); |
|
31
|
|
|
$table->addColumn('timeout', Type::INTEGER, [ |
|
32
|
|
|
'notnull' => true, |
|
33
|
|
|
'unsigned' => true, |
|
34
|
|
|
'comment' => 'timestamp when the lock expires' |
|
35
|
|
|
]); |
|
36
|
|
|
$table->addColumn('created_at', Type::INTEGER, [ |
|
37
|
|
|
'notnull' => true, |
|
38
|
|
|
'unsigned' => true, |
|
39
|
|
|
'comment' => 'timestamp when the lock was created' |
|
40
|
|
|
]); |
|
41
|
|
|
$table->addColumn('token', Type::STRING, [ |
|
42
|
|
|
'notnull' => true, |
|
43
|
|
|
'length' => 1024, |
|
44
|
|
|
'comment' => 'uuid for webdav locks - 1024 random chars for WOPI locks' |
|
45
|
|
|
]); |
|
46
|
|
|
$table->addColumn('token_hash', Type::STRING, [ |
|
47
|
|
|
'notnull' => true, |
|
48
|
|
|
'length' => 32, |
|
49
|
|
|
'comment' => 'md5(token)' |
|
50
|
|
|
]); |
|
51
|
|
|
// mysql specific |
|
52
|
|
|
$table->addColumn('scope', Type::SMALLINT, [ |
|
53
|
|
|
'notnull' => true, |
|
54
|
|
|
'comment' => '1 - exclusive, 2 - shared' |
|
55
|
|
|
]); |
|
56
|
|
|
$table->addColumn('depth', Type::SMALLINT, [ |
|
57
|
|
|
'notnull' => true, |
|
58
|
|
|
'comment' => '0, 1 or infinite' |
|
59
|
|
|
]); |
|
60
|
|
|
$table->addColumn('owner_account_id', Type::BIGINT, [ |
|
61
|
|
|
'notnull' => false, |
|
62
|
|
|
'unsigned' => true, |
|
63
|
|
|
'length' => 20, |
|
64
|
|
|
'comment' => 'owner of the lock - FK to account table' |
|
65
|
|
|
]); |
|
66
|
|
|
|
|
67
|
|
|
$table->setPrimaryKey(['id']); |
|
68
|
|
|
$table->addUniqueIndex(['token_hash']); |
|
69
|
|
|
$table->addForeignKeyConstraint("{$prefix}filecache", ['file_id'], ['fileid']); |
|
70
|
|
|
$table->addForeignKeyConstraint("{$prefix}accounts", ['owner_account_id'], ['id']); |
|
71
|
|
|
// TODO: cascade delete |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|