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

fix: allow for long lines in SQL migrations #472

Merged
merged 2 commits into from
Sep 24, 2022
Merged

fix: allow for long lines in SQL migrations #472

merged 2 commits into from
Sep 24, 2022

Conversation

FelixZY
Copy link
Contributor

@FelixZY FelixZY commented Sep 24, 2022

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

When lines that are too long are encountered, the scanner in internal/utils/parser/token.go#Split fails, but the .Err() is not checked, causing the error to be suppressed and the internal/utils/parser/token.go#Split func to return partial data.

See #470

What is the new behavior?

  • Errors produced by the scanner used in internal/utils/parser/token.go#Split are propagated to the caller.
  • Lines up to 256K can now be read by internal/utils/parser/token.go#Split.

For really long lines, it is possible for the scanner to run out of
buffer space, resulting in

```go
scanner.Err() // bufio.Scanner: token too long
```

This error was not checked however, causing a silent failure which was
supressed.

This commit adds a check for `scanner.Err()` and properly propagates any
non-nil values.
@FelixZY FelixZY requested a review from a team as a code owner September 24, 2022 12:21
Copy link
Contributor

@sweatybridge sweatybridge left a comment

Choose a reason for hiding this comment

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

Thanks a lot for looking into this issue and fixing. Just a minor suggestion before merging.

@sweatybridge sweatybridge changed the title #470: Allow for long lines in SQL migrations fix: allow for long lines in SQL migrations Sep 24, 2022
@coveralls
Copy link

coveralls commented Sep 24, 2022

Pull Request Test Coverage Report for Build 3118377043

  • 13 of 17 (76.47%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 39.832%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/db/diff/migra.go 3 5 60.0%
internal/db/reset/reset.go 3 5 60.0%
Totals Coverage Status
Change from base Build 3110861124: 0.08%
Covered Lines: 1992
Relevant Lines: 5001

💛 - Coveralls

For really long lines, it is possible for the scanner to run out of
buffer space, resulting in

```go
scanner.Err() // bufio.Scanner: token too long
```

Following [this](https://stackoverflow.com/a/39864391/1137077)
suggestion from Stack Overflow, this commit implements a workaround
where the maximum buffer capacity is increased from 64K to 256K. Testing
against the SQL file with geodata from #470 showed that already 128K was
enough to resolve that issue. 256K is double that and - as a wise man
once said - "ought to be enough for anybody".
@sweatybridge sweatybridge merged commit aa6a512 into supabase:main Sep 24, 2022
@github-actions
Copy link

🎉 This PR is included in version 1.4.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

3 participants