From adeac7aa3925c76dc53fb011c873d25eae520a4e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 27 Mar 2014 14:44:19 +0100 Subject: Check sqlite migration on a copy of the database file --- lib/private/db/migrator.php | 1 + lib/private/db/sqlitemigrator.php | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 lib/private/db/sqlitemigrator.php (limited to 'lib') 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 @@ + + * 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()); + } + } +} -- cgit v1.2.3