feat: postgres migration table existence check#860
Merged
Conversation
mfridman
commented
Nov 23, 2024
| } | ||
|
|
||
| func (p *Postgres) TableExists(tableName string) string { | ||
| schemaName, tableName := parseTableIdentifier(tableName) |
Collaborator
Author
There was a problem hiding this comment.
This should handle cases where the table name contains the schema name; otherwise, assumed public.
mfridman
commented
Nov 23, 2024
| b = retry.WithMaxRetries(3, b) | ||
| return retry.Do(ctx, b, func(ctx context.Context) error { | ||
| if e, ok := p.store.(interface { | ||
| TableExists(context.Context, database.DBTxConn, string) (bool, error) |
Collaborator
Author
There was a problem hiding this comment.
The whole point of this PR was to make this a "well-defined" method part of the extended Store interface.
By having this inlined, makes it difficult to understand where else in the codebase there might be such hidden interfaces.
But with the concept of the "controller" there's a single place where users (and us) can look to discover these.
mfridman
commented
Nov 23, 2024
| type customStoreSQLite3 struct { | ||
| database.Store | ||
| } | ||
| var _ database.StoreExtender = (*customStoreSQLite3)(nil) |
Collaborator
Author
There was a problem hiding this comment.
This feels much nicer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #461
This PR introduces an extension mechanism for
Storeimplementations to optimize database operations. The first extension is table existence checking, which improves performance and reduces error logging noise.New Interface
Benefits
Implementation
The postgres implementation uses native
pg_tablesqueries, serving as a template for other dialects.I initially tried out the store controller in #752, and I didn't mind it. But decided to keep it ./internal since only the guts of goose should care about this.
The only thing end-users need to know is that they can implement the above method on their custom
Store. And for maintainers, all we need to do to add support is follow the postgres example.