Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop table doesn't work as expected #2211

Open
algorhythm opened this issue Aug 21, 2023 · 0 comments
Open

Drop table doesn't work as expected #2211

algorhythm opened this issue Aug 21, 2023 · 0 comments

Comments

@algorhythm
Copy link
Contributor

algorhythm commented Aug 21, 2023

The documentation says to use the following code when deleting a table:

$this->table('table')->drop()->save();

https://book.cakephp.org/phinx/0/en/migrations.html#dropping-a-table

But in my opinion it's better using:

$this->table('table')->drop()->update();

...because if the table doesn't exists and when executing Table::executeActions(), the actions will contain DropTable and a dynamically added CreateTable action. That makes no sense.

This is due to the following code:

/**
 * Executes all the pending actions for this table
 *
 * @param bool $exists Whether or not the table existed prior to executing this method
 * @return void
 */
protected function executeActions(bool $exists): void
{
    /* ... */

    // If the table does not exist, the last command in the chain needs to be
    // a CreateTable action.
    if (! $exists) {
        $this->actions->addAction(new CreateTable($this->table));
    }

    /* ... */
}

So am I using the save and update methods in a wrong way and then the documentation needs to be changed or is it a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant