-
Notifications
You must be signed in to change notification settings - Fork 881
"Relation does not exist" error when using SQLC with goose migrations #3444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is happening to me too. |
I think I've found the issue: when the migrations are loaded if you're using numbers for the migrations, e.g. 001, 002, ..., etc. The files don't get sorted correctly passed 009 and so 0010 is run before 001. You can see this in the parseCatalog() function in compile.go (see image below) Not sure who the best person is to mention here, but I'm happy to create a pr for this. Should I use a regex to detect the file format name? Or is there a way you would rather handle this? |
Digging into this a little more the culprit seems to be the os.ReadDir call in the sqlpath.Glob() function. It's sorting the files by name and doesn't handle the numbering of the migrations correctly |
Quick FixLeaving this here for anyone who runs into this and needs a quick fix, one that avoids having to rename all your existing migrations:
schema:
- "schema.sql"
PGPASSWORD=<PASSWORD> pg_dump -h localhost -p 5432 -s -U <USER> <DATABASE> > schema.sql |
Noah's quick fix didn't work for me, but changing the goose comment from: Using SQLITE3
Query:
Config:
sqlc.mp4 |
Version
1.26.0
What happened?
I'm integrating sqlc into an existing golang project using Goose. When I run sqlc generate I'm getting the following error:
migrations/0036_source_table_embeddings.sql:1:1: relation "global_metric" does not exist
The table does exist and is in an earlier migration file. Strangely if remove the lines referencing that table in the migration file referenced in the error, sqlc generate runs successfully.
The table in question is created in migration 5 and if I use it in any migration before migration 9 sqlc generate runs successfully, if I include it in any migration after migration 9 I get the above error of the reference not being found. The table is not deleted or modified in any way in migration 9.
Relevant log output
migrations/0036_source_table_embeddings.sql:1:1: relation "global_metric" does not exist
Database schema
SQL queries
Configuration
Playground URL
No response
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: