Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

Serialization issue when copying AlterTableCommand #29

Description

@krystof018

Hello, I came across bug when creating new instance of AlterTableCommand from old one.

$actions = getMeNewActions($originalCommand);

 $newCommand = new AlterTableCommand(
    $originalCommand->getTable(),
    $actions,
    $originalCommand->getAlterOptions(),
    $originalCommand->getOptionsList(), // this causes the problem
    $originalCommand->getPartitioning(),
);

Problem is with AlterTableCommand::getOptionsList().

public function getOptionsList(): TableOptionsList
{
    return $this->tableOptions ?? new TableOptionsList([]);
}

This would not be problematic itself if serialization of AlterTableCommand did not depend on null check:

// in AlterTableCommand::serialize() line 127
if ($this->tableOptions !== null) {
    if (!$this->actions->isEmpty()) {
        $result .= ',';
    }
    $result .= "\n" . $formatter->indent . $this->tableOptions->serialize($formatter, ",\n", ' ');
}

The logic should probably check if the TableOptionsList is empty so the comma + \n + indent there is not added without reason since empty TableOptionsList serializes to ''.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions