Skip to content
Snippets Groups Projects
Commit 674edc53 authored by PEREZ-RAMIREZ Julian's avatar PEREZ-RAMIREZ Julian
Browse files

creating first version of db without relationships

parent fff97cb7
No related branches found
No related tags found
No related merge requests found
Showing
with 910 additions and 37 deletions
...@@ -12,5 +12,19 @@ composer require --dev symfony/maker-bundle ...@@ -12,5 +12,19 @@ composer require --dev symfony/maker-bundle
php bin/console doctrine:database:create php bin/console doctrine:database:create
php bin/console make:migration php bin/console make:migration
php bin/console doctrine:migrations:migrate php bin/console doctrine:migrations:migrate
```
Create an entity
```
docker exec -it symfony_app php bin/console make:entity
```
Create migration file to apply in the dp
```
docker exec -it symfony_app php bin/console make:migration
```
Apply the migration file in the db
```
docker exec -it symfony_app php bin/console doctrine:migrations:migrate
``` ```
\ No newline at end of file
<?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');
}
}
<?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 Version20250223144640 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 item (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, price DOUBLE PRECISION NOT NULL, purchase_url VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE purchase (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, wishlist_id INT NOT NULL, item_id INT NOT NULL, url_proof VARCHAR(255) DEFAULT NULL, message VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, user_name VARCHAR(255) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, surname VARCHAR(255) DEFAULT NULL, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, is_blocked TINYINT(1) DEFAULT NULL, role VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE wish_list (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, name VARCHAR(255) NOT NULL, expiration_date DATETIME DEFAULT NULL, is_active TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE wish_list_item (id INT AUTO_INCREMENT NOT NULL, wishlist_id INT NOT NULL, item_id INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE wish_list_member (id INT AUTO_INCREMENT NOT NULL, wishlist_id INT NOT NULL, user_id INT NOT NULL, can_edit TINYINT(1) NOT NULL, is_accepted TINYINT(1) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', 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 item');
$this->addSql('DROP TABLE purchase');
$this->addSql('DROP TABLE user');
$this->addSql('DROP TABLE wish_list');
$this->addSql('DROP TABLE wish_list_item');
$this->addSql('DROP TABLE wish_list_member');
}
}
<?php
namespace App\Entity;
use App\Repository\ItemRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ItemRepository::class)]
class Item
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $description = null;
#[ORM\Column]
private ?float $price = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $purchase_url = null;
#[ORM\Column]
private ?\DateTimeImmutable $created_at = null;
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): static
{
$this->id = $id;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): static
{
$this->price = $price;
return $this;
}
public function getPurchaseUrl(): ?string
{
return $this->purchase_url;
}
public function setPurchaseUrl(?string $purchase_url): static
{
$this->purchase_url = $purchase_url;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
}
<?php
namespace App\Entity;
use App\Repository\PurchaseRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PurchaseRepository::class)]
class Purchase
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column]
private ?int $user_id = null;
#[ORM\Column]
private ?int $wishlist_id = null;
#[ORM\Column]
private ?int $item_id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $url_proof = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $message = null;
#[ORM\Column]
private ?\DateTimeImmutable $created_at = null;
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): static
{
$this->id = $id;
return $this;
}
public function getUserId(): ?int
{
return $this->user_id;
}
public function setUserId(int $user_id): static
{
$this->user_id = $user_id;
return $this;
}
public function getWishlistId(): ?int
{
return $this->wishlist_id;
}
public function setWishlistId(int $wishlist_id): static
{
$this->wishlist_id = $wishlist_id;
return $this;
}
public function getItemId(): ?int
{
return $this->item_id;
}
public function setItemId(int $item_id): static
{
$this->item_id = $item_id;
return $this;
}
public function getUrlProof(): ?string
{
return $this->url_proof;
}
public function setUrlProof(?string $url_proof): static
{
$this->url_proof = $url_proof;
return $this;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(?string $message): static
{
$this->message = $message;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
}
<?php
namespace App\Entity;
use App\Enum\UserRole;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $user_name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $surname = null;
#[ORM\Column(length: 255)]
private ?string $email = null;
#[ORM\Column(length: 255)]
private ?string $password = null;
#[ORM\Column(nullable: true)]
private ?bool $is_blocked = null;
#[ORM\Column(enumType: UserRole::class)]
private ?UserRole $role = null;
#[ORM\Column]
private ?\DateTimeImmutable $created_at = null;
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): static
{
$this->id = $id;
return $this;
}
public function getUserName(): ?string
{
return $this->user_name;
}
public function setUserName(?string $user_name): static
{
$this->user_name = $user_name;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getSurname(): ?string
{
return $this->surname;
}
public function setSurname(?string $surname): static
{
$this->surname = $surname;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
public function isBlocked(): ?bool
{
return $this->is_blocked;
}
public function setIsBlocked(?bool $is_blocked): static
{
$this->is_blocked = $is_blocked;
return $this;
}
public function getRole(): ?UserRole
{
return $this->role;
}
public function setRole(UserRole $role): static
{
$this->role = $role;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
}
<?php
namespace App\Entity;
use App\Repository\WishListRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: WishListRepository::class)]
class WishList
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column]
private ?int $user_id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $expiration_date = null;
#[ORM\Column]
private ?bool $is_active = null;
#[ORM\Column]
private ?\DateTimeImmutable $created_at = null;
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): static
{
$this->id = $id;
return $this;
}
public function getUserId(): ?int
{
return $this->user_id;
}
public function setUserId(int $user_id): static
{
$this->user_id = $user_id;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getExpirationDate(): ?\DateTimeInterface
{
return $this->expiration_date;
}
public function setExpirationDate(?\DateTimeInterface $expiration_date): static
{
$this->expiration_date = $expiration_date;
return $this;
}
public function isActive(): ?bool
{
return $this->is_active;
}
public function setIsActive(bool $is_active): static
{
$this->is_active = $is_active;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
}
...@@ -2,48 +2,48 @@ ...@@ -2,48 +2,48 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\ProductRepository; use App\Repository\WishListItemRepository;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProductRepository::class)] #[ORM\Entity(repositoryClass: WishListItemRepository::class)]
class Product class WishListItem
{ {
#[ORM\Id] #[ORM\Id]
#[ORM\GeneratedValue] #[ORM\GeneratedValue]
#[ORM\Column] #[ORM\Column]
private ?int $id = null; private ?int $id = null;
#[ORM\Column(length: 255)] #[ORM\Column]
private ?string $name = null; private ?int $wishlist_id = null;
#[ORM\Column] #[ORM\Column]
private ?float $price = null; private ?int $item_id = null;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
} }
public function getName(): ?string public function getWishlistId(): ?int
{ {
return $this->name; return $this->wishlist_id;
} }
public function setName(string $name): static public function setWishlistId(int $wishlist_id): static
{ {
$this->name = $name; $this->wishlist_id = $wishlist_id;
return $this; return $this;
} }
public function getPrice(): ?float public function getItemId(): ?int
{ {
return $this->price; return $this->item_id;
} }
public function setPrice(float $price): static public function setItemId(int $item_id): static
{ {
$this->price = $price; $this->item_id = $item_id;
return $this; return $this;
} }
......
<?php
namespace App\Entity;
use App\Repository\WishListMemberRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: WishListMemberRepository::class)]
class WishListMember
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column]
private ?int $wishlist_id = null;
#[ORM\Column]
private ?int $user_id = null;
#[ORM\Column]
private ?bool $can_edit = null;
#[ORM\Column(nullable: true)]
private ?bool $is_accepted = null;
#[ORM\Column]
private ?\DateTimeImmutable $created_at = null;
public function getId(): ?int
{
return $this->id;
}
public function getWishlistId(): ?int
{
return $this->wishlist_id;
}
public function setWishlistId(int $wishlist_id): static
{
$this->wishlist_id = $wishlist_id;
return $this;
}
public function getUserId(): ?int
{
return $this->user_id;
}
public function setUserId(int $user_id): static
{
$this->user_id = $user_id;
return $this;
}
public function isCanEdit(): ?bool
{
return $this->can_edit;
}
public function setCanEdit(bool $can_edit): static
{
$this->can_edit = $can_edit;
return $this;
}
public function isAccepted(): ?bool
{
return $this->is_accepted;
}
public function setIsAccepted(?bool $is_accepted): static
{
$this->is_accepted = $is_accepted;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
}
<?php
namespace App\Enum;
enum UserRole: string
{
case ADMIN = 'admin';
case USER = 'user';
public function label(): string
{
return match($this) {
self::ADMIN => 'Administrator',
self::USER => 'Regular User'
};
}
}
?>
\ No newline at end of file
<?php
namespace App\Repository;
use App\Entity\Item;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Item>
*/
class ItemRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Item::class);
}
// /**
// * @return Item[] Returns an array of Item objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('i')
// ->andWhere('i.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('i.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Item
// {
// return $this->createQueryBuilder('i')
// ->andWhere('i.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
...@@ -2,22 +2,22 @@ ...@@ -2,22 +2,22 @@
namespace App\Repository; namespace App\Repository;
use App\Entity\Product; use App\Entity\Purchase;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
/** /**
* @extends ServiceEntityRepository<Product> * @extends ServiceEntityRepository<Purchase>
*/ */
class ProductRepository extends ServiceEntityRepository class PurchaseRepository extends ServiceEntityRepository
{ {
public function __construct(ManagerRegistry $registry) public function __construct(ManagerRegistry $registry)
{ {
parent::__construct($registry, Product::class); parent::__construct($registry, Purchase::class);
} }
// /** // /**
// * @return Product[] Returns an array of Product objects // * @return Purchase[] Returns an array of Purchase objects
// */ // */
// public function findByExampleField($value): array // public function findByExampleField($value): array
// { // {
...@@ -31,7 +31,7 @@ class ProductRepository extends ServiceEntityRepository ...@@ -31,7 +31,7 @@ class ProductRepository extends ServiceEntityRepository
// ; // ;
// } // }
// public function findOneBySomeField($value): ?Product // public function findOneBySomeField($value): ?Purchase
// { // {
// return $this->createQueryBuilder('p') // return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val') // ->andWhere('p.exampleField = :val')
......
<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<User>
*/
class UserRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
// /**
// * @return User[] Returns an array of User objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('u.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?User
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
<?php
namespace App\Repository;
use App\Entity\WishListItem;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<WishListItem>
*/
class WishListItemRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, WishListItem::class);
}
// /**
// * @return WishListItem[] Returns an array of WishListItem objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('w.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?WishListItem
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
<?php
namespace App\Repository;
use App\Entity\WishListMember;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<WishListMember>
*/
class WishListMemberRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, WishListMember::class);
}
// /**
// * @return WishListMember[] Returns an array of WishListMember objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('w.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?WishListMember
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
<?php
namespace App\Repository;
use App\Entity\WishList;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<WishList>
*/
class WishListRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, WishList::class);
}
// /**
// * @return WishList[] Returns an array of WishList objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('w.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?WishList
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment