Skip to content

Using executeStatement() in up()/down() methods? #1582

@mpdude

Description

@mpdude

In a code review, I spotted someone doing $this->connection->executeStatement() in an up() method. They claim "it works".

My suspicion is that this is just by coincidence, because of the acutal changes made in this particular case, but not generally safe.

I would assume that addSql batches the statements for execution, for dumping to a file or skipping it in a --dry-run – and that would not be possible with direct executeStatement().

The documentation does not address this and I would like to clarify it.

  • May I use direct executeStatement() or executeQuery() in up(), down(), postUp() or postDown()?
  • May/shall I use addSql() in postUp() or postDown()?
  • Are postUp() / postDown() only called when the migrations has actually been executed, i. e. not in a dry-run?
  • What should I be aware of when mixing addSql and other statements?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions