cycle / database

Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
MIT License
54 stars 22 forks source link

Postgresql migrations endlessly tries to create enums #180

Closed Eugentis closed 5 months ago

Eugentis commented 2 years ago

We have PostgreSQL table state like:

create table logs
(
    ...,
    target      varchar(7)
        constraint logs_target_enum_62e2522d7df9c
            check ((target)::text = 'catalog'::text)
);

but cycle:migrate can't detect that field already have enum type and each next migration tries to fix it in next way:

class OrmDefault561cd35f5d5487d642a5bd8b65997299 extends Migration
{
    public function up(): void
    {        
        $this->table('logs')
            ->alterColumn('target', 'enum', [
                'nullable' => true,
                'default'  => null,
                'values'   => [
                    'catalog'
                ]
            ])
            ->update();
    }

    public function down(): void
    {
        $this->table('logs')
            ->alterColumn('target', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 7
            ])
            ->update();
    }
}

As I can see migrator can't understand that field already have enum functionality based on constraints

Eugentis commented 2 years ago

One more comment - it is actual only for cases when enum contains only one value