Add option to remove all the tables from the destination database
This commit is contained in:
parent
1b7eb4dc6c
commit
af3bedf985
|
@ -65,6 +65,12 @@ class ConvertFromSqlite extends Command {
|
||||||
InputOption::VALUE_REQUIRED,
|
InputOption::VALUE_REQUIRED,
|
||||||
'the password of the database to convert to. Will be asked when not specified'
|
'the password of the database to convert to. Will be asked when not specified'
|
||||||
)
|
)
|
||||||
|
->addOption(
|
||||||
|
'clear-schema',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
'remove all tables from the destination database'
|
||||||
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +130,20 @@ class ConvertFromSqlite extends Command {
|
||||||
|
|
||||||
$toDB = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
|
$toDB = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
|
||||||
|
|
||||||
|
// Clearing schema in new database
|
||||||
|
if ($input->getOption('clear-schema')) {
|
||||||
|
$schemaManager = $toDB->getSchemaManager();
|
||||||
|
$toTables = $schemaManager->listTableNames();
|
||||||
|
if (!empty($toTables)) {
|
||||||
|
$output->writeln('Clearing schema in new database');
|
||||||
|
}
|
||||||
|
foreach($toTables as $table) {
|
||||||
|
$schemaManager->dropTable($table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create tables in new database
|
// create tables in new database
|
||||||
|
$output->writeln('Creating schema in new database');
|
||||||
$schemaManager = new \OC\DB\MDB2SchemaManager($toDB);
|
$schemaManager = new \OC\DB\MDB2SchemaManager($toDB);
|
||||||
$schemaManager->createDbFromStructure(\OC::$SERVERROOT.'/db_structure.xml');
|
$schemaManager->createDbFromStructure(\OC::$SERVERROOT.'/db_structure.xml');
|
||||||
$apps = \OC_App::getEnabledApps();
|
$apps = \OC_App::getEnabledApps();
|
||||||
|
@ -188,8 +207,6 @@ class ConvertFromSqlite extends Command {
|
||||||
$count = $fromDB->fetchColumn($query);
|
$count = $fromDB->fetchColumn($query);
|
||||||
$query = 'SELECT * FROM '.$table;
|
$query = 'SELECT * FROM '.$table;
|
||||||
$statement = $fromDB->executeQuery($query);
|
$statement = $fromDB->executeQuery($query);
|
||||||
$query = 'DELETE FROM '.$table;
|
|
||||||
$toDB->executeUpdate($query);
|
|
||||||
$progress->start($output, $count);
|
$progress->start($output, $count);
|
||||||
$progress->setRedrawFrequency($count > 100 ? 5 : 1);
|
$progress->setRedrawFrequency($count > 100 ? 5 : 1);
|
||||||
while($row = $statement->fetch()) {
|
while($row = $statement->fetch()) {
|
||||||
|
|
Loading…
Reference in New Issue