-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Squashing migrations without a specified "from" version errors out with a cryptic message. For illustrative purposes, this is what my migrations directory looks like before the squash:
❯ ls
1572807617574_create_table_public_users/ 1573059995258_add_relationship__table_public_users/
1572808699643_create_table_public_todos/ 1573060030824_drop_relationship_todos_public_table_users/
1573059126051_update_permission_user_public_table_users/ 1573060041829_add_relationship__table_public_users/
1573059163275_update_permission_user_public_table_users/ 1573879239441_update_permission_user_public_table_todos/
1573059489599_add_relationship__table_public_todos/ 1573881953476_update_permission_user_public_table_users/
1573059527289_update_permission_user_public_table_todos/ 1574304290151_update_permission_user_public_table_users/
1573059543036_update_permission_user_public_table_todos/ 1574304455739_update_permission_user_public_table_users/
1573059603294_update_permission_user_public_table_todos/ 1574304621930_update_permission_user_public_table_users/
1573059620224_update_permission_user_public_table_todos/ 1574304688090_update_permission_user_public_table_users/
1573059663511_update_permission_user_public_table_todos/ 1574304816367_update_permission_user_public_table_users/
1573059674592_update_permission_user_public_table_todos/ 1574304826608_update_permission_user_public_table_users/
1573059926424_update_permission_user_public_table_users/
I wanted to squash them all, so I omitted the "--from" option:
❯ hasura migrate squash --log-level DEBUG --admin-secret myadminsecretkey --endpoint http://localhost:8080
WARN This command is currently experimental and hence in preview, correctness of squashed migration is not guaranteed!
FATA[0000] unable to squash migrations: 0 down migration not found
The error message is confusing. I thought the 0 was a count value and spent some time trying to figure out what the message is saying, because it would appear to be a double negative. But I went through the source to discover that 0 is supposed actually the migration version number. I didn't think it was the migration number at first because I don't have any migrations with the version 0.
If I specify the starting version as the first migration version, everything works fine:
❯ hasura migrate squash --from 1572807617574 --admin-secret myadminsecretkey --endpoint http://localhost:8080
WARN This command is currently experimental and hence in preview, correctness of squashed migration is not guaranteed!
INFO Created '1576429237138_squashed' after squashing '1572807617574' till '1574304826608'
INFO The following migrations are squashed into a new one:
1572807617574
1572808699643
1573059126051
1573059163275
1573059489599
1573059527289
1573059543036
1573059603294
1573059620224
1573059663511
1573059674592
1573059926424
1573059995258
1573060030824
1573060041829
1573879239441
1573881953476
1574304290151
1574304455739
1574304621930
1574304688090
1574304816367
1574304826608
INFO Do you want to delete these migration source files? (y/N)
y
If finding the default starting version is too hard, then the --from option should be mandatory. Otherwise, I think there's a bug with the initial version calculation.