>我创建了几个实体:
用户
namespace AppModels;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
/**
* @ORMEntity
* @ORMTable(name="users")
*/
class User {
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue
*/
protected $id;
/**
* @ORMColumn(type="string", length=32, nullable=false)
*/
protected $firstName;
/**
* @ORMColumn(type="string", length=32, nullable=false)
*/
protected $lastName;
/**
* @ORMColumn(type="string", length=100, unique=true, nullable=false)
*/
protected $userName;
/**
* @ORMColumn(type="string", length=100, unique=true, nullable=false)
* @AssertEmail
*/
protected $email;
/**
* @ORMColumn(type="string", length=500, nullable=false)
*/
protected $password;
/**
* @ORMColumn(type="datetime", nullable=true)
*/
protected $created_at;
/**
* @ORMColumn(type="datetime", nullable=true)
*/
protected $updated_at;
...
}
图像
namespace AppModels;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
/**
* @ORMEntity
* @ORMTable(name="images")
* @ORMHasLifecycleCallbacks
*/
class Image {
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue
*/
protected $id;
/**
* @ORMManyToOne(targetEntity="AppModelsUser")
* @ORMJoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user_id;
/**
* @ORMColumn(type="datetime", nullable=true)
*/
protected $created_at;
/**
* @ORMColumn(type="datetime", nullable=true)
*/
protected $updated_at;
/**
* @ORMColumn(type="string", nullable=false)
*/
protected $location;
/**
* @ORMColumn(type="integer", nullable=false)
*/
protected $imageSize;
....
}
当我运行'vendorbindoctrine' migrations:diff
时,它会继续并生成迁移。虽然只是一次迁移...
迁移
namespace ImageUplaoderMigrations;
use DoctrineDBALMigrationsAbstractMigration;
use DoctrineDBALSchemaSchema;
/**
* 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');
}
}
这不是我想要的,我想要个人迁移。我不能一次创建多个实体,然后运行某种命令来生成彼此独立的迁移吗?
首先,迁移工具只是一个工具。它不是从版本生成路径的防弹方式。通常,它用作您将手动修改的模板。
具体回答您的问题,因为该工具旨在比较整体架构。考虑到实体之间存在关系,无论如何都不可能评估单个实体。
不过,我真的不明白您想要拆分迁移的原因。通常,这是一个全有或全无的交易,因为您的应用程序期待一个单一版本(除非您的应用程序真的很聪明!
长话短说,它只是一个开发人员工具,而不是您问题的解决方案。