Making generating schema for connections with prefixes work correctly. The prefix needs to be removed so that when tables are created or updated they do not get the prefix added twice.

Moving tests around. Fixes #1180
This commit is contained in:
mark_story 2010-10-20 23:17:04 -04:00
parent 498417203b
commit 7c296211ef
2 changed files with 23 additions and 11 deletions

View file

@ -253,13 +253,18 @@ class CakeSchema extends Object {
}
if (is_object($Object) && $Object->useTable !== false) {
$table = $db->fullTableName($Object, false);
if (in_array($table, $currentTables)) {
$key = array_search($table, $currentTables);
$fulltable = $table = $db->fullTableName($Object, false);
if ($prefix && strpos($table, $prefix) !== 0) {
continue;
}
$table = str_replace($prefix, '', $table);
if (in_array($fulltable, $currentTables)) {
$key = array_search($fulltable, $currentTables);
if (empty($tables[$table])) {
$tables[$table] = $this->__columns($Object);
$tables[$table]['indexes'] = $db->index($Object);
$tables[$table]['tableParameters'] = $db->readTableParameters($table);
$tables[$table]['tableParameters'] = $db->readTableParameters($fulltable);
unset($currentTables[$key]);
}
if (!empty($Object->hasAndBelongsToMany)) {

View file

@ -559,13 +559,6 @@ class CakeSchemaTest extends CakeTestCase {
$this->Schema->tables['datatypes']['float_field']
);
$db =& ConnectionManager::getDataSource('test_suite');
$config = $db->config;
$config['prefix'] = 'schema_test_prefix_';
ConnectionManager::create('schema_prefix', $config);
$read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false));
$this->assertTrue(empty($read['tables']));
$SchemaPost =& ClassRegistry::init('SchemaPost');
$SchemaPost->table = 'sts';
$SchemaPost->tablePrefix = 'po';
@ -603,6 +596,20 @@ class CakeSchemaTest extends CakeTestCase {
}
/**
* test reading schema with config prefix.
*
* @return void
*/
function testSchemaReadWithConfigPrefix() {
$db =& ConnectionManager::getDataSource('test_suite');
$config = $db->config;
$config['prefix'] = 'schema_test_prefix_';
ConnectionManager::create('schema_prefix', $config);
$read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false));
$this->assertTrue(empty($read['tables']));
}
/**
* test reading schema from plugins.
*