current state of Syncope
authorLars Kneschke <l.kneschke@metaways.de>
Wed, 25 Jan 2012 04:51:43 +0000 (05:51 +0100)
committerLars Kneschke <l.kneschke@metaways.de>
Wed, 25 Jan 2012 04:51:43 +0000 (05:51 +0100)
docs/syncope.sql
lib/Syncope/Backend/Device.php
lib/Syncope/Backend/Folder.php
lib/Syncope/Backend/IFolder.php
lib/Syncope/Backend/SyncState.php
lib/Syncope/Model/IDevice.php
tests/Syncope/Backend/DeviceTests.php
tests/Syncope/Command/ATestCase.php
tests/bootstrap.php

index f2a9c09..612fe05 100644 (file)
@@ -1,9 +1,11 @@
-CREATE TABLE IF NOT EXISTS `syncope_devices` (
+CREATE TABLE IF NOT EXISTS `syncope_device` (
     `id` varchar(40) NOT NULL, `name`,
     `deviceid` varchar(64) NOT NULL,                                                                                                                                                                         
     `devicetype` varchar(64) NOT NULL,
     `policykey` varchar(64) DEFAULT NULL,
+    `policy_id` varchar(40) NOT NULL,
     `owner_id` varchar(40) NOT NULL,
+    `useragent` varchar(255) NOT NULL,
     `acsversion` varchar(40) NOT NULL,
     `pinglifetime` int(11) DEFAULT NULL,
     `remotewipe` int(11) DEFAULT '0',
@@ -18,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `syncope_folders` (
   `folderid` varchar(254) NOT NULL,
   `parentid` varchar(254) DEFAULT NULL,
   `displayname` varchar(254) NOT NULL,
-  `type` int(11) DEFAULT NULL,
+  `type` int(11) NOT NULL,
   `creation_time` datetime NOT NULL,
   `lastfiltertype` int(11) DEFAULT NULL,
   PRIMARY KEY (`id`),
@@ -27,14 +29,14 @@ CREATE TABLE IF NOT EXISTS `syncope_folders` (
   CONSTRAINT `folderstates::device_id--devices::id` FOREIGN KEY (`device_id`) REFERENCES `devices` (`id`) ON DELETE CASCADE ON UPDATE CASCADE 
 );
 
-CREATE TABLE `syncope_synckeys` (
+CREATE TABLE `syncope_synckey` (
   `device_id` varchar(64) NOT NULL DEFAULT '',
   `type` varchar(64) NOT NULL DEFAULT '',
   `counter` int(11) unsigned NOT NULL DEFAULT '0',
   `lastsync` datetime DEFAULT NULL,
   `pendingdata` longblob,
   PRIMARY KEY (`device_id`,`type`,`counter`),
-  CONSTRAINT `syncope_synckeys::device_id--syncope_devices::id` FOREIGN KEY (`device_id`) REFERENCES `syncope_devices` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+  CONSTRAINT `syncope_synckey::device_id--syncope_device::id` FOREIGN KEY (`device_id`) REFERENCES `syncope_device` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
 );
 
 CREATE TABLE `syncope_contents` (                                                                                                                                           
@@ -46,6 +48,6 @@ CREATE TABLE `syncope_contents` (
   `is_deleted` tinyint(1) unsigned DEFAULT '0',                                                                                                                                                            
   PRIMARY KEY (`id`),                                                                                                                                                                                      
   UNIQUE KEY `device_id--folder_id--contentid` (`device_id`(40),`folder_id`(40),`contentid`(40)),                                                                                 
-  KEY `acsync_contents::device_id--acsync_devices::id` (`device_id`),                                                                                                                                        
-  CONSTRAINT `acsync_contents::device_id--acsync_devices::id` FOREIGN KEY (`device_id`) REFERENCES `syncope_devices` (`id`) ON DELETE CASCADE ON UPDATE CASCADE                                         
+  KEY `acsync_contents::device_id--acsync_device::id` (`device_id`),                                                                                                                                        
+  CONSTRAINT `acsync_contents::device_id--acsync_device::id` FOREIGN KEY (`device_id`) REFERENCES `syncope_device` (`id`) ON DELETE CASCADE ON UPDATE CASCADE                                         
 );
\ No newline at end of file
index 1e20375..908d7ed 100644 (file)
@@ -27,9 +27,12 @@ class Syncope_Backend_Device implements Syncope_Backend_IDevice
      */
     protected $_db;
     
-    public function __construct(Zend_Db_Adapter_Abstract $_db)
+    protected $_tablePrefix;
+    
+    public function __construct(Zend_Db_Adapter_Abstract $_db, $_tablePrefix = 'syncope_')
     {
-        $this->_db = $_db;
+        $this->_db          = $_db;
+        $this->_tablePrefix = $_tablePrefix;
     }
 
     /**
@@ -42,12 +45,14 @@ class Syncope_Backend_Device implements Syncope_Backend_IDevice
     {
         $id = sha1(mt_rand(). microtime());
         
-        $this->_db->insert('syncope_devices', array(
+        $this->_db->insert($this->_tablePrefix . 'device', array(
                'id'         => $id, 
                'deviceid'   => $_device->deviceid,
                'devicetype' => $_device->devicetype,
+               'policy_id'  => $_device->policy_id,
                'policykey'  => $_device->policykey,
                'owner_id'   => $_device->owner_id,
+               'useragent'  => $_device->useragent,
                'acsversion' => $_device->acsversion,
                'remotewipe' => $_device->remotewipe
         ));
@@ -63,7 +68,7 @@ class Syncope_Backend_Device implements Syncope_Backend_IDevice
     public function get($_id)
     {
         $select = $this->_db->select()
-            ->from('syncope_devices')
+            ->from($this->_tablePrefix . 'device')
             ->where('id = ?', $_id);
             
         $stmt = $this->_db->query($select);
@@ -80,14 +85,14 @@ class Syncope_Backend_Device implements Syncope_Backend_IDevice
     {
         $id = $_id instanceof Syncope_Model_IDevice ? $_id->id : $id;
         
-        $result = $this->_db->delete('syncope_devices', array('id' => $id));
+        $result = $this->_db->delete($this->_tablePrefix . 'device', array('id' => $id));
         
         return (bool) $result;
     }
     
     public function update(Syncope_Model_IDevice $_device)
     {
-        $this->_db->update('syncope_devices', array(
+        $this->_db->update($this->_tablePrefix . 'device', array(
                'acsversion'   => $_device->acsversion,
                'policykey'    => $_device->policykey,
                'pingfolder'   => $_device->pingfolder,
index 2c39548..22ae9d0 100644 (file)
@@ -28,32 +28,36 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
      */
     protected $_db;
     
-    public function __construct(Zend_Db_Adapter_Abstract $_db)
+    protected $_tablePrefix;
+    
+    public function __construct(Zend_Db_Adapter_Abstract $_db, $_tablePrefix = 'syncope_')
     {
         $this->_db = $_db;
+        
+        $this->_tablePrefix = $_tablePrefix;
     }
     
     /**
      * create new folder state
      *
-     * @param Syncope_Model_IFolder $_folderState
+     * @param Syncope_Model_IFolder $_folder
      * @return Syncope_Model_IFolder
      */
-    public function create(Syncope_Model_IFolder $_folderState)
+    public function create(Syncope_Model_IFolder $_folder)
     {
         $id = sha1(mt_rand(). microtime());
-        $deviceId = $_folderState->device_id instanceof Syncope_Model_IDevice ? $_folderState->device_id->id : $_folderState->device_id;
+        $deviceId = $_folder->device_id instanceof Syncope_Model_IDevice ? $_folder->device_id->id : $_folder->device_id;
     
-        $this->_db->insert('syncope_folders', array(
+        $this->_db->insert($this->_tablePrefix . 'folders', array(
                'id'             => $id, 
                'device_id'      => $deviceId,
-               'class'          => $_folderState->class,
-               'folderid'       => $_folderState->folderid instanceof Syncope_Model_IFolder ? $_folderState->folderid->id : $_folderState->folderid,
-               'parentid'       => $_folderState->parentid,
-               'displayname'    => $_folderState->displayname,
-               'type'           => $_folderState->type,
-               'creation_time'  => $_folderState->creation_time->format('Y-m-d H:i:s'),
-               'lastfiltertype' => $_folderState->lastfiltertype
+               'class'          => $_folder->class,
+               'folderid'       => $_folder->folderid instanceof Syncope_Model_IFolder ? $_folder->folderid->id : $_folder->folderid,
+               'parentid'       => $_folder->parentid,
+               'displayname'    => $_folder->displayname,
+               'type'           => $_folder->type,
+               'creation_time'  => $_folder->creation_time->format('Y-m-d H:i:s'),
+               'lastfiltertype' => $_folder->lastfiltertype
         ));
         
         return $this->get($id);
@@ -63,7 +67,7 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
     {
         $id = $_id instanceof Syncope_Model_IFolder ? $_id->id : $id;
     
-        $result = $this->_db->delete('syncope_folders', array('id' => $id));
+        $result = $this->_db->delete($this->_tablePrefix . 'folders', array('id' => $id));
     
         return (bool) $result;
     }
@@ -76,7 +80,7 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
     public function get($_id)
     {
         $select = $this->_db->select()
-            ->from('syncope_folders')
+            ->from($this->_tablePrefix . 'folders')
             ->where('id = ?', $_id);
     
         $stmt = $this->_db->query($select);
@@ -107,20 +111,20 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
             $this->_db->quoteInto($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
         );
         
-        $this->_db->delete('syncope_folders', $where);
+        $this->_db->delete($this->_tablePrefix . 'folders', $where);
     }
     
-    public function update(Syncope_Model_IFolder $_state)
+    public function update(Syncope_Model_IFolder $_folder)
     {
-        $deviceId = $_state->device_id instanceof Syncope_Model_IDevice ? $_state->device_id->id : $_state->device_id;
+        $deviceId = $_folder->device_id instanceof Syncope_Model_IDevice ? $_folder->device_id->id : $_folder->device_id;
     
-        $this->_db->update('syncope_folders', array(
-               'lastfiltertype'     => $_state->lastfiltertype
+        $this->_db->update($this->_tablePrefix . 'folders', array(
+               'lastfiltertype'     => $_folder->lastfiltertype
         ), array(
-               'id = ?' => $_state->id
+               'id = ?' => $_folder->id
         ));
     
-        return $this->get($_state->id);
+        return $this->get($_folder->id);
     }
     
     /**
@@ -135,7 +139,7 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
         $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
         
         $select = $this->_db->select()
-            ->from('syncope_folders')
+            ->from($this->_tablePrefix . 'folders')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('class') . ' = ?', $_class);
         
@@ -161,21 +165,21 @@ class Syncope_Backend_Folder implements Syncope_Backend_IFolder
         $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
         
         $select = $this->_db->select()
-            ->from('syncope_folders')
+            ->from($this->_tablePrefix . 'folders')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('folderid') . ' = ?', $_folderId);
         
         $stmt = $this->_db->query($select);
-        $state = $stmt->fetchObject('Syncope_Model_Folder');
+        $folder = $stmt->fetchObject('Syncope_Model_Folder');
         
-        if (! $state instanceof Syncope_Model_IFolder) {
+        if (! $folder instanceof Syncope_Model_IFolder) {
             throw new Syncope_Exception_NotFound('folder not found');
         }
         
-        if (!empty($state->creation_time)) {
-            $state->creation_time = new DateTime($state->creation_time, new DateTimeZone('utc'));
+        if (!empty($folder->creation_time)) {
+            $folder->creation_time = new DateTime($folder->creation_time, new DateTimeZone('utc'));
         }
         
-        return $state;
+        return $folder;
     }
 }
index 1f2f36b..32abd60 100755 (executable)
 interface Syncope_Backend_IFolder
 {
     /**
-     * @param Syncope_Model_IFolder $_folderState
+     * @param Syncope_Model_IFolder $_folder
      * @return Syncope_Model_IFolder
      */
-    public function create(Syncope_Model_IFolder $_folderState);
+    public function create(Syncope_Model_IFolder $_folder);
     
     public function delete($_id);
     
-    /**
-     * delete all stored folderId's for given device
-     *
-     * @param Syncope_Model_Device $_deviceId
-     * @param string $_class
-     */
-    public function resetState($_deviceId);
+    public function get($_id);
     
     /**
      * get folder indentified by $_folderId
@@ -54,4 +48,14 @@ interface Syncope_Backend_IFolder
      * @return array
      */
     public function getFolderState($_deviceId, $_class);
+    
+    /**
+     * delete all stored folderId's for given device
+     *
+     * @param Syncope_Model_Device $_deviceId
+     * @param string $_class
+     */
+    public function resetState($_deviceId);
+    
+    public function update(Syncope_Model_IFolder $_folder);
 }
index ee6fe28..825e45d 100644 (file)
@@ -28,15 +28,12 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
      */
     protected $_db;
     
-    /**
-     * @var Zend_Log
-     */
-    protected $_logger;
+    protected $_tablePrefix;
     
-    public function __construct(Zend_Db_Adapter_Abstract $_db, Zend_Log $_logger = null)
+    public function __construct(Zend_Db_Adapter_Abstract $_db, $_tablePrefix = 'syncope_')
     {
-        $this->_db     = $_db;
-        $this->_logger = $_logger;
+        $this->_db          = $_db;
+        $this->_tablePrefix = $_tablePrefix;
     }
     
     /**
@@ -50,7 +47,7 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
         $id = sha1(mt_rand(). microtime());
         $deviceId = $_syncState->device_id instanceof Syncope_Model_IDevice ? $_syncState->device_id->id : $_syncState->device_id;
     
-        $this->_db->insert('syncope_synckeys', array(
+        $this->_db->insert($this->_tablePrefix . 'synckey', array(
                'id'          => $id, 
                'device_id'   => $deviceId,
                'type'        => $_syncState->type instanceof Syncope_Model_IFolder ? $_syncState->type->id : $_syncState->type,
@@ -78,7 +75,7 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
             'counter != ?'  => $_state->counter
         );
     
-        $this->_db->delete('syncope_synckeys', $where);
+        $this->_db->delete($this->_tablePrefix . 'synckey', $where);
     
         return true;
     
@@ -92,11 +89,12 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
     public function get($_id)
     {
         $select = $this->_db->select()
-            ->from('syncope_synckeys')
+            ->from($this->_tablePrefix . 'synckey')
             ->where('id = ?', $_id);
     
         $stmt = $this->_db->query($select);
         $state = $stmt->fetchObject('Syncope_Model_SyncState');
+        $stmt = null; # see https://bugs.php.net/bug.php?id=44081
         
         if (! $state instanceof Syncope_Model_ISyncState) {
             throw new Syncope_Exception_NotFound('id not found');
@@ -123,13 +121,14 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
         $folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId;
     
         $select = $this->_db->select()
-            ->from('syncope_synckeys')
+            ->from($this->_tablePrefix . 'synckey')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('type')      . ' = ?', $folderId);
     
         $stmt = $this->_db->query($select);
         $state = $stmt->fetchObject('Syncope_Model_SyncState');
-    
+        $stmt = null; # see https://bugs.php.net/bug.php?id=44081
+        
         if (! $state instanceof Syncope_Model_ISyncState) {
             throw new Syncope_Exception_NotFound('id not found');
         }
@@ -160,14 +159,14 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
             $this->_db->quoteInto($this->_db->quoteIdentifier('type') . ' = ?',      $folderId)
         );
     
-        $this->_db->delete('syncope_synckeys', $where);
+        $this->_db->delete($this->_tablePrefix . 'synckey', $where);
     }
     
     public function update(Syncope_Model_ISyncState $_syncState)
     {
         $deviceId = $_syncState->device_id instanceof Syncope_Model_IDevice ? $_syncState->device_id->id : $_syncState->device_id;
         
-        $this->_db->update('syncope_synckeys', array(
+        $this->_db->update($this->_tablePrefix . 'synckey', array(
                'counter'     => $_syncState->counter,
                'lastsync'    => $_syncState->lastsync->format('Y-m-d H:i:s'),
                'pendingdata' => isset($_syncState->pendingdata) ? $_syncState->pendingdata : null
@@ -191,13 +190,14 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
         $folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId;
         
         $select = $this->_db->select()
-            ->from('syncope_synckeys')
+            ->from($this->_tablePrefix . 'synckey')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('counter')   . ' = ?', $_syncKey)
             ->where($this->_db->quoteIdentifier('type')      . ' = ?', $folderId);
         
         $stmt = $this->_db->query($select);
         $state = $stmt->fetchObject('Syncope_Model_SyncState');
+        $stmt = null; # see https://bugs.php.net/bug.php?id=44081
         
         if (! $state instanceof Syncope_Model_ISyncState) {
             return false;
@@ -212,18 +212,19 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
         
         // check if this was the latest syncKey
         $select = $this->_db->select()
-            ->from('syncope_synckeys')
+            ->from($this->_tablePrefix . 'synckey')
             ->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)
             ->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey + 1)
             ->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId);
         
         $stmt = $this->_db->query($select);
         $moreRecentState = $stmt->fetchObject('Syncope_Model_SyncState');
+        $stmt = null; # see https://bugs.php.net/bug.php?id=44081
         
         // found more recent synckey => the last sync repsone got not received by the client
         if ($moreRecentState instanceof Syncope_Model_ISyncState) {
             // undelete entries marked as deleted in syncope_contents table
-            $this->_db->update('syncope_contents', array(
+            $this->_db->update($this->_tablePrefix . 'contents', array(
                'is_deleted'  => 0,
             ), array(
                'device_id = ?'  => $deviceId,
@@ -232,7 +233,7 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
             ));
             
             // remove entries added during latest sync in syncope_contents table
-            $this->_db->delete('syncope_contents', array(
+            $this->_db->delete($this->_tablePrefix . 'contents', array(
                'device_id = ?'     => $deviceId,
                'folder_id = ?'     => $folderId,
                'creation_time > ?' => $state->lastsync->format('Y-m-d H:i:s'),
@@ -240,7 +241,7 @@ class Syncope_Backend_SyncState implements Syncope_Backend_ISyncState
             
         } else {
             // finaly delete all entries marked for removal in syncope_contents table    
-            $this->_db->delete('syncope_contents', array(
+            $this->_db->delete($this->_tablePrefix . 'contents', array(
                'device_id = ?'  => $deviceId,
                'folder_id = ?'  => $folderId,
                'is_deleted = ?' => 1
index 807fae4..75c8af5 100644 (file)
@@ -20,6 +20,7 @@
  * @property    string   deviceid
  * @property    string   devicetype
  * @property    string   policykey
+ * @property    string   policy_id
  * @property    string   owner_id
  * @property    string   acsversion
  * @property    string   pingfolder
index 2c2c0ca..46b6e38 100644 (file)
@@ -81,6 +81,10 @@ class Syncope_Backend_DeviceTests extends PHPUnit_Framework_TestCase
         $device = $this->testCreateDevice();
         
         $this->_deviceBackend->delete($device);
+        
+        $this->setExpectedException('Syncope_Exception_NotFound');
+        
+        $this->_deviceBackend->get($device->id);
     }
     
     /**
@@ -95,7 +99,9 @@ class Syncope_Backend_DeviceTests extends PHPUnit_Framework_TestCase
                        'deviceid'   => 'android-abcd',
                        'devicetype' => Syncope_Model_Device::TYPE_ANDROID,
                        'policykey'  => 1,
+                       'policy_id'  => 1,
                        'owner_id'   => '1234',
+                       'useragent'  => 'blabla',
                        'acsversion' => '12.0',
                        'remotewipe' => 0
                 )); 
@@ -106,7 +112,9 @@ class Syncope_Backend_DeviceTests extends PHPUnit_Framework_TestCase
                        'deviceid'   => 'webos-abcd',
                        'devicetype' => Syncope_Model_Device::TYPE_ANDROID,
                        'policykey'  => 1,
+                       'policy_id'  => 1,
                        'owner_id'   => '1234',
+                       'useragent'  => 'blabla',
                        'acsversion' => '12.0',
                        'remotewipe' => 0
                 )); 
@@ -118,7 +126,9 @@ class Syncope_Backend_DeviceTests extends PHPUnit_Framework_TestCase
                        'deviceid'   => 'iphone-abcd',
                        'devicetype' => Syncope_Model_Device::TYPE_IPHONE,
                        'policykey'  => 1,
+                       'policy_id'  => 1,
                        'owner_id'   => '1234',
+                       'useragent'  => 'blabla',
                        'acsversion' => '2.5',
                        'remotewipe' => 0
                 )); 
index 882dede..41e4be4 100644 (file)
@@ -65,10 +65,10 @@ abstract class Syncope_Command_ATestCase extends PHPUnit_Framework_TestCase
         
         $logger = new Zend_Log($writer);
         
-        $this->_deviceBackend       = new Syncope_Backend_Device($this->_db, $logger);
-        $this->_folderBackend       = new Syncope_Backend_Folder($this->_db, $logger);
-        $this->_syncStateBackend    = new Syncope_Backend_SyncState($this->_db, $logger);
-        $this->_contentStateBackend = new Syncope_Backend_Content($this->_db, $logger);
+        $this->_deviceBackend       = new Syncope_Backend_Device($this->_db);
+        $this->_folderBackend       = new Syncope_Backend_Folder($this->_db);
+        $this->_syncStateBackend    = new Syncope_Backend_SyncState($this->_db);
+        $this->_contentStateBackend = new Syncope_Backend_Content($this->_db);
 
         $this->_device = $this->_deviceBackend->create(
             Syncope_Backend_DeviceTests::getTestDevice()
index 594805e..f8b8bdd 100644 (file)
@@ -28,12 +28,14 @@ function getTestDatabase()
     // enable foreign keys
     #$db->query('PRAGMA foreign_keys = ON');
     
-    $db->query("CREATE TABLE IF NOT EXISTS `syncope_devices` (
+    $db->query("CREATE TABLE IF NOT EXISTS `syncope_device` (
         `id` varchar(40) NOT NULL,
         `deviceid` varchar(64) NOT NULL,                                                                                                                                                                         
         `devicetype` varchar(64) NOT NULL,
         `policykey` varchar(64) DEFAULT NULL,
         `owner_id` varchar(40) NOT NULL,
+        `useragent` varchar(255) NOT NULL,
+        `policy_id` varchar(40) NOT NULL,
         `acsversion` varchar(40) NOT NULL,
         `pinglifetime` int(11) DEFAULT NULL,
         `remotewipe` int(11) DEFAULT '0',
@@ -48,14 +50,14 @@ function getTestDatabase()
         `folderid` varchar(254) NOT NULL,
         `parentid` varchar(254) DEFAULT NULL,
         `displayname` varchar(254) NOT NULL,
-        `type` int(11) DEFAULT NULL,
+        `type` int(11) NOT NULL,
         `creation_time` datetime NOT NULL,
         `lastfiltertype` int(11) DEFAULT NULL,
         PRIMARY KEY (`id`),
         UNIQUE (`device_id`,`class`,`folderid`)
        )");
     
-    $db->query("CREATE TABLE `syncope_synckeys` (
+    $db->query("CREATE TABLE `syncope_synckey` (
        `id` varchar(40) NOT NULL,
        `device_id` varchar(64) NOT NULL,
        `type` varchar(64) NOT NULL,