Migration to database (MariaDB)

+ Change 'Group' to 'TargetGroup'
master
Julien Rosset 6 years ago
parent 0d36b952e4
commit f02753ac62

@ -4,7 +4,3 @@
APP_ENV=dev
APP_SECRET=02d2777e0242595653c8a47180aeba9e
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
DATABASE_URL=pdo-mysql://wishlist:wishlist@localhost:3306/wishlist?serverVersion=mariadb-10.4.7&charset=UTF-8
###< doctrine/doctrine-bundle ###

3
.idea/.gitignore vendored

@ -1,3 +1,6 @@
# Default ignored files
/workspace.xml
/deployment.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="dev - local" uuid="bab97201-1b5a-4cb2-a1de-c485f86aa6a5">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://localhost:3306/wishlist</jdbc-url>
</data-source>
</component>
</project>

@ -16,10 +16,10 @@ class Member {
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Group", inversedBy="members")
* @ORM\JoinColumn(name="group_id", nullable=false)
* @ORM\ManyToOne(targetEntity="App\Entity\TargetGroup", inversedBy="members")
* @ORM\JoinColumn(nullable=false)
*/
private $group;
private $targetGroup;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="memberOfGroups")
@ -35,12 +35,12 @@ class Member {
return $this->id;
}
public function getGroup (): ?Group {
return $this->group;
public function getTargetGroup (): ?TargetGroup {
return $this->targetGroup;
}
public function setGroup (?Group $group): self {
$this->group = $group;
public function setTargetGroup (?TargetGroup $targetGroup): self {
$this->targetGroup = $targetGroup;
return $this;
}

@ -7,9 +7,9 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\GroupRepository")
* @ORM\Entity(repositoryClass="App\Repository\TargetGroupRepository")
*/
class Group
class TargetGroup
{
/**
* @ORM\Id()
@ -68,7 +68,7 @@ class Group
{
if (!$this->members->contains($member)) {
$this->members[] = $member;
$member->setGroup($this);
$member->setTargetGroup($this);
}
return $this;
@ -79,8 +79,8 @@ class Group
if ($this->members->contains($member)) {
$this->members->removeElement($member);
// set the owning side to null (unless already changed)
if ($member->getGroup() === $this) {
$member->setGroup(null);
if ($member->getTargetGroup() === $this) {
$member->setTargetGroup(null);
}
}

@ -85,6 +85,15 @@ class User implements UserInterface
* @var ArrayCollection The user {@see User friends}
*
* @ORM\ManyToMany(targetEntity="App\Entity\User")
* @ORM\JoinTable(
* name="friend",
* joinColumns={
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="friend_id", referencedColumnName="id")
* }
* )
*/
private ArrayCollection $friends;
@ -123,6 +132,13 @@ class User implements UserInterface
*/
private ArrayCollection $comments;
/**
* @var bool Is the user inactive ?
*
* @ORM\Column(type="boolean")
*/
private $inactive;
public function __construct () {
$this->friends = new ArrayCollection();
$this->configNotifications = new ArrayCollection();
@ -431,4 +447,16 @@ class User implements UserInterface
return $this;
}
public function getInactive(): ?bool
{
return $this->inactive;
}
public function setInactive(bool $inactive): self
{
$this->inactive = $inactive;
return $this;
}
}

@ -19,7 +19,7 @@ class Wish {
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Group", inversedBy="wishes")
* @ORM\ManyToOne(targetEntity="App\Entity\TargetGroup", inversedBy="wishes")
* @ORM\JoinColumn(nullable=false)
*/
private $target;
@ -89,11 +89,11 @@ class Wish {
return $this->id;
}
public function getTarget (): ?Group {
public function getTarget (): ?TargetGroup {
return $this->target;
}
public function setTarget (?Group $target): self {
public function setTarget (?TargetGroup $target): self {
$this->target = $target;
return $this;

@ -0,0 +1,85 @@
<?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 Version20200206113340 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->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('CREATE TABLE comment (wish_id INT NOT NULL, user_id INT NOT NULL, date DATETIME NOT NULL, anonymous TINYINT(1) NOT NULL, content LONGTEXT NOT NULL, INDEX IDX_9474526C42B83698 (wish_id), INDEX IDX_9474526CA76ED395 (user_id), PRIMARY KEY(wish_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE config_notification (user_id INT NOT NULL, notif_id INT NOT NULL, site TINYINT(1) NOT NULL, email TINYINT(1) NOT NULL, INDEX IDX_6C50D7BDA76ED395 (user_id), INDEX IDX_6C50D7BD5E61BFFA (notif_id), PRIMARY KEY(user_id, notif_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE language (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE member (id INT AUTO_INCREMENT NOT NULL, target_group_id INT NOT NULL, user_id INT DEFAULT NULL, fakeuser_name VARCHAR(255) DEFAULT NULL, INDEX IDX_70E4FA7824FF092E (target_group_id), INDEX IDX_70E4FA78A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE notification (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE participant (wish_id INT NOT NULL, user_id INT NOT NULL, anonymous TINYINT(1) NOT NULL, price NUMERIC(11, 2) DEFAULT NULL, paid TINYINT(1) NOT NULL, INDEX IDX_D79F6B1142B83698 (wish_id), INDEX IDX_D79F6B11A76ED395 (user_id), PRIMARY KEY(wish_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE target_group (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, language_id INT DEFAULT NULL, email VARCHAR(180) NOT NULL, roles LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, fist_name VARCHAR(255) DEFAULT NULL, gender SMALLINT NOT NULL, avatar VARCHAR(255) DEFAULT NULL, inactive TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), INDEX IDX_8D93D64982F1BAF4 (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE friend (user_id INT NOT NULL, friend_id INT NOT NULL, INDEX IDX_55EEAC61A76ED395 (user_id), INDEX IDX_55EEAC616A5458E8 (friend_id), PRIMARY KEY(user_id, friend_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user_notification (user_id INT NOT NULL, notif_id INT NOT NULL, date DATETIME NOT NULL, description VARCHAR(255) NOT NULL, seen TINYINT(1) NOT NULL, INDEX IDX_3F980AC8A76ED395 (user_id), INDEX IDX_3F980AC85E61BFFA (notif_id), PRIMARY KEY(user_id, notif_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE wish (id INT AUTO_INCREMENT NOT NULL, target_id INT NOT NULL, owner_id INT NOT NULL, date DATETIME NOT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, visible TINYINT(1) NOT NULL, price_estimated NUMERIC(11, 2) DEFAULT NULL, price_real NUMERIC(11, 2) DEFAULT NULL, crowdfunding TINYINT(1) NOT NULL, finished DATETIME DEFAULT NULL, INDEX IDX_D7D174C9158E0B66 (target_id), INDEX IDX_D7D174C97E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C42B83698 FOREIGN KEY (wish_id) REFERENCES wish (id)');
$this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526CA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE config_notification ADD CONSTRAINT FK_6C50D7BDA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE config_notification ADD CONSTRAINT FK_6C50D7BD5E61BFFA FOREIGN KEY (notif_id) REFERENCES notification (id)');
$this->addSql('ALTER TABLE member ADD CONSTRAINT FK_70E4FA7824FF092E FOREIGN KEY (target_group_id) REFERENCES target_group (id)');
$this->addSql('ALTER TABLE member ADD CONSTRAINT FK_70E4FA78A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE participant ADD CONSTRAINT FK_D79F6B1142B83698 FOREIGN KEY (wish_id) REFERENCES wish (id)');
$this->addSql('ALTER TABLE participant ADD CONSTRAINT FK_D79F6B11A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE user ADD CONSTRAINT FK_8D93D64982F1BAF4 FOREIGN KEY (language_id) REFERENCES language (id)');
$this->addSql('ALTER TABLE friend ADD CONSTRAINT FK_55EEAC61A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE friend ADD CONSTRAINT FK_55EEAC616A5458E8 FOREIGN KEY (friend_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE user_notification ADD CONSTRAINT FK_3F980AC8A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE user_notification ADD CONSTRAINT FK_3F980AC85E61BFFA FOREIGN KEY (notif_id) REFERENCES notification (id)');
$this->addSql('ALTER TABLE wish ADD CONSTRAINT FK_D7D174C9158E0B66 FOREIGN KEY (target_id) REFERENCES target_group (id)');
$this->addSql('ALTER TABLE wish ADD CONSTRAINT FK_D7D174C97E3C61F9 FOREIGN KEY (owner_id) REFERENCES user (id)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE user DROP FOREIGN KEY FK_8D93D64982F1BAF4');
$this->addSql('ALTER TABLE config_notification DROP FOREIGN KEY FK_6C50D7BD5E61BFFA');
$this->addSql('ALTER TABLE user_notification DROP FOREIGN KEY FK_3F980AC85E61BFFA');
$this->addSql('ALTER TABLE member DROP FOREIGN KEY FK_70E4FA7824FF092E');
$this->addSql('ALTER TABLE wish DROP FOREIGN KEY FK_D7D174C9158E0B66');
$this->addSql('ALTER TABLE comment DROP FOREIGN KEY FK_9474526CA76ED395');
$this->addSql('ALTER TABLE config_notification DROP FOREIGN KEY FK_6C50D7BDA76ED395');
$this->addSql('ALTER TABLE member DROP FOREIGN KEY FK_70E4FA78A76ED395');
$this->addSql('ALTER TABLE participant DROP FOREIGN KEY FK_D79F6B11A76ED395');
$this->addSql('ALTER TABLE friend DROP FOREIGN KEY FK_55EEAC61A76ED395');
$this->addSql('ALTER TABLE friend DROP FOREIGN KEY FK_55EEAC616A5458E8');
$this->addSql('ALTER TABLE user_notification DROP FOREIGN KEY FK_3F980AC8A76ED395');
$this->addSql('ALTER TABLE wish DROP FOREIGN KEY FK_D7D174C97E3C61F9');
$this->addSql('ALTER TABLE comment DROP FOREIGN KEY FK_9474526C42B83698');
$this->addSql('ALTER TABLE participant DROP FOREIGN KEY FK_D79F6B1142B83698');
$this->addSql('DROP TABLE comment');
$this->addSql('DROP TABLE config_notification');
$this->addSql('DROP TABLE language');
$this->addSql('DROP TABLE member');
$this->addSql('DROP TABLE notification');
$this->addSql('DROP TABLE participant');
$this->addSql('DROP TABLE target_group');
$this->addSql('DROP TABLE user');
$this->addSql('DROP TABLE friend');
$this->addSql('DROP TABLE user_notification');
$this->addSql('DROP TABLE wish');
}
}

@ -2,21 +2,21 @@
namespace App\Repository;
use App\Entity\Group;
use App\Entity\TargetGroup;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
/**
* @method Group|null find($id, $lockMode = null, $lockVersion = null)
* @method Group|null findOneBy(array $criteria, array $orderBy = null)
* @method Group[] findAll()
* @method Group[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
* @method TargetGroup|null find($id, $lockMode = null, $lockVersion = null)
* @method TargetGroup|null findOneBy(array $criteria, array $orderBy = null)
* @method TargetGroup[] findAll()
* @method TargetGroup[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class GroupRepository extends ServiceEntityRepository
class TargetGroupRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Group::class);
parent::__construct($registry, TargetGroup::class);
}
// /**
Loading…
Cancel
Save