Skip to content

Commit c004851

Browse files
authored
fix(docs): Add ordering warning for numeric goose migration (#3481)
When using Goose with numeric migrations, if the migration files aren't in lexographic order SQLC parses them in the wrong order. This is similar to the issue that occurs with golang-migrate. This pr documents this behaviour.
1 parent 849ef0e commit c004851

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/howto/ddl.md

+25
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,31 @@ type Post struct {
145145

146146
### goose
147147

148+
**Warning:**
149+
sqlc parses migration files in lexicographic order. **If you are using numeric filenames for migrations in Goose and you choose to have sqlc enumerate your migration files**,
150+
make sure their numeric ordering matches their lexicographic ordering to avoid
151+
unexpected behavior. This can be done by prepending enough zeroes to the
152+
migration filenames.
153+
154+
This doesn't work as intended.
155+
156+
```
157+
1_initial.sql
158+
...
159+
9_foo.sql
160+
# this migration file will be parsed BEFORE 9_foo
161+
10_bar.sql
162+
```
163+
164+
This worked as intended.
165+
166+
```
167+
001_initial.sql
168+
...
169+
009_foo.sql
170+
010_bar.sql
171+
```
172+
148173
```sql
149174
-- +goose Up
150175
CREATE TABLE post (

0 commit comments

Comments
 (0)