Postgres issue with 'relation "goose_db_version" does not exist'
When running a 'goose up' command for a SQL migration with a configured Postgres database, I get the following error:
2014/04/30 11:56:15 error finalizing migration 20140429165615_InitialSchema.sql, quitting. (pq: relation "goose_db_version" does not exist)
I've tracked this down to a problem with the search_path that is available when using the txn object instantiated from calling db.Begin in the migration_sql.go runSQLMigration method. For some reason, at least in my configuration of Postgres, the search_path for this context does not include the public schema. For example, adding this code to the runSQLMigration method:
sPath, err := txn.Query("SHOW search_path;")
if err != nil {
log.Println(err)
}
for sPath.Next() {
var path string
err := sPath.Scan(&path)
log.Println("search_path:", path)
if err != nil {
log.Println(err)
}
}
produces:
search_path: {my_schema_from_dbconf.yml}, pg_catalog
Adding similar code to query against the db object returns:
search_path: "$user",public
Since the public schema is optional, I removed it and got another error: permission denied to create "pg_catalog.goose_db_version_id_seq"
I'm kind of new to Postgres, so maybe I just have something configured wrong. Any helpful hints would be appreciated.
Comments (4)
-
-
Also, changing instances of the reference to
goose_db_version
topublic.goose_db_version
works, but not sure this is the "right thing" since public is optional. -
Figured it out! I was using a SQL migration and there was a statement in there that set the search_path that I hadn't seen. Removing this fixes the issue.
-
repo owner - changed status to resolved
great! setting this to resolved - please re-open or re-file if there's still an issue.
- Log in to comment
Whoops, I wasn't logged in.
Anonymous
= me :)