Reputation: 12923
I have a couple entities that I created:
namespace App\Models;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Column(type="string", length=32, nullable=false)
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=32, nullable=false)
*/
protected $lastName;
/**
* @ORM\Column(type="string", length=100, unique=true, nullable=false)
*/
protected $userName;
/**
* @ORM\Column(type="string", length=100, unique=true, nullable=false)
* @Assert\Email
*/
protected $email;
/**
* @ORM\Column(type="string", length=500, nullable=false)
*/
protected $password;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $updated_at;
...
}
namespace App\Models;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="images")
* @ORM\HasLifecycleCallbacks
*/
class Image {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="\App\Models\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user_id;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $updated_at;
/**
* @ORM\Column(type="string", nullable=false)
*/
protected $location;
/**
* @ORM\Column(type="integer", nullable=false)
*/
protected $imageSize;
....
}
When I run 'vendor\bin\doctrine' migrations:diff
it goes ahead and generates a migration. Just one migration though ...
namespace ImageUplaoder\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20150430210959 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// 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 images (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, location VARCHAR(255) NOT NULL, imageSize INT NOT NULL, INDEX IDX_E01FBE6AA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, firstName VARCHAR(32) NOT NULL, lastName VARCHAR(32) NOT NULL, userName VARCHAR(100) NOT NULL, email VARCHAR(100) NOT NULL, password VARCHAR(500) NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_1483A5E9586CA949 (userName), UNIQUE INDEX UNIQ_1483A5E9E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE images ADD CONSTRAINT FK_E01FBE6AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id)');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// 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 images DROP FOREIGN KEY FK_E01FBE6AA76ED395');
$this->addSql('DROP TABLE images');
$this->addSql('DROP TABLE users');
}
}
This is not what I want, I wanted individual migrations. Can I not create multiple entities at once and then run some kind of command to generate migrations that all individual of each other?
Upvotes: 2
Views: 197
Reputation: 5084
Firstly, the migration tool is just a tool. It is not meant as a bulletproof way to generate paths from versions. Generally, it is used as a template to which you will manually modify.
To answer your question specifically, because the tool is designed to compare the overall schema. Considering there are relationships between entities, it isn't even possible to evaluate individual entities anyways.
I don't really understand your reasoning for wanting to split up the migrations though. Normally, it's an all-or-nothing deal since your application is expecting a singular version (unless your application is really smart!).
Long story short, it's just a developer tool, not a solution to your problem.
Upvotes: 2