Fix db schema

This commit is contained in:
Robin Appelman 2015-07-16 12:55:28 +02:00
parent 86acd535c2
commit 96a9d171b3
5 changed files with 44 additions and 12 deletions

View File

@ -1185,10 +1185,20 @@
<!--
Table for storing high-level locking
-->
<name>*dbprefix*locks</name>
<name>*dbprefix*file_locks</name>
<declaration>
<field>
<name>id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<unsigned>true</unsigned>
<length>4</length>
<autoincrement>1</autoincrement>
</field>
<field>
<name>lock</name>
<type>integer</type>
@ -1204,9 +1214,24 @@
<length>64</length>
</field>
<field>
<name>ttl</name>
<type>integer</type>
<notnull>true</notnull>
<length>4</length>
</field>
<index>
<primary>true</primary>
<unique>true</unique>
<name>lock_id_index</name>
<field>
<name>id</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<unique>true</unique>
<name>lock_path_index</name>
<field>
@ -1215,6 +1240,14 @@
</field>
</index>
<index>
<name>lock_ttl_index</name>
<field>
<name>ttl</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>

View File

@ -1,8 +1,6 @@
<?php
/**
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <icewind@owncloud.com>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0

View File

@ -38,7 +38,7 @@ class DBLockingProvider extends AbstractLockingProvider {
}
protected function initLockField($path) {
$this->connection->insertIfNotExist('*PREFIX*locks', ['path' => $path, 'lock' => 0], ['path']);
$this->connection->insertIfNotExist('*PREFIX*file_locks', ['path' => $path, 'lock' => 0], ['path']);
}
/**
@ -47,7 +47,7 @@ class DBLockingProvider extends AbstractLockingProvider {
* @return bool
*/
public function isLocked($path, $type) {
$query = $this->connection->prepare('SELECT `lock` from `*PREFIX*locks` WHERE `path` = ?');
$query = $this->connection->prepare('SELECT `lock` from `*PREFIX*file_locks` WHERE `path` = ?');
$query->execute([$path]);
$lockValue = (int)$query->fetchColumn();
if ($type === self::LOCK_SHARED) {
@ -68,12 +68,12 @@ class DBLockingProvider extends AbstractLockingProvider {
$this->initLockField($path);
if ($type === self::LOCK_SHARED) {
$result = $this->connection->executeUpdate(
'UPDATE `*PREFIX*locks` SET `lock` = `lock` + 1 WHERE `path` = ? AND `lock` >= 0',
'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` + 1 WHERE `path` = ? AND `lock` >= 0',
[$path]
);
} else {
$result = $this->connection->executeUpdate(
'UPDATE `*PREFIX*locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 0',
'UPDATE `*PREFIX*file_locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 0',
[$path]
);
}
@ -91,12 +91,12 @@ class DBLockingProvider extends AbstractLockingProvider {
$this->initLockField($path);
if ($type === self::LOCK_SHARED) {
$this->connection->executeUpdate(
'UPDATE `*PREFIX*locks` SET `lock` = `lock` - 1 WHERE `path` = ? AND `lock` > 0',
'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` - 1 WHERE `path` = ? AND `lock` > 0',
[$path]
);
} else {
$this->connection->executeUpdate(
'UPDATE `*PREFIX*locks` SET `lock` = 0 WHERE `path` = ? AND `lock` = -1',
'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `path` = ? AND `lock` = -1',
[$path]
);
}
@ -114,12 +114,12 @@ class DBLockingProvider extends AbstractLockingProvider {
$this->initLockField($path);
if ($targetType === self::LOCK_SHARED) {
$result = $this->connection->executeUpdate(
'UPDATE `*PREFIX*locks` SET `lock` = 1 WHERE `path` = ? AND `lock` = -1',
'UPDATE `*PREFIX*file_locks` SET `lock` = 1 WHERE `path` = ? AND `lock` = -1',
[$path]
);
} else {
$result = $this->connection->executeUpdate(
'UPDATE `*PREFIX*locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 1',
'UPDATE `*PREFIX*file_locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 1',
[$path]
);
}

View File

@ -76,6 +76,7 @@ class DropOldTables extends BasicEmitter implements RepairStep {
'calendar_share_event',
'foldersize',
'fscache',
'locks',
'log',
'media_albums',
'media_artists',

View File

@ -37,7 +37,7 @@ class DBLockingProvider extends LockingProvider {
}
public function tearDown() {
$this->connection->executeQuery('DELETE FROM `*PREFIX*locks`');
$this->connection->executeQuery('DELETE FROM `*PREFIX*file_locks`');
parent::tearDown();
}
}