doctrine / dbal

Doctrine Database Abstraction Layer
https://www.doctrine-project.org/projects/dbal.html
MIT License
9.4k stars 1.33k forks source link

Working with Doctrine Migrations #2491

Open o5 opened 7 years ago

o5 commented 7 years ago

Hi there,

I would like to use Doctrine Migrations with PostgreSQL. I want a table migration_versions in public schema:

$configuration->setMigrationsTableName('public.migration_versions');

I created first migration file and it worked perfectly in first migrations:migrate command execution. But second execution of same command fails:

[Doctrine\DBAL\Exception\TableExistsException]
  An exception occurred while executing 'CREATE TABLE public.migration_versions (version VARCHAR(255) NOT NULL, PRIMARY KEY(version))':
  SQLSTATE[42P07]: Duplicate table: 7 ERROR:  relation "migration_versions" already exists

I ended in source code of DBAL, and this line causes the problem. If I change return statement to

return $table['schema_name'] . "." . $table['table_name'];

problem is fixed. It's interesting because the change is very old.

Any idea? Is there somebody who uses Doctrine Migrations with PostgreSQL?

Versions:

doctrine/migrations: 1.4.1
PostgeSQL 9.5.4

Thank you.

o5 commented 7 years ago

Hmm, here is probably same issue reported in 2013 and still not resolved.

mishal commented 7 years ago

Using any existing namespace for migration table but NOT public does work. If you use public.migration it will fail, when using foobar.migration it will work (if you have that schema in your database)

o5 commented 7 years ago

@mishal: public IS default schema in Postgres and I think it should work.

Possible workarounds:

A: Use an own PostgreSqlSchemaManager and override _getPortableTableDefinition method B: Create an another schema before running migrations CREATE SCHEMA IF NOT EXISTS ...

I used first and hope the interface will not change :)