Skip to content

Conversation

@kalistratovtimofey
Copy link
Contributor

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Fix regex to properly cut default value for default empty string and default whitespace

User Case Description

I've faced extra "ALTER TABLE..." requests on every app start with Gorm auto-migrate. Investigated that Gorm doesn't cut properly "default" value, if it is empty string or whitespace. Returned to case with 2 separate regexes that was first added in #143 (comment)


if column.DefaultValueValue.Valid {
column.DefaultValueValue.String = regexp.MustCompile(`'?(.*)\b'?:+[\w\s]+$`).ReplaceAllString(column.DefaultValueValue.String, "$1")
column.DefaultValueValue.String = regexp.MustCompile(`'(.*)'::[\w\s]+$`).ReplaceAllString(column.DefaultValueValue.String, "$1")
Copy link
Member

Choose a reason for hiding this comment

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

Hi @kalistratovtimofey

Can you write some tests for this PR?

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