cakephp / cakephp/phinx

Copying tables, schema only, both schema and data

Open
#633 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
PHP
Stars
4.5k
Forks
884
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation file or test is named in the issue. Start by checking the table API and migration reversal behavior around setColumns(), setIndexes(), setForeignKeys(), setData(), and save(); done means a documented or dedicated operation can copy schema only or schema plus data and can be automatically reversed.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.