mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
feat: add table filter to schema:export and schema:expected
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
2e0baa5801
commit
4da6081786
2 changed files with 31 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ use OC\DB\Connection;
|
|||
use OC\DB\MigrationService;
|
||||
use OC\DB\SchemaWrapper;
|
||||
use OC\Migration\NullOutput;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
|
@ -30,12 +31,14 @@ class ExpectedSchema extends Base {
|
|||
->setName('db:schema:expected')
|
||||
->setDescription('Export the expected database schema for a fresh installation')
|
||||
->setHelp("Note that the expected schema might not exactly match the exported live schema as the expected schema doesn't take into account any database wide settings or defaults.")
|
||||
->addArgument('table', InputArgument::OPTIONAL, 'Only show the schema for the specified table')
|
||||
->addOption('sql', null, InputOption::VALUE_NONE, 'Dump the SQL statements for creating the expected schema');
|
||||
parent::configure();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$schema = new Schema();
|
||||
$onlyTable = $input->getArgument('table');
|
||||
|
||||
$this->applyMigrations('core', $schema);
|
||||
|
||||
|
|
@ -44,6 +47,18 @@ class ExpectedSchema extends Base {
|
|||
$this->applyMigrations($app, $schema);
|
||||
}
|
||||
|
||||
if ($onlyTable) {
|
||||
$tablesToDrop = [];
|
||||
foreach ($schema->getTables() as $table) {
|
||||
if ($table->getName() !== $onlyTable) {
|
||||
$tablesToDrop[] = $table->getName();
|
||||
}
|
||||
}
|
||||
foreach ($tablesToDrop as $table) {
|
||||
$schema->dropTable($table);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = $input->getOption('sql');
|
||||
if ($sql) {
|
||||
$output->writeln($schema->toSql($this->connection->getDatabasePlatform()));
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ namespace OC\Core\Command\Db;
|
|||
|
||||
use OC\Core\Command\Base;
|
||||
use OCP\IDBConnection;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
|
@ -25,6 +26,7 @@ class ExportSchema extends Base {
|
|||
$this
|
||||
->setName('db:schema:export')
|
||||
->setDescription('Export the current database schema')
|
||||
->addArgument('table', InputArgument::OPTIONAL, 'Only show the schema for the specified table')
|
||||
->addOption('sql', null, InputOption::VALUE_NONE, 'Dump the SQL statements for creating a copy of the schema');
|
||||
parent::configure();
|
||||
}
|
||||
|
|
@ -32,6 +34,20 @@ class ExportSchema extends Base {
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$schema = $this->connection->createSchema();
|
||||
$sql = $input->getOption('sql');
|
||||
$onlyTable = $input->getArgument('table');
|
||||
|
||||
if ($onlyTable) {
|
||||
$tablesToDrop = [];
|
||||
foreach ($schema->getTables() as $table) {
|
||||
if ($table->getName() !== $onlyTable) {
|
||||
$tablesToDrop[] = $table->getName();
|
||||
}
|
||||
}
|
||||
foreach ($tablesToDrop as $table) {
|
||||
$schema->dropTable($table);
|
||||
}
|
||||
}
|
||||
|
||||
if ($sql) {
|
||||
$output->writeln($schema->toSql($this->connection->getDatabasePlatform()));
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue