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

Check to make sure migration name is valid #879

Closed

Conversation

AngelOnFira
Copy link
Contributor

@AngelOnFira AngelOnFira commented Jul 16, 2022

I created a migration named initial-tables, however, I had to change it since it wasn't valid as a Rust module name.

image

I'm sure there are some other characters that should be filtered out, but I didn't look too deep. Also, I created a custom error for this, but I'm not super sure if that's the cleanest place to put it. I can make any changes necessary :)

@tyt2y3 tyt2y3 requested a review from billy1624 July 17, 2022 08:40
@tyt2y3
Copy link
Member

tyt2y3 commented Jul 17, 2022

Hi @AngelOnFira welcome back!

Comment on lines +256 to +262
// Make sure the migration name doesn't contain any characters that
// are invalid module names in Rust.
if migration_name.contains('-') {
return Err(Box::new(MigrationCommandError::InvalidName(
"Invalid character used in migration name".to_string(),
)));
}
Copy link
Member

Choose a reason for hiding this comment

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

Hey @AngelOnFira, sorry for the delay. I think the error message can be more specific? E.g. hyphen - cannot be used in migration name

Copy link
Member

Choose a reason for hiding this comment

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

Such as...

Suggested change
// Make sure the migration name doesn't contain any characters that
// are invalid module names in Rust.
if migration_name.contains('-') {
return Err(Box::new(MigrationCommandError::InvalidName(
"Invalid character used in migration name".to_string(),
)));
}
// Make sure the migration name doesn't contain any characters that
// are invalid module names in Rust.
if migration_name.contains('-') {
return Err(Box::new(MigrationCommandError::InvalidName(
"Hyphen `-` cannot be used in migration name".to_string(),
)));
}

Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

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

One more nitpick, could we have a test case for this new behaviour? I want this behaviour to be checked and persisted in years to come :)
Thank you so much for the great contributions!

@billy1624 billy1624 changed the base branch from master to catch-invalid-migration-name October 26, 2022 09:25
@billy1624 billy1624 changed the base branch from catch-invalid-migration-name to master October 26, 2022 09:29
@billy1624 billy1624 closed this Oct 26, 2022
Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

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

Hey @AngelOnFira, I'll continue the work on #1155 :)

@AngelOnFira AngelOnFira deleted the catch-invalid-migration-name branch November 2, 2022 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants