Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip a statement in a Doctrine migration if a column is present?

Tags:

php

doctrine

I am working with Doctrine migrations. I just learned about the skipIf() method in the AbstractMigration class, and I would like to use it to skip over some code if a column exists.

Can someone provide an example of how I might do that?

like image 584
Patrick Avatar asked Oct 17 '25 04:10

Patrick


1 Answers

If you have the typical Schema class in your method, you can do something like this:

public function up(Schema $schema)
{
    if (!$schema->getTable('your_table')->hasColumn('your_column')) {
        // do your code
    }
}

Or, if you want to use the skipIf you should be able to do the following though I have not tested.

public function up(Schema $schema)
{
    $this->skipIf(
        $schema->getTable('your_table')->hasColumn('your_column'), 
        'Skipping because `your_column` exists'
    );
}
like image 106
OK sure Avatar answered Oct 19 '25 22:10

OK sure