Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations diff and postgres schema problem with recreating existing tables #85

Open
seticzech opened this issue Mar 21, 2019 · 0 comments

Comments

@seticzech
Copy link

Package Version
doctrine/annotations v1.6.0
doctrine/dbal v2.9.2
doctrine/migrations v1.8.1
doctrine/orm v2.6.3
laravel-doctrine/migrations 1.2.0
laravel-doctrine/orm 1.4.9
laravel/framework v5.7.27
PostgreSQL 9.6.11
PHP 7.2.15

Summary

Running doctrine:migrations:diff multiple times without any changes and with existing table in database always generate the same code trying to create table with schema and delete the very same table without schema.

How to reproduce

On any project create entity:

/**
 * @ORM\Entity(repositoryClass = "App\Domain\Repositories\UserRepository")
 * @ORM\Table(name = "users", schema = "public")
 */
class User
{

    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy = "IDENTITY")
     * @ORM\Column(type = "integer")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length = 64, nullable = false, unique = true)
     * @var string
     */
    protected $username;

}

Run doctrine:migrations:diff

Generated migration is ok now:

$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE TABLE public.users (id SERIAL NOT NULL, username VARCHAR(64) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE UNIQUE INDEX UNIQ_2552C48DF85E0677 ON public.users (username)');

Run doctrine:migrations:migrate and table is created succesfully in database.

Run doctrine:migrations:diff and new migration is generated:

$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE TABLE public.users (id SERIAL NOT NULL, username VARCHAR(64) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE UNIQUE INDEX UNIQ_2552C48DF85E0677 ON public.users (username)');
$this->addSql('DROP TABLE users');

Of course next running doctrine:migrations:migrate ends with error

relation "users" already exists

Comment

I don't know if this behavior is related to laravel-doctrine or doctrine itself so I also created bug report in doctrine issue tracker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant