From 3406dc14f42bd5e254c1e5a5cadc228d7b1f26be Mon Sep 17 00:00:00 2001 From: "cleo.eiras" Date: Tue, 3 Jun 2025 09:29:09 +0200 Subject: [PATCH] Commande pour peupler la db --- src/Command/PopulateDBCommand.php | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/Command/PopulateDBCommand.php diff --git a/src/Command/PopulateDBCommand.php b/src/Command/PopulateDBCommand.php new file mode 100644 index 0000000..2d06d1a --- /dev/null +++ b/src/Command/PopulateDBCommand.php @@ -0,0 +1,62 @@ +connection = $connection; + } + + protected function configure() + { + $this + ->setDescription('Populate the database.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + try { + + // On supprime la table si elle existe déjà + $this->connection->executeStatement('DROP TABLE IF EXISTS rarity'); + + // On crée la table + $this->connection->executeStatement(' + CREATE TABLE rarity ( + id INT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + drop_rate FLOAT NOT NULL + ) + '); + + // On peuple la table + $this->connection->executeStatement("INSERT INTO rarity (id, name, drop_rate) VALUES + (1, 'Common', 0.6), + (2, 'Rare', 0.2), + (3, 'Epic', 0.1), + (4, 'Mythical', 0.085), + (5, 'Legendary', 0.015) + "); + + $output->writeln('Base de données peuplée.'); + } catch (\Exception $e) { + $output->writeln('Erreur : ' . $e->getMessage() . ''); + return Command::FAILURE; + } + + return Command::SUCCESS; + } +}