Completed
Push — master ( 24a68b...bc84ac )
by Thomas
22:37 queued 09:54
created

Version20180607072706   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B changeSchema() 0 60 1
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