phinx
phinx copied to clipboard
Copying tables, schema only, both schema and data
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.
+1
Are you able to provide a patch with your suggested changes as PR?
Still interested, but too busy to do it now.
Just to check: I don't think this already has been implemented as a feature right?