diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-04-08 16:01:08 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-06-03 11:18:17 +0200 |
commit | 3b4555ca918f549d48d55b6f01a641bc0a21850e (patch) | |
tree | f48f561f7e5a21f37a86a046d7186e0e44c181c4 /lib/private/db/migrator.php | |
parent | adeac7aa3925c76dc53fb011c873d25eae520a4e (diff) | |
download | nextcloud-server-3b4555ca918f549d48d55b6f01a641bc0a21850e.tar.gz nextcloud-server-3b4555ca918f549d48d55b6f01a641bc0a21850e.zip |
Try and check migration before applying it
Diffstat (limited to 'lib/private/db/migrator.php')
-rw-r--r-- | lib/private/db/migrator.php | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php index 5ba16e34311..917f92f64b6 100644 --- a/lib/private/db/migrator.php +++ b/lib/private/db/migrator.php @@ -36,6 +36,23 @@ class Migrator { } /** + * @param \Doctrine\DBAL\Schema\Schema $targetSchema + * @return string + */ + public function generateChangeScript(Schema $targetSchema) { + $schemaDiff = $this->getDiff($targetSchema, $this->connection); + + $script = ''; + $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform()); + foreach ($sqls as $sql) { + $script .= $sql . ';'; + $script .= PHP_EOL; + } + + return $script; + } + + /** * @param Schema $targetSchema * @throws \OC\DB\MigrationException */ @@ -109,16 +126,8 @@ class Migrator { return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions()); } - /** - * @param \Doctrine\DBAL\Schema\Schema $targetSchema - * @param \Doctrine\DBAL\Connection $connection - */ - protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) { - if (is_null($connection)) { - $connection = $this->connection; - } - - $sourceSchema = $this->connection->getSchemaManager()->createSchema(); + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { + $sourceSchema = $connection->getSchemaManager()->createSchema(); // remove tables we don't know about /** @var $table \Doctrine\DBAL\Schema\Table */ @@ -139,8 +148,25 @@ class Migrator { foreach ($schemaDiff->changedTables as $tableDiff) { $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); + foreach ($tableDiff->changedColumns as $column) { + $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); + } + } + + return $schemaDiff; + } + + /** + * @param \Doctrine\DBAL\Schema\Schema $targetSchema + * @param \Doctrine\DBAL\Connection $connection + */ + protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) { + if (is_null($connection)) { + $connection = $this->connection; } + $schemaDiff = $this->getDiff($targetSchema, $connection); + $connection->beginTransaction(); foreach ($schemaDiff->toSql($connection->getDatabasePlatform()) as $sql) { $connection->query($sql); |