pressly / goose

A database migration tool. Supports SQL migrations and Go functions.
http://pressly.github.io/goose/
Other
6.65k stars 505 forks source link

Goose returns incorrect error when multiple DB users try to up migrations #800

Open R0masik opened 1 month ago

R0masik commented 1 month ago

I have Postgres and 2 users in it (user1 and user2) with all granted rights. I run migrations as user1 and it completed successfully, then I try to run the same migrations from user2, but I get error relation "goose_db_version" already exists, although the real error is that permission to read "goose_db_version" table is denied for user2.

The problem is in the line https://github.com/pressly/goose/blob/master/migrate.go#L216, goose tries to get list of migrations and after getting any error tries to create table "goose_db_version". This is confusing, I think it is necessary to create table "goose_db_version" only if it does not exist and return error in any other case.

mfridman commented 3 weeks ago

Are you running things in parallel? Also, are you using goose as a CLI or importing it as a library without your application?

R0masik commented 2 weeks ago

I use goose as a library in my go app. It doesn't really matter whether you perform migrations sequentially or in parallel: the user who created "goose_db_version" table will have access to it, but others will not. If I grant permissions to other users to read "goose_db_version" table, the error is gone.

The problem is that goose doesn't return a real error as I pointed out in the post above, and that's misleading.