goose icon indicating copy to clipboard operation
goose copied to clipboard

experiemntal: add StoreController to allowing extending interface

Open mfridman opened this issue 1 year ago • 0 comments

This PR adds a *database.StoreController type to allow us to extend goose behavior without breaking the core Store interface.

We can document any optional methods by having a well-defined type like the *database.StoreController. It becomes much easier to reason about in the code than the type assertions and hidden interfaces. A good example of this in the wild is the ResponseController added to the net/http package in Go.

For a practical example see https://github.com/pressly/goose/issues/461. The request here was to support a more graceful operation for checking whether the version table exists or not.

I've gone ahead and implemented the Postgres-specific version of the TableExists() method. And the nice thing is we can incrementally update the rest of the dialect implementations piecemeal.

But we always fallback to some less optimized version if ErrNotSupported is returned.

mfridman avatar Apr 21 '24 02:04 mfridman