From 52974f84eb3390b6d7a56a4d50d1a3c1b4d6aad1 Mon Sep 17 00:00:00 2001 From: Julian PEREZ-RAMIREZ <julian.perez-ramirez@imt-atlantique.net> Date: Sun, 23 Feb 2025 17:00:24 +0100 Subject: [PATCH] v1 database with relationships --- web_app/migrations/Version20250223154313.php | 43 --------------- web_app/migrations/Version20250223155752.php | 57 ++++++++++++++++++++ web_app/src/Entity/Purchase.php | 3 -- web_app/src/Entity/WishListItem.php | 2 - web_app/src/Entity/WishListMember.php | 2 - 5 files changed, 57 insertions(+), 50 deletions(-) delete mode 100644 web_app/migrations/Version20250223154313.php create mode 100644 web_app/migrations/Version20250223155752.php diff --git a/web_app/migrations/Version20250223154313.php b/web_app/migrations/Version20250223154313.php deleted file mode 100644 index 67db709..0000000 --- a/web_app/migrations/Version20250223154313.php +++ /dev/null @@ -1,43 +0,0 @@ -<?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 Version20250223154313 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 INT NOT NULL, wishlist INT NOT NULL, item 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)\', UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), 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)\', INDEX IDX_5B8739BDA76ED395 (user_id), 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 INT NOT NULL, item 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 INT NOT NULL, user 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'); - $this->addSql('ALTER TABLE wish_list ADD CONSTRAINT FK_5B8739BDA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE wish_list DROP FOREIGN KEY FK_5B8739BDA76ED395'); - $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'); - } -} diff --git a/web_app/migrations/Version20250223155752.php b/web_app/migrations/Version20250223155752.php new file mode 100644 index 0000000..12eff67 --- /dev/null +++ b/web_app/migrations/Version20250223155752.php @@ -0,0 +1,57 @@ +<?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 Version20250223155752 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, wish_list_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)\', INDEX IDX_6117D13BA76ED395 (user_id), INDEX IDX_6117D13BD69F3311 (wish_list_id), INDEX IDX_6117D13B126F525E (item_id), 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)\', UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), 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)\', INDEX IDX_5B8739BDA76ED395 (user_id), 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, wish_list_id INT NOT NULL, item_id INT NOT NULL, INDEX IDX_9A7FA711D69F3311 (wish_list_id), INDEX IDX_9A7FA711126F525E (item_id), 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, wish_list_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)\', INDEX IDX_F4CA81DFD69F3311 (wish_list_id), INDEX IDX_F4CA81DFA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE purchase ADD CONSTRAINT FK_6117D13BA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + $this->addSql('ALTER TABLE purchase ADD CONSTRAINT FK_6117D13BD69F3311 FOREIGN KEY (wish_list_id) REFERENCES wish_list (id)'); + $this->addSql('ALTER TABLE purchase ADD CONSTRAINT FK_6117D13B126F525E FOREIGN KEY (item_id) REFERENCES item (id)'); + $this->addSql('ALTER TABLE wish_list ADD CONSTRAINT FK_5B8739BDA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + $this->addSql('ALTER TABLE wish_list_item ADD CONSTRAINT FK_9A7FA711D69F3311 FOREIGN KEY (wish_list_id) REFERENCES wish_list (id)'); + $this->addSql('ALTER TABLE wish_list_item ADD CONSTRAINT FK_9A7FA711126F525E FOREIGN KEY (item_id) REFERENCES item (id)'); + $this->addSql('ALTER TABLE wish_list_member ADD CONSTRAINT FK_F4CA81DFD69F3311 FOREIGN KEY (wish_list_id) REFERENCES wish_list (id)'); + $this->addSql('ALTER TABLE wish_list_member ADD CONSTRAINT FK_F4CA81DFA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE purchase DROP FOREIGN KEY FK_6117D13BA76ED395'); + $this->addSql('ALTER TABLE purchase DROP FOREIGN KEY FK_6117D13BD69F3311'); + $this->addSql('ALTER TABLE purchase DROP FOREIGN KEY FK_6117D13B126F525E'); + $this->addSql('ALTER TABLE wish_list DROP FOREIGN KEY FK_5B8739BDA76ED395'); + $this->addSql('ALTER TABLE wish_list_item DROP FOREIGN KEY FK_9A7FA711D69F3311'); + $this->addSql('ALTER TABLE wish_list_item DROP FOREIGN KEY FK_9A7FA711126F525E'); + $this->addSql('ALTER TABLE wish_list_member DROP FOREIGN KEY FK_F4CA81DFD69F3311'); + $this->addSql('ALTER TABLE wish_list_member DROP FOREIGN KEY FK_F4CA81DFA76ED395'); + $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'); + } +} diff --git a/web_app/src/Entity/Purchase.php b/web_app/src/Entity/Purchase.php index 641cf28..7f65dc8 100644 --- a/web_app/src/Entity/Purchase.php +++ b/web_app/src/Entity/Purchase.php @@ -13,17 +13,14 @@ class Purchase #[ORM\Column] private ?int $id = null; - #[ORM\Column] #[ORM\ManyToOne(targetEntity: User::class)] #[ORM\JoinColumn(nullable: false)] private ?int $user = null; - #[ORM\Column] #[ORM\ManyToOne(targetEntity: WishList::class)] #[ORM\JoinColumn(nullable: false)] private ?int $wishList = null; - #[ORM\Column] #[ORM\ManyToOne(targetEntity: Item::class)] #[ORM\JoinColumn(nullable: false)] private ?int $item = null; diff --git a/web_app/src/Entity/WishListItem.php b/web_app/src/Entity/WishListItem.php index 78fa1b7..bbc25da 100644 --- a/web_app/src/Entity/WishListItem.php +++ b/web_app/src/Entity/WishListItem.php @@ -13,12 +13,10 @@ class WishListItem #[ORM\Column] private ?int $id = null; - #[ORM\Column] #[ORM\ManyToOne(targetEntity: WishList::class)] #[ORM\JoinColumn(nullable: false)] private ?int $wishList = null; - #[ORM\Column] #[ORM\ManyToOne(targetEntity: Item::class)] #[ORM\JoinColumn(nullable: false)] private ?int $item = null; diff --git a/web_app/src/Entity/WishListMember.php b/web_app/src/Entity/WishListMember.php index 6646e5a..2d007a2 100644 --- a/web_app/src/Entity/WishListMember.php +++ b/web_app/src/Entity/WishListMember.php @@ -13,12 +13,10 @@ class WishListMember #[ORM\Column] private ?int $id = null; - #[ORM\Column] #[ORM\ManyToOne(targetEntity: WishList::class)] #[ORM\JoinColumn(nullable: false)] private ?int $wishList = null; - #[ORM\Column] #[ORM\ManyToOne(targetEntity: User::class)] #[ORM\JoinColumn(nullable: false)] private ?int $user = null; -- GitLab