-
Notifications
You must be signed in to change notification settings - Fork 633
Allow init goose version table before querying it. #461
Description
When running goose for the first time on a clean DB the following lines are printed to the DB log (using Postgres):
ERROR: relation "goose_db_version" does not exist at character 36
STATEMENT: SELECT version_id, is_applied from goose_db_version ORDER BY id DESCThe reason is that EnsureDBVersion is always trying first to query goose_db_version and only if it fails it creates the version table.
func EnsureDBVersion(db *sql.DB) (int64, error) {
rows, err := GetDialect().dbVersionQuery(db)
if err != nil {
return 0, createVersionTable(db)
}
...While this logic makes sense, we are concerned that our customers running our service will see this error in their database and think this is a bug.
In our service, we have a logic before running any migration that checks if the DB is "clean"/has our tables/has tables we don't know (used to prevent installing our service to a dirty/used database).
I wonder if it is possible to make createVersionTable public so we can call it when we identify the DB is clean and, by doing so, avoid the error in the DB log.
If you are open to this change, I'll be happy to open a PR adding this.