mirror of
https://github.com/code-rhapsodie/dataflow-bundle.git
synced 2026-03-24 14:52:21 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47af0e226c | ||
|
|
6d86ba16a0 |
25
CHANGELOG.md
25
CHANGELOG.md
@@ -1,3 +1,28 @@
|
||||
# Version 5.2.0
|
||||
* Added custom index for job status
|
||||
|
||||
# Version 5.1.0
|
||||
* Refactor SchemaDump command
|
||||
|
||||
# Version 5.0.1
|
||||
* Fix compatibility with doctrine 4
|
||||
|
||||
# Version 5.0.0
|
||||
* Initiate Kudos on dataflow-bundle
|
||||
* Added Symfony 7 support
|
||||
* Removed Symfony 6 compatibility
|
||||
* Removed Symfony 5 compatibility
|
||||
* Removed Symfony 4 compatibility
|
||||
* Removed Symfony 3 compatibility
|
||||
* Changed README.md
|
||||
* Added CI
|
||||
|
||||
# Version 4.1.3
|
||||
* Fix log exception argument typing
|
||||
|
||||
# Version 4.1.2
|
||||
* Fix DBAL 2.12 compatibility break
|
||||
|
||||
# Version 4.1.0
|
||||
|
||||
* Added custom index for exception log
|
||||
|
||||
113
src/Command/DatabaseSchemaCommand.php
Normal file
113
src/Command/DatabaseSchemaCommand.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CodeRhapsodie\DataflowBundle\Command;
|
||||
|
||||
use CodeRhapsodie\DataflowBundle\Factory\ConnectionFactory;
|
||||
use CodeRhapsodie\DataflowBundle\Repository\JobRepository;
|
||||
use CodeRhapsodie\DataflowBundle\Repository\ScheduledDataflowRepository;
|
||||
use CodeRhapsodie\DataflowBundle\SchemaProvider\DataflowSchemaProvider;
|
||||
use Doctrine\DBAL\Schema\Comparator;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(name: 'code-rhapsodie:dataflow:database-schema', description: 'Generates schema create / update SQL queries')]
|
||||
class DatabaseSchemaCommand extends Command
|
||||
{
|
||||
public function __construct(private ConnectionFactory $connectionFactory)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setHelp('The <info>%command.name%</info> help you to generate SQL Query to create or update your database schema for this bundle')
|
||||
->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Dump only the update SQL queries.')
|
||||
->addOption('update', null, InputOption::VALUE_NONE, 'Dump/execute only the update SQL queries.')
|
||||
->addOption('connection', null, InputOption::VALUE_REQUIRED, 'Define the DBAL connection to use');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
if (null !== $input->getOption('connection')) {
|
||||
$this->connectionFactory->setConnectionName($input->getOption('connection'));
|
||||
}
|
||||
|
||||
$connection = $this->connectionFactory->getConnection();
|
||||
|
||||
$schemaProvider = new DataflowSchemaProvider();
|
||||
$schema = $schemaProvider->createSchema();
|
||||
|
||||
$sqls = $schema->toSql($connection->getDatabasePlatform());
|
||||
|
||||
if ($input->getOption('update')) {
|
||||
$sm = $connection->createSchemaManager();
|
||||
|
||||
$tableArray = [JobRepository::TABLE_NAME, ScheduledDataflowRepository::TABLE_NAME];
|
||||
$tables = [];
|
||||
foreach ($sm->listTables() as $table) {
|
||||
/** @var Table $table */
|
||||
if (in_array($table->getName(), $tableArray)) {
|
||||
$tables[] = $table;
|
||||
}
|
||||
}
|
||||
|
||||
$namespaces = [];
|
||||
|
||||
if ($connection->getDatabasePlatform()->supportsSchemas()) {
|
||||
$namespaces = $sm->listSchemaNames();
|
||||
}
|
||||
|
||||
$sequences = [];
|
||||
|
||||
if ($connection->getDatabasePlatform()->supportsSequences()) {
|
||||
$sequences = $sm->listSequences();
|
||||
}
|
||||
|
||||
$oldSchema = new Schema($tables, $sequences, $sm->createSchemaConfig(), $namespaces);
|
||||
|
||||
$sqls = $connection->getDatabasePlatform()->getAlterSchemaSQL((new Comparator($connection->getDatabasePlatform()))->compareSchemas($oldSchema, $schema));
|
||||
|
||||
if (empty($sqls)) {
|
||||
$io->info('There is no update SQL queries.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($input->getOption('dump-sql')) {
|
||||
$io->text('Execute these SQL Queries on your database:');
|
||||
foreach ($sqls as $sql) {
|
||||
$io->text($sql . ';');
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
if (!$io->askQuestion(new ConfirmationQuestion('Are you sure to update database ?', true))) {
|
||||
$io->text("Execution canceled.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
foreach ($sqls as $sql) {
|
||||
$connection->executeQuery($sql);
|
||||
}
|
||||
|
||||
$io->success(sprintf('%d queries executed.', \count($sqls)));
|
||||
|
||||
return parent::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -20,15 +21,11 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated This command is deprecated and will be removed in 6.0, use this command "code-rhapsodie:dataflow:database-schema" instead.
|
||||
*/
|
||||
#[AsCommand('code-rhapsodie:dataflow:dump-schema', 'Generates schema create / update SQL queries')]
|
||||
class SchemaCommand extends Command
|
||||
{
|
||||
public function __construct(private ConnectionFactory $connectionFactory)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -46,51 +43,24 @@ class SchemaCommand extends Command
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (null !== $input->getOption('connection')) {
|
||||
$this->connectionFactory->setConnectionName($input->getOption('connection'));
|
||||
}
|
||||
|
||||
$connection = $this->connectionFactory->getConnection();
|
||||
|
||||
$schemaProvider = new DataflowSchemaProvider();
|
||||
$schema = $schemaProvider->createSchema();
|
||||
|
||||
$sqls = $schema->toSql($connection->getDatabasePlatform());
|
||||
|
||||
if ($input->getOption('update')) {
|
||||
$sm = $connection->createSchemaManager();
|
||||
|
||||
$tableArray = [JobRepository::TABLE_NAME, ScheduledDataflowRepository::TABLE_NAME];
|
||||
$tables = [];
|
||||
foreach ($sm->listTables() as $table) {
|
||||
/** @var Table $table */
|
||||
if (in_array($table->getName(), $tableArray)) {
|
||||
$tables[] = $table;
|
||||
}
|
||||
}
|
||||
|
||||
$namespaces = [];
|
||||
|
||||
if ($connection->getDatabasePlatform()->supportsSchemas()) {
|
||||
$namespaces = $sm->listSchemaNames();
|
||||
}
|
||||
|
||||
$sequences = [];
|
||||
|
||||
if ($connection->getDatabasePlatform()->supportsSequences()) {
|
||||
$sequences = $sm->listSequences();
|
||||
}
|
||||
|
||||
$oldSchema = new Schema($tables, $sequences, $sm->createSchemaConfig(), $namespaces);
|
||||
|
||||
$sqls = $connection->getDatabasePlatform()->getAlterSchemaSQL((new Comparator($connection->getDatabasePlatform()))->compareSchemas($oldSchema, $schema));
|
||||
}
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->text('Execute these SQL Queries on your database:');
|
||||
foreach ($sqls as $sql) {
|
||||
$io->text($sql.';');
|
||||
}
|
||||
$io->warning('This command is deprecated and will be removed in 6.0, use this command "code-rhapsodie:dataflow:database-schema" instead.');
|
||||
|
||||
return parent::SUCCESS;
|
||||
$options = array_filter($input->getOptions());
|
||||
|
||||
//add -- before each keys
|
||||
$options = array_combine(
|
||||
array_map(fn($key) => '--' . $key, array_keys($options)),
|
||||
array_values($options)
|
||||
);
|
||||
|
||||
$options['--dump-sql'] = true;
|
||||
|
||||
$inputArray = new ArrayInput([
|
||||
'command' => 'code-rhapsodie:dataflow:database-schema',
|
||||
...$options
|
||||
]);
|
||||
|
||||
return $this->getApplication()->doRun($inputArray, $output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +45,15 @@ services:
|
||||
tags: ['console.command']
|
||||
|
||||
CodeRhapsodie\DataflowBundle\Command\SchemaCommand:
|
||||
deprecated:
|
||||
package: 'code-rhapsodie/dataflow-bundle'
|
||||
version: '5.0'
|
||||
tags: ['console.command']
|
||||
|
||||
CodeRhapsodie\DataflowBundle\Command\DatabaseSchemaCommand:
|
||||
arguments:
|
||||
$connectionFactory: '@CodeRhapsodie\DataflowBundle\Factory\ConnectionFactory'
|
||||
tags: ['console.command']
|
||||
tags: [ 'console.command' ]
|
||||
|
||||
CodeRhapsodie\DataflowBundle\Repository\ScheduledDataflowRepository:
|
||||
lazy: true
|
||||
|
||||
@@ -48,6 +48,7 @@ class DataflowSchemaProvider
|
||||
$tableSchedule->addColumn('enabled', 'boolean', ['notnull' => true]);
|
||||
|
||||
$tableJob->addForeignKeyConstraint($tableSchedule->getName(), ['scheduled_dataflow_id'], ['id']);
|
||||
$tableJob->addIndex(['status'], 'idx_status');
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user