bun
bun copied to clipboard
[QUESTION] set_version for migrations?
- 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 layout20060102150405
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
- Second question: Is there any workaround to run migration either up or down exactly for one version?
Thanks in advance
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
Thank you for response!
- 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)
-
I'll try to play with
mark_applied
, thanks! -
Rollback doing revert for single group, is this correct? E.g. having migrations on screenshot below
rollback
affects two last rows.So, if I do everything right for my purposes and every
group_id
is equal toid
, then will myrollback
calls use one migration file per call?
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.