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

Max length for naming #275

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Conversation

0del
Copy link
Contributor

@0del 0del commented Feb 5, 2024

TODO list:

  • Apply max length validation for temporary name
  • Operations validation
  • Schema name validation
  • triggers name validation

fixes: #64

@0del 0del changed the title Max length temporary name WIP: Max length temporary name Feb 5, 2024
@0del 0del changed the title WIP: Max length temporary name WIP: Max length for naming Feb 5, 2024
@0del 0del changed the title WIP: Max length for naming Max length for naming Feb 7, 2024
pkg/migrations/errors.go Outdated Show resolved Hide resolved
pkg/migrations/errors.go Outdated Show resolved Hide resolved
pkg/migrations/types.go Outdated Show resolved Hide resolved
pkg/roll/execute.go Outdated Show resolved Hide resolved
pkg/migrations/op_add_column.go Outdated Show resolved Hide resolved
pkg/migrations/op_set_fk.go Outdated Show resolved Hide resolved
0del and others added 8 commits February 15, 2024 07:12
Signed-off-by: Alexis Rico <sferadev@gmail.com>
Signed-off-by: Alexis Rico <sferadev@gmail.com>
@SferaDev
Copy link
Member

SferaDev commented Mar 1, 2024

@andrew-farries Updated with main and applied the changes to make CI checks pass

0del and others added 2 commits March 1, 2024 23:32
}

func (e InvalidNameLengthError) Error() string {
return fmt.Sprintf("max length of %q is %d", e.Name, e.Max)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return fmt.Sprintf("max length of %q is %d", e.Name, e.Max)
return fmt.Sprintf("length of %q (%d) exceeds maximum length of %d", e.Name, len(e.Name), e.Max)

Comment on lines +8 to +17
func validateName(name string) error {
if len(name) > MaxNameLength {
return InvalidNameLengthError{Name: name, Max: MaxNameLength}
}
return nil
}

func ValidateName(name string) error {
return validateName(name)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Get rid of validateName and use the exported ValidateName everywhere.

Comment on lines +141 to +145

if err := validateName(o.Column); err != nil {
return err
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it makes sense to check the length of the column name on the operation here as it must already exist in the database. The check can be removed.

Comment on lines +59 to +61
if err := validateName(o.Column); err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it makes sense to check the length of the column name on the operation here as it must already exist in the database. The check can be removed.

Comment on lines +125 to +128
if err := validateName(o.Column); err != nil {
return err
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it makes sense to check the length of the column name on the operation here as it must already exist in the database. The check can be removed.

Comment on lines +147 to +150
if err := validateName(o.Column); err != nil {
return err
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it makes sense to check the length of the column name on the operation here as it must already exist in the database. The check can be removed.

Comment on lines +148 to +150
if err := validateName(o.Column); err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it makes sense to check the length of the column name on the operation here as it must already exist in the database. The check can be removed.

Comment on lines +165 to +168
if err := validateName(o.Column); err != nil {
return err
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it makes sense to check the length of the column name on the operation here as it must already exist in the database. The check can be removed.

Comment on lines +153 to +155
if err := validateName(o.Column); err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it makes sense to check the length of the column name on the operation here as it must already exist in the database. The check can be removed.

Comment on lines +115 to +117
if err := migrations.ValidateName(versionSchema); err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is too late to check the length of the new version schema - at this point a potentially lengthy migration start operation has already taken place so it's a poor user experience for the migration to fail with a validation check at this stage. I'd remove the check here and if we need it we can add a check earlier in the migration start process as a separate PR.

@andrew-farries
Copy link
Collaborator

Bump @0del 👋

This PR is almost ready to go; it just needs some removals.

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.

Add guards for names max length
3 participants