laravel-doctrine / migrations

Integration with Doctrine2's migrations package for Laravel
MIT License
75 stars 77 forks source link

[Bug] Refresh command command not working with filtered tables #84

Open kennaar opened 5 years ago

kennaar commented 5 years ago

Hi,

I'm trying to use the refresh command to rollback and migrate my database. I have a migration for a password_resets table. When I run the refresh command, internally it calls the reset command and it doesn't drop the password_resets table because I have it in my migrations.schema.filter regex listed. Then the refresh command calls the migrate command and it tries to create the password_resets table because this command doesn't account for the filter.

Removing it from the filter regex also isn't any good because then the diff command generates a migration to drop the table every time.

I think I'm doing something wrong like I should provide an extra option when running the command, but there doesn't seem to be any option.

Thanks in advance

SPie commented 5 years ago

You can use the Builder::hasTable($tableName) method so you only create a table if it doesn't exist already.

public function up(Schema $schema)
{
    $builder = new Builder($schema);
    if (!$builder->hasTable('password_reset')) {
        $builder->create('password_reset', function (Table $table) {
            // create table
        });
    }
}