cakephp / cakephp/phinx

A way to add functions like addTimeStamps

Open
#1,530 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

something like:

$table->addMethod('addUserIds', function($table) {
  $table->addColumn('created_by', 'integer', ['unsigned' => true, 'null' => true])
            ->addColumn('updated_by', 'integer', ['unsigned' => true, 'null' => true])
            ->addColumn('deleted_by', 'integer', ['unsigned' => true, 'null' => true]);
});

Then you could:

$table->addTimestamps()->addUserIds()->create();

Or any number of standardized columns. Is there a way to do this already that maybe I have overlooked? I have considered extending the AbstractMigration class but I'm not sure that would get me there.

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

Review the existing migration and table APIs, including AbstractMigration, to determine whether custom chained methods such as addUserIds can already be defined. Compare that behavior with the proposed addMethod example and document or implement a supported way to add standardized column helpers; done means the example can be used during a migration without duplicating the column definitions.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.