Skip to content

Commit

Permalink
fix(docs): Add ordering warning for numeric goose migration (#3481)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rob2244 authored Aug 5, 2024
1 parent 849ef0e commit c004851
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/howto/ddl.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,31 @@ type Post struct {

### goose

**Warning:**
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**,
make sure their numeric ordering matches their lexicographic ordering to avoid
unexpected behavior. This can be done by prepending enough zeroes to the
migration filenames.

This doesn't work as intended.

```
1_initial.sql
...
9_foo.sql
# this migration file will be parsed BEFORE 9_foo
10_bar.sql
```

This worked as intended.

```
001_initial.sql
...
009_foo.sql
010_bar.sql
```

```sql
-- +goose Up
CREATE TABLE post (
Expand Down

0 comments on commit c004851

Please sign in to comment.