bun icon indicating copy to clipboard operation
bun copied to clipboard

[QUESTION] set_version for migrations?

Open LdDl opened this issue 2 years ago • 3 comments

  1. First question: Comparing to go-pg migration tool we've lost ability to use set_version for some edge cases (semi-automatic-hardcoded migrations). I guess it happens due the nature of new way of migrations naming (it is based on timestamp layout 20060102150405 now - ref code). Are there any plans to implement those feature or allow to do custom naming, e.g.:
1_prepare_schema.go
2_fill_tables.go
3_prepare_triggers.go
etc.

instead of

20220101100000_prepare_schema.go
20220101102000_fill_tables.go
20220101102030_prepare_triggers.go
etc.

? Or can you give me some advice how to do it with current migration tool functionality

  1. Second question: Is there any workaround to run migration either up or down exactly for one version?

Thanks in advance

LdDl avatar Aug 03 '22 21:08 LdDl

There are no plans to allow custom naming, because it is an essential part of how Bun migrations work.

You can use mark_applied instead of set_version. You can also try to improve Bun to accept list of versions that must be applied, e.g.:

go run . db migrate 20220101100000 20220101102030
go run . db rollback 20220101100000

vmihailenco avatar Aug 04 '22 06:08 vmihailenco

Thank you for response!

  1. Recently I've found 'hacky' way to dodge timestamp naming by converting from:
20220101100000_prepare_schema.go
20220101102000_fill_tables.go
20220101102030_prepare_triggers.go

to:

00000000000001_prepare_schema.go
00000000000002_fill_tables.go
00000000000003_prepare_triggers.go

It works for my case (I need to change order of migration files calls sometimes and it is easier for me to work with serial identifiers)

  1. I'll try to play with mark_applied, thanks!

  2. Rollback doing revert for single group, is this correct? E.g. having migrations on screenshot below rollback affects two last rows. image So, if I do everything right for my purposes and every group_id is equal to id, then will my rollback calls use one migration file per call?

LdDl avatar Aug 04 '22 08:08 LdDl

So, if I do everything right for my purposes and every group_id is equal to id, then will my rollback calls use one migration file per call?

Yes, I guess so.

You could also try to add option that makes bun/migrate to create groups with only 1 migration in them.

vmihailenco avatar Aug 06 '22 10:08 vmihailenco