Feature: Allow naming migration files via generate --name - #85
Open
moritzebeling wants to merge 3 commits into
Open
Feature: Allow naming migration files via generate --name#85moritzebeling wants to merge 3 commits into
generate --name#85moritzebeling wants to merge 3 commits into
Conversation
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds optional naming for newly generated migration files via a -n, --name flag, producing a slugified filename suffix and embedding the provided name into the generated migration file content.
Changes:
- Added
-n, --name <name>option to thegenerateCLI command. - Updated
createMigrationto incorporate a slugified name into the generated migration filename and include a name-derived comment in the file body. - Introduced a new
slugifyhelper with accompanying Jest tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
cli.js |
Adds --name option and forwards it to createMigration. |
lib/migration.js |
Uses slugify(name) to build the migration filename and injects a comment into generated content. |
lib/helpers/slugify.js |
New helper for slugifying a provided migration name. |
lib/helpers/slugify.test.js |
Adds Jest coverage for slugify behavior and edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+46
to
52
| const hasName = name && slugify(name); | ||
| const slug = hasName || 'migration'; | ||
| const filename = path.join(directory, `${timestamp}-${slug}.${module ? 'cjs' : 'js'}`); | ||
| const comment = hasName ? `// ${name}` : '// Add your migration code here'; | ||
| const content = stripIndent`${migrationHeader} | ||
| // Add your migration code here | ||
| ${comment} | ||
| })`; |
Comment on lines
+1
to
+9
| const slugify = (text) => | ||
| text | ||
| .toString() | ||
| .replace(/([a-z])([A-Z])/g, '$1-$2') | ||
| .toLowerCase() | ||
| .trim() | ||
| .replace(/[^a-z0-9]+/g, '-') | ||
| .replace(/^-/, '') | ||
| .replace(/-$/, ''); |
| }); | ||
|
|
||
| it('handles leading and trailing hyphens', () => { | ||
| expect(slugify('--hello--')).toBe('hello'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


When generating a new migration, the filename always defaults to
{timestamp}-migration.js, requiring a manual rename to something meaningful. This is especially annoying for automated workflows (e.g. AI coding agents).This PR adds an optional
-n, --nameflag togeneratethat sluggifies the provided name into the filename and places it as a comment inside the generated file. Fully backward-compatible -- omitting the flag preserves the existing behavior.Changes
-n, --name <name>option to thegenerateCLI commandcreateMigrationto use a slugified name in the filename and as in-file commentlib/helpers/slugify.jsutility (zero dependencies, 7 LOC)lib/helpers/slugify.test.jswith 9 test cases covering edge casesHow to test