cakephp / cakephp/phinx

Replace the column options array with an object

Open
#1,879 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

As already suggested 2 years ago https://github.com/cakephp/phinx/issues/249#issuecomment-373716784

// suggested backward compatible way, using a factory to create the object
$this->table('some_table')
	->addColumn(Column::text('name')->length(212)->notNull())
	->addColumn(Column::bool('active')->default(false)
	->update();

// even shorter complementary API, use the factory internally and provide methods
$this->table('some_table')
	->addTextColumn('name')->length(212)->notNull()
	->addBoolColumn('active')->default(false)
	->update();

// old way
$this->table('some_table')
	->addColumn('name', 'text', ['length' => 212, 'null' => false])
	->addColumn('active', 'bool', ['default' => false])
	->update();

The first example would require a check inside of the addColumn() method if it's only one arg and if it is of a specific interface (ColumnFactoryInterface?). The second example would not require and backward compatibility change to addColumn() but provide new expressive methods for add a specific column type.

I think we really don't need to have a discussion about the obvious advantages of using an expressive object oriented notation over the fugly arrays. Do we?

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

Start by reviewing the table() and addColumn() API shown in the issue, along with the earlier discussion in issue #249. Compare the proposed Column factory and typed helper approaches, then determine which backward-compatible object API should replace or complement the current array form. Done means the chosen API is implemented with compatibility behavior and covered by the project's relevant migration tests.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.