phinx icon indicating copy to clipboard operation
phinx copied to clipboard

Copying tables, schema only, both schema and data

Open berarma opened this issue 10 years ago • 4 comments

I want to copy a table in one of my migrations, in one case I want to copy everything but in another case I just want to use the same schema. I don't know if this can be already done, I'm new to Phinx and I couldn't find anything in the docs.

Right now I'm using MySQL statements to do this operations but this can't be automatically reversed.

I've thought I could do something like the following but I'd like some kind of confirmation:

public function change()
{
    $original = $this->table('original');
    $copy = $this->table('copy');
    $copy->setColumns($original->getColumns())
         ->setIndexes($original->getIndexes())
         ->setForeignKeys($original->getForeignKeys())
         ->setData($original->getData()) // Just in case I want a full copy
         ->save();
}

I'm also opening this issue to suggest implementing this functionality in its own method saving some calls and maybe mistakenly missing some others. Or just in case it's something that could be added to the docs.

berarma avatar Sep 02 '15 08:09 berarma

+1

tendallas avatar Dec 10 '15 16:12 tendallas

Are you able to provide a patch with your suggested changes as PR?

dereuromark avatar Mar 01 '18 20:03 dereuromark

Still interested, but too busy to do it now.

berarma avatar Mar 02 '18 08:03 berarma

Just to check: I don't think this already has been implemented as a feature right?

GlennM avatar Aug 25 '20 11:08 GlennM