Loading config/module.config.php +16 −16 Changes for config/module.config.php: 16 added lines, 16 removed lines. Original line number Diff line number Diff line Loading @@ -6,17 +6,10 @@ return [ 'unicaen-bddadmin' => [ 'connection' => [ 'default' => [ 'driver' => 'Postgresql', // par défaut, ou Oracle ou Mysql 'host' => '', 'port' => '', 'dbname' => '', 'user' => '', 'password' => '', ], // Autres instances de la BDD ], 'current_connection' => 'default', 'ddl' => [ 'dir' => 'data/ddl', 'columns_positions_file' => 'data/ddl_columns_pos.php', Loading Loading @@ -61,23 +54,30 @@ return [ 'service_manager' => [ 'factories' => [ Bdd::class => BddFactory::class, Command\InstallBddCommand::class => Command\CommandFactory::class, Command\UpdateBddCommand::class => Command\CommandFactory::class, Command\InstallCommand::class => Command\CommandFactory::class, Command\UpdateCommand::class => Command\CommandFactory::class, Command\UpdateDdlCommand::class => Command\CommandFactory::class, Command\UpdateDataCommand::class => Command\CommandFactory::class, Command\ClearBddCommand::class => Command\CommandFactory::class, Command\ClearCommand::class => Command\CommandFactory::class, Command\CopyToCommand::class => Command\CommandFactory::class, Command\CopyFromCommand::class => Command\CommandFactory::class, Command\LoadCommand::class => Command\CommandFactory::class, Command\SaveCommand::class => Command\CommandFactory::class, ], ], 'laminas-cli' => [ 'commands' => [ 'bddadmin:install-bdd' => Command\InstallBddCommand::class, 'bddadmin:update-bdd' => Command\UpdateBddCommand::class, 'bddadmin:clear-bdd' => Command\ClearBddCommand::class, 'bddadmin:install' => Command\InstallCommand::class, 'bddadmin:update' => Command\UpdateCommand::class, 'bddadmin:clear' => Command\ClearCommand::class, 'bddadmin:update-ddl' => Command\UpdateDdlCommand::class, 'bddadmin:update-data' => Command\UpdateDataCommand::class, 'bddadmin:copy-to' => Command\CopyToCommand::class, 'bddadmin:copy-from' => Command\CopyFromCommand::class, 'bddadmin:load' => Command\LoadCommand::class, 'bddadmin:save' => Command\SaveCommand::class, ], ], ]; No newline at end of file config/unicaen-bddadmin.local.php.dist +4 −1 Changes for config/unicaen-bddadmin.local.php.dist: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ return [ 'unicaen-bddadmin' => [ 'connection' => [ 'default' => [ // généralement : base de dév 'default' => [ // généralement : base de dév, peut s'appeler autrement que 'default' 'host' => 'à renseigner ...', 'port' => 'à renseigner ...', 'dbname' => 'à renseigner ...', Loading @@ -26,5 +26,8 @@ return [ ... */ ], /* Connexion à utiliser par défaut, nom à sélectionner parmi la liste des connexions disponibles */ //'current_connection' => 'default', ], ]; No newline at end of file src/Bdd.php +41 −11 Changes for src/Bdd.php: 41 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -37,9 +37,8 @@ class Bdd use LoggerAwareTrait; use OptionsTrait; const CONNECTION_DEFAULT = 'default'; const OPTION_CONNECTION = 'connection'; const OPTION_CURRENT_CONNECTION = 'current_connection'; const OPTION_DDL = 'ddl'; const OPTION_DATA = 'data'; const OPTION_MIGRATION = 'migration'; Loading Loading @@ -123,7 +122,7 @@ class Bdd Ddl::SCHEMA . '.drop' => 'Suppression des schémas', ]; private string $connection = self::CONNECTION_DEFAULT; private string $connection = 'default'; /** @var array|Bdd[] */ private array $bdds = []; Loading @@ -149,16 +148,20 @@ class Bdd public function __construct(array $options = [], string $connection = self::CONNECTION_DEFAULT) public function __construct(array $options = [], ?string $connection = null) { $this->connection = $connection; if (!empty($options)) { // Compatibilité avec l'ancienne configuration des connections if (!isset($options[self::OPTION_CONNECTION]) && isset($options['host'])) { $options = [self::OPTION_CONNECTION => [$connection => $options]]; } $this->setOptions($options); if (empty($connection)){ $connection = $this->getOption(self::OPTION_CURRENT_CONNECTION, 'default'); } $this->connection = $connection; $this->connect(); } Loading @@ -179,6 +182,23 @@ class Bdd public function getConnectionName(): string { return $this->connection; } public function getBdds(): array { $bdds = $this->getOption(self::OPTION_CONNECTION); unset($bdds[$this->getOption(self::OPTION_CURRENT_CONNECTION)]); return array_keys($bdds); } public function getBdd(string $connection): self { if (!array_key_exists($connection, $this->bdds)) { Loading Loading @@ -858,8 +878,8 @@ class Bdd $this->logTitle('Génération de la DDL à partir de la base de données'); try { $filters = $bdd->getFiltersForUpdateDdl(); $ddl = $bdd->getDdl($filters); $filters = $this->getFiltersForUpdateDdl(); $ddl = $this->getDdl($filters); $ddl->saveToDir(); $this->logSuccess('DDL mise à jour'); } catch (\Throwable $e) { Loading Loading @@ -1087,6 +1107,8 @@ class Bdd $this->create($source, $filters); $this->majSequences(); $this->logEnd(); return $this; Loading Loading @@ -1185,10 +1207,12 @@ class Bdd $ddl->loadFromFile($tmpPath . '/bdd.ddl'); $ddl->filter($filters); $schDdl = $ddl->get(Ddl::SCHEMA); $sDdl = $ddl->get(Ddl::SEQUENCE); $tDdl = $ddl->get(Ddl::TABLE); $this->drop(); $this->create([Ddl::TABLE => $tDdl]); $this->create([Ddl::SCHEMA => $schDdl, Ddl::SEQUENCE => $sDdl, Ddl::TABLE => $tDdl]); $tables = array_keys($tDdl); Loading @@ -1203,8 +1227,14 @@ class Bdd } } $this->inCopy = false; $this->create($ddl, [Ddl::SCHEMA => ['excludes' => '%']]); $this->create($ddl, [Ddl::TABLE => ['excludes' => '%']]); if ($filters instanceof DdlFilters) { $filters = $filters->toArray(); } $filters[Ddl::SCHEMA] = ['excludes' => '%']; $filters[Ddl::SEQUENCE] = ['excludes' => '%']; $filters[Ddl::TABLE] = ['excludes' => '%']; $this->create($ddl, $filters); $this->majSequences($ddl); Loading src/Command/ClearBddCommand.php→src/Command/ClearCommand.php +9 −2 Changes for src/Command/ClearCommand.php: 9 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -11,14 +11,21 @@ use Unicaen\BddAdmin\Data\DataManager; use Unicaen\BddAdmin\Ddl\Ddl; /** * Description of ClearBddCommand * Description of ClearCommand * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class ClearBddCommand extends Command class ClearCommand extends Command { use BddAwareTrait; protected function configure(): void { $this->setDescription('Vide la base de données'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); Loading src/Command/CopyFromCommand.php 0 → 100644 +59 −0 Changes for src/Command/CopyFromCommand.php: 59 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Unicaen\BddAdmin\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Unicaen\BddAdmin\BddAwareTrait; use Unicaen\BddAdmin\Data\DataManager; use Unicaen\BddAdmin\Ddl\Ddl; /** * Description of CopyFromCommand * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class CopyFromCommand extends Command { use BddAwareTrait; protected function configure(): void { $this ->setDescription('Copie depuis une autre BDD') ->addArgument('source', InputArgument::OPTIONAL, 'Nom de la BDD d\'origine'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $bdd = $this->getBdd()->setLogger($io); $bdds = $bdd->getBdds(); if (empty($bdds)) { $io->error('Aucune base de donnée possible n\'est en source : copie impossible'); $io->info('Veuillez ajouter d\'autres connexions en configuration dans unicaen-bddadmin/connection'); return Command::INVALID; } $source = $input->getArgument('source'); if (!$source) { $source = $io->choice( 'Veuillez choisir une base de données source', $bdd->getBdds() ); } // Lance la copie $bdd->copy($source); return Command::SUCCESS; } } No newline at end of file Loading
config/module.config.php +16 −16 Changes for config/module.config.php: 16 added lines, 16 removed lines. Original line number Diff line number Diff line Loading @@ -6,17 +6,10 @@ return [ 'unicaen-bddadmin' => [ 'connection' => [ 'default' => [ 'driver' => 'Postgresql', // par défaut, ou Oracle ou Mysql 'host' => '', 'port' => '', 'dbname' => '', 'user' => '', 'password' => '', ], // Autres instances de la BDD ], 'current_connection' => 'default', 'ddl' => [ 'dir' => 'data/ddl', 'columns_positions_file' => 'data/ddl_columns_pos.php', Loading Loading @@ -61,23 +54,30 @@ return [ 'service_manager' => [ 'factories' => [ Bdd::class => BddFactory::class, Command\InstallBddCommand::class => Command\CommandFactory::class, Command\UpdateBddCommand::class => Command\CommandFactory::class, Command\InstallCommand::class => Command\CommandFactory::class, Command\UpdateCommand::class => Command\CommandFactory::class, Command\UpdateDdlCommand::class => Command\CommandFactory::class, Command\UpdateDataCommand::class => Command\CommandFactory::class, Command\ClearBddCommand::class => Command\CommandFactory::class, Command\ClearCommand::class => Command\CommandFactory::class, Command\CopyToCommand::class => Command\CommandFactory::class, Command\CopyFromCommand::class => Command\CommandFactory::class, Command\LoadCommand::class => Command\CommandFactory::class, Command\SaveCommand::class => Command\CommandFactory::class, ], ], 'laminas-cli' => [ 'commands' => [ 'bddadmin:install-bdd' => Command\InstallBddCommand::class, 'bddadmin:update-bdd' => Command\UpdateBddCommand::class, 'bddadmin:clear-bdd' => Command\ClearBddCommand::class, 'bddadmin:install' => Command\InstallCommand::class, 'bddadmin:update' => Command\UpdateCommand::class, 'bddadmin:clear' => Command\ClearCommand::class, 'bddadmin:update-ddl' => Command\UpdateDdlCommand::class, 'bddadmin:update-data' => Command\UpdateDataCommand::class, 'bddadmin:copy-to' => Command\CopyToCommand::class, 'bddadmin:copy-from' => Command\CopyFromCommand::class, 'bddadmin:load' => Command\LoadCommand::class, 'bddadmin:save' => Command\SaveCommand::class, ], ], ]; No newline at end of file
config/unicaen-bddadmin.local.php.dist +4 −1 Changes for config/unicaen-bddadmin.local.php.dist: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ return [ 'unicaen-bddadmin' => [ 'connection' => [ 'default' => [ // généralement : base de dév 'default' => [ // généralement : base de dév, peut s'appeler autrement que 'default' 'host' => 'à renseigner ...', 'port' => 'à renseigner ...', 'dbname' => 'à renseigner ...', Loading @@ -26,5 +26,8 @@ return [ ... */ ], /* Connexion à utiliser par défaut, nom à sélectionner parmi la liste des connexions disponibles */ //'current_connection' => 'default', ], ]; No newline at end of file
src/Bdd.php +41 −11 Changes for src/Bdd.php: 41 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -37,9 +37,8 @@ class Bdd use LoggerAwareTrait; use OptionsTrait; const CONNECTION_DEFAULT = 'default'; const OPTION_CONNECTION = 'connection'; const OPTION_CURRENT_CONNECTION = 'current_connection'; const OPTION_DDL = 'ddl'; const OPTION_DATA = 'data'; const OPTION_MIGRATION = 'migration'; Loading Loading @@ -123,7 +122,7 @@ class Bdd Ddl::SCHEMA . '.drop' => 'Suppression des schémas', ]; private string $connection = self::CONNECTION_DEFAULT; private string $connection = 'default'; /** @var array|Bdd[] */ private array $bdds = []; Loading @@ -149,16 +148,20 @@ class Bdd public function __construct(array $options = [], string $connection = self::CONNECTION_DEFAULT) public function __construct(array $options = [], ?string $connection = null) { $this->connection = $connection; if (!empty($options)) { // Compatibilité avec l'ancienne configuration des connections if (!isset($options[self::OPTION_CONNECTION]) && isset($options['host'])) { $options = [self::OPTION_CONNECTION => [$connection => $options]]; } $this->setOptions($options); if (empty($connection)){ $connection = $this->getOption(self::OPTION_CURRENT_CONNECTION, 'default'); } $this->connection = $connection; $this->connect(); } Loading @@ -179,6 +182,23 @@ class Bdd public function getConnectionName(): string { return $this->connection; } public function getBdds(): array { $bdds = $this->getOption(self::OPTION_CONNECTION); unset($bdds[$this->getOption(self::OPTION_CURRENT_CONNECTION)]); return array_keys($bdds); } public function getBdd(string $connection): self { if (!array_key_exists($connection, $this->bdds)) { Loading Loading @@ -858,8 +878,8 @@ class Bdd $this->logTitle('Génération de la DDL à partir de la base de données'); try { $filters = $bdd->getFiltersForUpdateDdl(); $ddl = $bdd->getDdl($filters); $filters = $this->getFiltersForUpdateDdl(); $ddl = $this->getDdl($filters); $ddl->saveToDir(); $this->logSuccess('DDL mise à jour'); } catch (\Throwable $e) { Loading Loading @@ -1087,6 +1107,8 @@ class Bdd $this->create($source, $filters); $this->majSequences(); $this->logEnd(); return $this; Loading Loading @@ -1185,10 +1207,12 @@ class Bdd $ddl->loadFromFile($tmpPath . '/bdd.ddl'); $ddl->filter($filters); $schDdl = $ddl->get(Ddl::SCHEMA); $sDdl = $ddl->get(Ddl::SEQUENCE); $tDdl = $ddl->get(Ddl::TABLE); $this->drop(); $this->create([Ddl::TABLE => $tDdl]); $this->create([Ddl::SCHEMA => $schDdl, Ddl::SEQUENCE => $sDdl, Ddl::TABLE => $tDdl]); $tables = array_keys($tDdl); Loading @@ -1203,8 +1227,14 @@ class Bdd } } $this->inCopy = false; $this->create($ddl, [Ddl::SCHEMA => ['excludes' => '%']]); $this->create($ddl, [Ddl::TABLE => ['excludes' => '%']]); if ($filters instanceof DdlFilters) { $filters = $filters->toArray(); } $filters[Ddl::SCHEMA] = ['excludes' => '%']; $filters[Ddl::SEQUENCE] = ['excludes' => '%']; $filters[Ddl::TABLE] = ['excludes' => '%']; $this->create($ddl, $filters); $this->majSequences($ddl); Loading
src/Command/ClearBddCommand.php→src/Command/ClearCommand.php +9 −2 Changes for src/Command/ClearCommand.php: 9 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -11,14 +11,21 @@ use Unicaen\BddAdmin\Data\DataManager; use Unicaen\BddAdmin\Ddl\Ddl; /** * Description of ClearBddCommand * Description of ClearCommand * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class ClearBddCommand extends Command class ClearCommand extends Command { use BddAwareTrait; protected function configure(): void { $this->setDescription('Vide la base de données'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); Loading
src/Command/CopyFromCommand.php 0 → 100644 +59 −0 Changes for src/Command/CopyFromCommand.php: 59 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Unicaen\BddAdmin\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Unicaen\BddAdmin\BddAwareTrait; use Unicaen\BddAdmin\Data\DataManager; use Unicaen\BddAdmin\Ddl\Ddl; /** * Description of CopyFromCommand * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class CopyFromCommand extends Command { use BddAwareTrait; protected function configure(): void { $this ->setDescription('Copie depuis une autre BDD') ->addArgument('source', InputArgument::OPTIONAL, 'Nom de la BDD d\'origine'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $bdd = $this->getBdd()->setLogger($io); $bdds = $bdd->getBdds(); if (empty($bdds)) { $io->error('Aucune base de donnée possible n\'est en source : copie impossible'); $io->info('Veuillez ajouter d\'autres connexions en configuration dans unicaen-bddadmin/connection'); return Command::INVALID; } $source = $input->getArgument('source'); if (!$source) { $source = $io->choice( 'Veuillez choisir une base de données source', $bdd->getBdds() ); } // Lance la copie $bdd->copy($source); return Command::SUCCESS; } } No newline at end of file