diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-05-19 12:18:10 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-05-19 12:18:10 +0200 |
commit | 7015dd74ce27db6e7c7cb2596e61343ac9f22902 (patch) | |
tree | 674bf5cde7a5dc3bc8e264dfe346bc7064f7cf1a | |
parent | 4e44d2ecd6cc2ac065342591c1af61532b3ba774 (diff) | |
parent | 80afbd3e4f2a0bcb635e1a6baf0fb3febc7cec51 (diff) | |
download | nextcloud-server-7015dd74ce27db6e7c7cb2596e61343ac9f22902.tar.gz nextcloud-server-7015dd74ce27db6e7c7cb2596e61343ac9f22902.zip |
Merge pull request #16421 from owncloud/stable8-replace-static-dbtableprefix-with-config-dbtableprefix
[stable8] Replace static dbtableprefix with config dbtableprefix
-rw-r--r-- | lib/private/db/migrator.php | 4 | ||||
-rw-r--r-- | tests/lib/db/migrator.php | 29 |
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php index fcf5aae0258..f55b5078c0e 100644 --- a/lib/private/db/migrator.php +++ b/lib/private/db/migrator.php @@ -100,7 +100,7 @@ class Migrator { * @return string */ protected function generateTemporaryTableName($name) { - return 'oc_' . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); + return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); } /** @@ -151,7 +151,7 @@ class Migrator { $indexName = $index->getName(); } else { // avoid conflicts in index names - $indexName = 'oc_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); + $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); } $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); } diff --git a/tests/lib/db/migrator.php b/tests/lib/db/migrator.php index 54267740480..6bde68c2d20 100644 --- a/tests/lib/db/migrator.php +++ b/tests/lib/db/migrator.php @@ -26,11 +26,17 @@ class Migrator extends \Test\TestCase { */ private $manager; + /** + * @var IConfig + **/ + private $config; + private $tableName; protected function setUp() { parent::setUp(); + $this->config = \OC::$server->getConfig(); $this->connection = \OC_DB::getConnection(); if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { $this->markTestSkipped('DB migration tests are not supported on OCI'); @@ -39,7 +45,7 @@ class Migrator extends \Test\TestCase { $this->markTestSkipped('DB migration tests are not supported on MSSQL'); } $this->manager = new \OC\DB\MDB2SchemaManager($this->connection); - $this->tableName = strtolower($this->getUniqueID('oc_test_')); + $this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_')); } protected function tearDown() { @@ -109,6 +115,27 @@ class Migrator extends \Test\TestCase { $this->assertTrue(true); } + public function testUpgradeDifferentPrefix() { + $oldTablePrefix = $this->config->getSystemValue('dbtableprefix', 'oc_'); + + $this->config->setSystemValue('dbtableprefix', 'ownc_'); + $this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix') . 'test_')); + + list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); + $migrator = $this->manager->getMigrator(); + $migrator->migrate($startSchema); + + $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); + $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar')); + $this->connection->insert($this->tableName, array('id' => 3, 'name' => 'qwerty')); + + $migrator->checkMigrate($endSchema); + $migrator->migrate($endSchema); + $this->assertTrue(true); + + $this->config->setSystemValue('dbtableprefix', $oldTablePrefix); + } + public function testInsertAfterUpgrade() { list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); $migrator = $this->manager->getMigrator(); |