Open rob2244 opened 3 months ago
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) if you put a break point were the files are being loaded you can see the sort order is incorrect. Not sure if this also happens when using dates for migrations.
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
Looks like this is an issue of documentation, there is a warning for golang-migrate for number based migrations but none for goose:
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
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