Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying a nullable field #203 #249

Merged
merged 8 commits into from Jun 23, 2016

Conversation

nitincoded
Copy link
Contributor

This patch provides the ability to specify that a column is nullable in a migration from the CakePHP bake command line by adding a question mark as a suffix to the column data type.

Example:
bin/cake bake migration CreatePerson name:string description:string? age:integer?

The patch applies to the ColumnParser class in src/Util/ColumnParser.php file and the diff can be found at:
nitincoded@bd453ee

A test was also added to the PHP Unit test in the ColumnParserTest class.

nitincoded and others added 6 commits June 22, 2016 09:37
Adds support for using the "?" as a suffix to the column data type to indicate that it is nullable.
Example:
    bin/cake bake migration CreatePerson name:string description:string? age:integer?
name:string description:string? age:integer?
…n comparison for the generated integer column
@@ -51,11 +51,14 @@ public function parseFields($arguments)
}
}

$nullable = substr($type, -1) == '?';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ===

@codecov-io
Copy link

codecov-io commented Jun 22, 2016

Current coverage is 33.25%

Merging #249 into master will decrease coverage by 0.03%

@@             master       #249   diff @@
==========================================
  Files            31         31          
  Lines          1748       1750     +2   
  Methods         212        212          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits            582        582          
- Misses         1166       1168     +2   
  Partials          0          0          

Powered by Codecov. Last updated by 71850bd...a8f0f21

@nitincoded
Copy link
Contributor Author

@dereuromark Thank you for your feedback. I have just made the changes that you have suggested, and I pushed them to the fork; the committed changes now appear in the pull request.

@@ -51,11 +51,14 @@ public function parseFields($arguments)
}
}

$nullable = substr($type, -1) === '?';
$type = $nullable ? substr($type, 0, strlen($type) - 1) : $type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The substr($type, 0, strlen($type) - 1) part could be replaced with only substr($type, 0, -1)

@HavokInspiration
Copy link
Member

Other than my comment, this looks good to me.
Thanks for your contribution @nitincoded !

@nitincoded
Copy link
Contributor Author

@HavokInspiration : I have made the change that you suggested and I look forward to your continued guidance in future.

@dereuromark dereuromark merged commit be84a7e into cakephp:master Jun 23, 2016
@dereuromark
Copy link
Member

Great work!

@bravo-kernel
Copy link

👏

@lorenzo
Copy link
Member

lorenzo commented Jun 23, 2016

Good job!

@lorenzo
Copy link
Member

lorenzo commented Jun 23, 2016

@nitincoded Would you mind changing the docs to add this new feature?

nitincoded added a commit to nitincoded/docs that referenced this pull request Jun 23, 2016
This feature is being introduced in cakephp/migrations v1.6.3.

Reference: Issue cakephp/migrations#203 / PR cakephp/migrations#249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants