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?
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'
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With