Skip to content

Commit

Permalink
Fix table names not properly read from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Dec 8, 2014
1 parent dcc3cf2 commit b850d5b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion DatabaseCopy/Command/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
use Symfony\Component\Console\Output\OutputInterface;


if (!function_exists('array_column')) {

/**
* Simplified array_column polyfill
*/
function array_column($ary, $columnKey)
{
return array_map(create_function('&$row', 'return $row["'.$columnKey.'"];'), $ary);
}
}

class CreateCommand extends AbstractCommand {

protected $indexes; // names assets
Expand Down Expand Up @@ -59,7 +70,7 @@ protected function renameIndexes($table) {
protected function renameAssets($schema, $platform) {
$this->indexes = array();

echo("renaming assets for target platform: " . $platform . "\n");
echo("Renaming assets for target platform: " . $platform . "\n");

foreach ($schema->getTables() as $table) {
echo("table: " . $table->getName() . "\n");
Expand Down Expand Up @@ -96,6 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$conn = \Doctrine\DBAL\DriverManager::getConnection($_config);
$tm = $conn->getSchemaManager();

echo("Creating database\n");
$tm->createDatabase($db);
}

Expand All @@ -107,8 +119,13 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$this->renameAssets($schema, $platform);
}

echo("Creating tables\n");

// sync configured tables only
if (($tables = $this->getOptionalConfig('tables'))) {
// extract target table names
$tables = array_column($tables, 'name');

foreach ($schema->getTables() as $table) {
if (!in_array($table->getName(), $tables)) {
$schema->dropTable($table->getName());
Expand Down

0 comments on commit b850d5b

Please sign in to comment.