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
Conversation
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) == '?'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ===
Current coverage is 33.25%@@ 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
|
@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; |
There was a problem hiding this comment.
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)
Other than my comment, this looks good to me. |
@HavokInspiration : I have made the change that you suggested and I look forward to your continued guidance in future. |
Great work! |
👏 |
Good job! |
@nitincoded Would you mind changing the docs to add this new feature? |
This feature is being introduced in cakephp/migrations v1.6.3. Reference: Issue cakephp/migrations#203 / PR cakephp/migrations#249
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.