From 18c213c1673b1bf58c7792097a9ff3bc4ca9bc49 Mon Sep 17 00:00:00 2001
From: Julian PEREZ-RAMIREZ <julian.perez-ramirez@imt-atlantique.net>
Date: Fri, 21 Feb 2025 21:36:37 +0100
Subject: [PATCH] creating first migration file

---
 README.md                                    | 16 +++++++
 web_app/composer.json                        |  3 ++
 web_app/config/bundles.php                   |  1 +
 web_app/migrations/Version20250221203107.php | 31 ++++++++++++
 web_app/src/Entity/Product.php               | 50 ++++++++++++++++++++
 web_app/src/Repository/ProductRepository.php | 43 +++++++++++++++++
 web_app/symfony.lock                         |  9 ++++
 7 files changed, 153 insertions(+)
 create mode 100644 README.md
 create mode 100644 web_app/migrations/Version20250221203107.php
 create mode 100644 web_app/src/Entity/Product.php
 create mode 100644 web_app/src/Repository/ProductRepository.php

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..84a9d0e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,16 @@
+Commands to set up Symfony with DB connection
+
+If you dont have installed yet
+
+```
+composer require symfony/orm-pack
+
+composer require --dev symfony/maker-bundle
+```
+
+```
+php bin/console doctrine:database:create
+php bin/console make:migration
+php bin/console doctrine:migrations:migrate
+
+```
\ No newline at end of file
diff --git a/web_app/composer.json b/web_app/composer.json
index bc22af8..61bf1a0 100644
--- a/web_app/composer.json
+++ b/web_app/composer.json
@@ -67,5 +67,8 @@
             "allow-contrib": false,
             "require": "7.2.*"
         }
+    },
+    "require-dev": {
+        "symfony/maker-bundle": "^1.62"
     }
 }
diff --git a/web_app/config/bundles.php b/web_app/config/bundles.php
index c1fa06a..de8898b 100644
--- a/web_app/config/bundles.php
+++ b/web_app/config/bundles.php
@@ -4,4 +4,5 @@ return [
     Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
     Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
     Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
+    Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
 ];
diff --git a/web_app/migrations/Version20250221203107.php b/web_app/migrations/Version20250221203107.php
new file mode 100644
index 0000000..10602e8
--- /dev/null
+++ b/web_app/migrations/Version20250221203107.php
@@ -0,0 +1,31 @@
+<?php
+
+declare(strict_types=1);
+
+namespace DoctrineMigrations;
+
+use Doctrine\DBAL\Schema\Schema;
+use Doctrine\Migrations\AbstractMigration;
+
+/**
+ * Auto-generated Migration: Please modify to your needs!
+ */
+final class Version20250221203107 extends AbstractMigration
+{
+    public function getDescription(): string
+    {
+        return '';
+    }
+
+    public function up(Schema $schema): void
+    {
+        // this up() migration is auto-generated, please modify it to your needs
+        $this->addSql('CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, price DOUBLE PRECISION NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
+    }
+
+    public function down(Schema $schema): void
+    {
+        // this down() migration is auto-generated, please modify it to your needs
+        $this->addSql('DROP TABLE product');
+    }
+}
diff --git a/web_app/src/Entity/Product.php b/web_app/src/Entity/Product.php
new file mode 100644
index 0000000..b78a233
--- /dev/null
+++ b/web_app/src/Entity/Product.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Entity;
+
+use App\Repository\ProductRepository;
+use Doctrine\ORM\Mapping as ORM;
+
+#[ORM\Entity(repositoryClass: ProductRepository::class)]
+class Product
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 255)]
+    private ?string $name = null;
+
+    #[ORM\Column]
+    private ?float $price = null;
+
+    public function getId(): ?int
+    {
+        return $this->id;
+    }
+
+    public function getName(): ?string
+    {
+        return $this->name;
+    }
+
+    public function setName(string $name): static
+    {
+        $this->name = $name;
+
+        return $this;
+    }
+
+    public function getPrice(): ?float
+    {
+        return $this->price;
+    }
+
+    public function setPrice(float $price): static
+    {
+        $this->price = $price;
+
+        return $this;
+    }
+}
diff --git a/web_app/src/Repository/ProductRepository.php b/web_app/src/Repository/ProductRepository.php
new file mode 100644
index 0000000..9564bc1
--- /dev/null
+++ b/web_app/src/Repository/ProductRepository.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Repository;
+
+use App\Entity\Product;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Persistence\ManagerRegistry;
+
+/**
+ * @extends ServiceEntityRepository<Product>
+ */
+class ProductRepository extends ServiceEntityRepository
+{
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, Product::class);
+    }
+
+    //    /**
+    //     * @return Product[] Returns an array of Product objects
+    //     */
+    //    public function findByExampleField($value): array
+    //    {
+    //        return $this->createQueryBuilder('p')
+    //            ->andWhere('p.exampleField = :val')
+    //            ->setParameter('val', $value)
+    //            ->orderBy('p.id', 'ASC')
+    //            ->setMaxResults(10)
+    //            ->getQuery()
+    //            ->getResult()
+    //        ;
+    //    }
+
+    //    public function findOneBySomeField($value): ?Product
+    //    {
+    //        return $this->createQueryBuilder('p')
+    //            ->andWhere('p.exampleField = :val')
+    //            ->setParameter('val', $value)
+    //            ->getQuery()
+    //            ->getOneOrNullResult()
+    //        ;
+    //    }
+}
diff --git a/web_app/symfony.lock b/web_app/symfony.lock
index bb5af90..b7d0228 100644
--- a/web_app/symfony.lock
+++ b/web_app/symfony.lock
@@ -70,6 +70,15 @@
             "src/Kernel.php"
         ]
     },
+    "symfony/maker-bundle": {
+        "version": "1.62",
+        "recipe": {
+            "repo": "github.com/symfony/recipes",
+            "branch": "main",
+            "version": "1.0",
+            "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
+        }
+    },
     "symfony/routing": {
         "version": "7.2",
         "recipe": {
-- 
GitLab