kitloong / laravel-migrations-generator

Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.
MIT License
2.43k stars 269 forks source link

Custom postgres types fails if there is an index on the type #198

Closed esbenp closed 4 weeks ago

esbenp commented 7 months ago

Describe the bug

107 added support for custom postgres types. The problem is the type is added outside of the normal migration, which is a problem if said column is also in an index on the table

To Reproduce

  1. Create table with column that is a type, but which also has an index on that column
  2. Generate migrations

This will create a migration ala

public function up()
{
    Schema::create('table', function (Blueprint $table) {
        ...

        $table->index(['column']);
    });
    DB::statement("ALTER TABLE table ADD column custom_type NOT NULL");
}

Which will fail since column is not defined when the index is added

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Details (please complete the following information):

Additional context Add any other context about the problem here.

esbenp commented 7 months ago

Correction: I think this only happens if it's part of a composite index

kitloong commented 4 weeks ago

@esbenp Thank you for raising the issue.

I was finally able to fix this after a while, sorry for taking for a while.

esbenp commented 4 weeks ago

Thanks!