Skip to content

Add default value syntax support for bake migration command#970

Merged
markstory merged 6 commits into5.xfrom
feature/default-value-syntax
Nov 25, 2025
Merged

Add default value syntax support for bake migration command#970
markstory merged 6 commits into5.xfrom
feature/default-value-syntax

Conversation

@dereuromark
Copy link
Copy Markdown
Member

Summary

  • Adds support for specifying default column values in the bake migration command using a new default[value] syntax
  • Updated the column grammar in the help text to document the new syntax
  • Added comprehensive tests for the new functionality

Examples

# Boolean defaults
bin/cake bake migration AddActiveToUsers active:boolean:default[true]
bin/cake bake migration AddSkipUpdatesToEventImports skip_updates:boolean:default[false]

# Integer defaults
bin/cake bake migration AddCountToProducts count:integer:default[0]

# String defaults (quoted)
bin/cake bake migration AddStatusToOrders status:string:default['pending']

# Combined with other options
bin/cake bake migration AddCountToProducts count:integer:default[0]:unique
bin/cake bake migration AddRoleToUsers role:string?:default['user']

Supported Value Types

  • Booleans: true, false
  • Integers: 0, 123, -456
  • Floats: 1.5, -2.75
  • Strings: 'hello' or "world" (quoted)
  • Null: null or NULL
  • SQL expressions: CURRENT_TIMESTAMP (passed through as-is)

Test plan

  • All existing tests pass
  • New tests added for parseDefaultValue() method
  • New tests added for parseFields() with default values
  • New tests added for parseIndexes() with default values
  • New tests added for validArguments() with default values
  • Code style checks pass

🤖 Generated with Claude Code

dereuromark and others added 2 commits November 24, 2025 10:59
Adds support for specifying default column values in the bake migration
command using the syntax: `column:type:default[value]`

Examples:
- `active:boolean:default[true]`
- `count:integer:default[0]`
- `status:string:default['pending']`

Supports booleans, integers, floats, strings (quoted), null, and SQL
expressions like CURRENT_TIMESTAMP.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Return null when default value is an empty string (no default specified)
instead of returning the empty string itself.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@markstory markstory left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me.

- Fix return type annotation for getTypeAndLength() using tuple syntax
- Convert string lengths to integers for proper type safety
- Add null coalescing operator for columnType parameter

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dereuromark dereuromark marked this pull request as ready for review November 24, 2025 18:37
dereuromark and others added 2 commits November 24, 2025 19:39
Verify that lengths are returned as integers (not strings) and that
precision/scale arrays contain integers for proper type safety.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dereuromark
Copy link
Copy Markdown
Member Author

Fun fact:
I only ran into this because claude wanted to "bake":

bin/cake bake migration AddActiveToUsers active:boolean:default[true]

and it errored out.
Only to create it manually then.

So that made me think: Sounds reasonable to expect this API yeah

- Update column pattern to include default[value]
- Document supported value types (boolean, int, float, string, null, SQL)
- Add practical examples showing default values in action
- Show how to combine defaults with other options

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@markstory markstory merged commit b037e78 into 5.x Nov 25, 2025
13 checks passed
@markstory markstory deleted the feature/default-value-syntax branch November 25, 2025 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants