Skip to content

fix(schema_cache): return results #154

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

Merged
merged 5 commits into from
Dec 14, 2024

Conversation

juleswritescode
Copy link
Collaborator

@juleswritescode juleswritescode commented Dec 13, 2024

We were calling .unwrap() on all database queries that loaded the schemas for the SchemaCache. I changed them so they (and the parent SchemaCache.load(..)) return Results.

Also:

  • I adjusted the callsites were SchemaCache.load() is called
  • I added a SchemaCacheError that implements the Diagnostic trait and implemented From<SchemaCacheError> for WorkspaceError
  • I made sure to use the get_new_test_db() from pg_test_utils in some tests – they were failing for me because of a missing env var, hope this didn't break anything?

Please check:
I'm not sure yet how the whole Diagnostic thing works. Does it need to be implemented for the SchemaCache?
I also wondered if we even want a specific SchemaCacheError type – we could also return a sqlx::Error, since there are only database connections and there's no other fallible business logic?

Lastly, the test_check_sql test in pg_typecheck/src/lib.rs suddenly failed because we're now getting a "contact" instead of an "unknown" string – is this the correct output? :)

Thank yooouuu

@juleswritescode juleswritescode marked this pull request as ready for review December 13, 2024 16:31
@psteinroe
Copy link
Collaborator

Thanks! Regarding the error: I think both approaches are totally valid. I don't think the schema cache will ever return any other error than the one emitted by sqlx. Since the workspace already implements a conversion for sqlx (I think), we could also simplify that here. But we can also keep it like it is now to have it more explicit. Whatever you prefer 🙌

@psteinroe
Copy link
Collaborator

I think the typecheck error could be coming from me accidentally changing the db url to a supabase db url. I have it running always so I tend to just change the url to it so that I don't have to run another db 😅 we can keep the fix in the test, or revert my change.

Copy link
Collaborator

@psteinroe psteinroe left a comment

Choose a reason for hiding this comment

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

awesome! Check my comments for answers to your open points :)

@juleswritescode
Copy link
Collaborator Author

juleswritescode commented Dec 14, 2024

Thanks! Regarding the error: I think both approaches are totally valid. I don't think the schema cache will ever return any other error than the one emitted by sqlx. Since the workspace already implements a conversion for sqlx (I think), we could also simplify that here. But we can also keep it like it is now to have it more explicit. Whatever you prefer 🙌

Let's remove it. It was a nice exercise but the code is simpler without it. :)

Edit: Done ✅

@psteinroe psteinroe merged commit 97679c2 into supabase-community:main Dec 14, 2024
1 check passed
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