aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/db/sqlitemigrator.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/db/sqlitemigrator.php')
-rw-r--r--lib/private/db/sqlitemigrator.php40
1 files changed, 40 insertions, 0 deletions
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());
+ }
+ }
+}