protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); // make sure schemas exists $tm = $this->tc->getSchemaManager(); $this->validateSchema($this->getConfig('target')); // $this->dropConstraints($tm, $this->getConfig('tables')); $this->tc->beginTransaction(); foreach ($this->getConfig('tables') as $workItem) { $name = $workItem['name']; // check if table exists if (!$this->tableExists($tm, $name)) { echo $name . " doesn't exist - skipping.\n"; continue; } $table = $tm->listTableDetails($name); if ($input->getOption('drop')) { echo $name . ": dropping\n"; $this->dropTable($this->tc, $table); } else { echo $name . ": truncating\n"; $this->truncateTable($this->tc, $table); } } $this->tc->commit(); }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); // make sure schemas exists $tm = $this->tc->getSchemaManager(); $this->validateSchema($this->getConfig('target')); if (($db = $this->getOptionalConfig('target.dbname')) !== null) { $tm->dropDatabase($db); } elseif ($this->tc->getDatabasePlatform()->getName() == 'sqlite' && ($db = $this->getOptionalConfig('target.path')) !== null) { unlink($db); } else { throw new \Exception('Cannot drop undefined schema'); } }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); // make sure schemas exists $sm = $this->sc->getSchemaManager(); $this->validateSchema($this->getConfig('source')); echo "Creating target schema\n"; // create schema if it doesn't exist if (($db = $this->getOptionalConfig('target.dbname')) !== null && $this->validateSchema($this->getConfig('target'), false) == false) { // get schema-less connection $_config = $this->getConfig('target'); unset($_config['dbname']); $conn = \Doctrine\DBAL\DriverManager::getConnection($_config); $tm = $conn->getSchemaManager(); echo "Creating database\n"; $tm->createDatabase($db); } try { $schema = $sm->createSchema(); 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()); } } } // make sure schema is free of conflicts for target platform if (in_array($platform = $this->tc->getDatabasePlatform()->getName(), array('sqlite'))) { $this->updateSchemaForTargetPlatform($schema, $platform); } $synchronizer = new SingleDatabaseSynchronizer($this->tc); $synchronizer->createSchema($schema); } catch (\Exception $e) { $sql = $schema->toSql($this->tc->getDatabasePlatform()); echo join($sql, "\n"); throw $e; } }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->batch = $input->getOption('batch') ?: self::BATCH_SIZE; // make sure schemas exists $sm = $this->sc->getSchemaManager(); $this->validateSchema($this->getConfig('source')); $tm = $this->tc->getSchemaManager(); $this->validateSchema($this->getConfig('target')); if (!$input->getOption('keep-constraints')) { $this->dropConstraints($tm, $this->getConfig('tables')); } if (($tables = $this->getOptionalConfig('tables')) == null) { echo "tables not configured - discovering from source schema\n"; $tables = array(); foreach ($this->getTables($sm) as $tableName) { echo $tableName . " discovered\n"; $tables[] = array('name' => $tableName, 'mode' => self::MODE_COPY); } } foreach ($tables as $workItem) { $name = $workItem['name']; $mode = strtolower($workItem['mode']); // only selected tables? if ($selectedTables = $input->getArgument('tables')) { if (!in_array($name, $selectedTables)) { continue; } } $table = $sm->listTableDetails($name); switch ($mode) { case self::MODE_SKIP: echo $name . ": skipping\n"; break; case self::MODE_COPY: $this->copyTable($table, false); break; case self::MODE_PRIMARY_KEY: $keyColumn = $this->getSimplePK($table); $this->copyTable($table, $keyColumn); break; default: throw new \Exception('Unknown mode ' . $mode); } } if (!$input->getOption('keep-constraints')) { $this->addConstraints($tm); } }