summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-03-27 14:44:19 +0100
committerRobin Appelman <icewind@owncloud.com>2014-06-03 11:17:21 +0200
commitadeac7aa3925c76dc53fb011c873d25eae520a4e (patch)
tree7256b51db516b8856ad786e13c3babd0fb7a00cb /lib
parent35550e8d9a7239c66457fc1533462fd5949d9d2d (diff)
downloadnextcloud-server-adeac7aa3925c76dc53fb011c873d25eae520a4e.tar.gz
nextcloud-server-adeac7aa3925c76dc53fb011c873d25eae520a4e.zip
Check sqlite migration on a copy of the database file
Diffstat (limited to 'lib')
-rw-r--r--lib/private/db/migrator.php1
-rw-r--r--lib/private/db/sqlitemigrator.php40
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php
index 3f32e8c603e..5ba16e34311 100644
--- a/lib/private/db/migrator.php
+++ b/lib/private/db/migrator.php
@@ -37,6 +37,7 @@ class Migrator {
/**
* @param Schema $targetSchema
+ * @throws \OC\DB\MigrationException
*/
public function checkMigrate(Schema $targetSchema) {
/**
diff --git a/lib/private/db/sqlitemigrator.php b/lib/private/db/sqlitemigrator.php
new file mode 100644
index 00000000000..f5f78986771
--- /dev/null
+++ b/lib/private/db/sqlitemigrator.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\DB;
+
+use Doctrine\DBAL\DBALException;
+
+class SQLiteMigrator extends Migrator {
+ /**
+ * @param \Doctrine\DBAL\Schema\Schema $targetSchema
+ * @throws \OC\DB\MigrationException
+ *
+ * For sqlite we simple make a copy of the entire database, and test the migration on that
+ */
+ public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) {
+ $dbFile = $this->connection->getDatabase();
+ $tmpFile = \OC_Helper::tmpFile('.db');
+ copy($dbFile, $tmpFile);
+
+ $connectionParams = array(
+ 'path' => $tmpFile,
+ 'driver' => 'pdo_sqlite',
+ );
+ $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
+ try {
+ $this->applySchema($targetSchema, $conn);
+ $conn->close();
+ unlink($tmpFile);
+ } catch (DBALException $e) {
+ $conn->close();
+ unlink($tmpFile);
+ throw new MigrationException('', $e->getMessage());
+ }
+ }
+}