public getDropSchemaSQL ( array $classes ) : array | ||
$classes | array | |
return | array |
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) { $isFullDatabaseDrop = $input->getOption('full-database'); if ($input->getOption('dump-sql') === true) { if ($isFullDatabaseDrop) { $sqls = $schemaTool->getDropDatabaseSQL(); } else { $sqls = $schemaTool->getDropSchemaSQL($metadatas); } $output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL); } else { if ($input->getOption('force') === true) { $output->write('Dropping database schema...' . PHP_EOL); if ($isFullDatabaseDrop) { $schemaTool->dropDatabase(); } else { $schemaTool->dropSchema($metadatas); } $output->write('Database schema dropped successfully!' . PHP_EOL); } else { $output->write('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL . PHP_EOL); if ($isFullDatabaseDrop) { $sqls = $schemaTool->getDropDatabaseSQL(); } else { $sqls = $schemaTool->getDropSchemaSQL($metadatas); } if (count($sqls)) { $output->write('Schema-Tool would execute ' . count($sqls) . ' queries to drop the database.' . PHP_EOL); $output->write('Please run the operation with --force to execute these queries or use --dump-sql to see them.' . PHP_EOL); } else { $output->write('Nothing to drop. The database is empty!' . PHP_EOL); } } } }
/** * Execute the console command. * * @return void */ public function fire() { $sql = $this->tool->getDropSchemaSQL($this->metadata->getAllMetadata()); if (empty($sql)) { $this->info('Current models do not exist in schema.'); return; } if ($this->option('sql')) { $this->info('Outputting drop query:'); $this->info(implode(';' . PHP_EOL, $sql)); } else { $this->info('Dropping database schema....'); $this->tool->dropSchema($this->metadata->getAllMetadata()); $this->info('Schema has been dropped!'); } }
/** * There seems to be a bug when I try to drop a table. */ public function testDropTable() { $statements = $this->tool->getDropSchemaSQL($this->classes); $this->assertInternalType('array', $statements); $this->assertSame('DROP SEQUENCE test_id_seq CASCADE', $statements[0]); $this->assertSame('DROP TABLE test', $statements[1]); }
public function uninstallEntity(array $entity) { $metadata = $this->getMetadata($entity); $tool = new SchemaTool($this->_em); $queries = $tool->getDropSchemaSQL($metadata); return $this->persist($queries ?: array()); }
/** * Execute the console command. * * @param ManagerRegistry $registry */ public function fire(ManagerRegistry $registry) { $this->error('ATTENTION: This operation should not be executed in a production environment.'); $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); foreach ($names as $name) { $em = $registry->getManager($name); $tool = new SchemaTool($em); $this->info(''); $this->message('Checking scheme for <info>' . $name . '</info> entity manager...'); if ($this->option('sql')) { if ($this->option('full')) { $sql = $tool->getDropDatabaseSQL(); } else { $sql = $tool->getDropSchemaSQL($em->getMetadataFactory()->getAllMetadata()); } $this->comment(' ' . implode('; ' . PHP_EOL, $sql)); } else { if ($this->option('force')) { $this->message('Dropping database schema...'); if ($this->option('full')) { $tool->dropDatabase(); } else { $tool->dropSchema($em->getMetadataFactory()->getAllMetadata()); } $this->info('Database schema dropped successfully!'); } if ($this->option('full')) { $sql = $tool->getDropDatabaseSQL(); } else { $sql = $tool->getDropSchemaSQL($em->getMetadataFactory()->getAllMetadata()); } if (count($sql)) { $pluralization = 1 === count($sql) ? 'query was' : 'queries were'; $this->message(sprintf('The Schema-Tool would execute <info>"%s"</info> %s to update the database.', count($sql), $pluralization)); $this->message('Please run the operation by passing one - or both - of the following options:'); $this->comment(sprintf(' <info>php artisan %s --force</info> to execute the command', $this->getName())); $this->comment(sprintf(' <info>php artisan %s --sql</info> to dump the SQL statements to the screen', $this->getName())); } else { $this->error('Nothing to drop. The database is empty!'); } } } }
public function fire() { $sql = $this->tool->getDropSchemaSQL($this->metadata->getAllMetadata()); if (empty($sql)) { $this->error('Current models do not exist in schema.'); return; } if ($this->option('sql')) { $this->info('Outputting drop query:' . PHP_EOL); $this->line(implode(';' . PHP_EOL, $sql) . ';'); } else { if ($this->option('commit')) { $this->info('Dropping database schema....'); $this->tool->dropSchema($this->metadata->getAllMetadata()); $this->info('Schema has been dropped!'); } else { $this->comment("Warning: this command can cause data loss. Run with --sql or --commit."); } } }
/** * {@inheritdoc} */ protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) { $isFullDatabaseDrop = $input->getOption('full-database'); if ($input->getOption('dump-sql')) { if ($isFullDatabaseDrop) { $sqls = $schemaTool->getDropDatabaseSQL(); } else { $sqls = $schemaTool->getDropSchemaSQL($metadatas); } $output->writeln(implode(';' . PHP_EOL, $sqls)); return 0; } if ($input->getOption('force')) { $output->writeln('Dropping database schema...'); if ($isFullDatabaseDrop) { $schemaTool->dropDatabase(); } else { $schemaTool->dropSchema($metadatas); } $output->writeln('Database schema dropped successfully!'); return 0; } $output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.' . PHP_EOL); if ($isFullDatabaseDrop) { $sqls = $schemaTool->getDropDatabaseSQL(); } else { $sqls = $schemaTool->getDropSchemaSQL($metadatas); } if (count($sqls)) { $output->writeln(sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls))); $output->writeln('Please run the operation by passing one - or both - of the following options:'); $output->writeln(sprintf(' <info>%s --force</info> to execute the command', $this->getName())); $output->writeln(sprintf(' <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName())); return 1; } $output->writeln('Nothing to drop. The database is empty!'); return 0; }
public function testGetDropSchemaSql() { $classes = array($this->_em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress'), $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser'), $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber')); $tool = new SchemaTool($this->_em); $sql = $tool->getDropSchemaSQL($classes); $this->assertEquals(13, count($sql)); $dropSequenceSQLs = 0; foreach ($sql as $stmt) { if (strpos($stmt, "DROP SEQUENCE") === 0) { $dropSequenceSQLs++; } } $this->assertEquals(4, $dropSequenceSQLs, "Expect 4 sequences to be dropped."); }
/** * Drops plugin's tables based on Doctrine metadata. * * @param array $metadata * @param MauticFactory $factory * * @throws \Doctrine\DBAL\ConnectionException * @throws \Exception */ public static function dropPluginSchema(array $metadata, MauticFactory $factory) { $db = $factory->getDatabase(); $schemaTool = new SchemaTool($factory->getEntityManager()); $dropQueries = $schemaTool->getDropSchemaSQL($metadata); $db->beginTransaction(); try { foreach ($dropQueries as $q) { $db->query($q); } $db->commit(); } catch (\Exception $e) { $db->rollback(); throw $e; } }