AF
Ash Frameworkβ€’3mo ago
Ev

Rollback went further than expected

Did I do this incorrectly? I ran mix ash.rollback -r Ngen.Repo and answered the prompt but it rolled much further back than I expected.
How many migrations should be rolled back? (default: 0)

Last 20 migration names, with the input you must provide to
rollback up to *and including* that migration:

1: /20250714010938_add_urls.exs
2: /20250714005740_add_sitemaps.exs
3: /20250713221021_initialize_extensions_1.exs
4: /20250707191126_pdp_add_rating.exs
5: /20250707184451_pdp_add_tags.exs
6: /20250621021828_add_source_id_to_embeddings.exs
7: /20250615215955_create_api_key_metadata.exs
8: /20250611064155_add_merchant_url_to_search_mapping.exs
...ommitting for brevity
20: /20250516072230_rename_raw_data.exs

Rollback to: 3 <--- I answered this
How many migrations should be rolled back? (default: 0)

Last 20 migration names, with the input you must provide to
rollback up to *and including* that migration:

1: /20250714010938_add_urls.exs
2: /20250714005740_add_sitemaps.exs
3: /20250713221021_initialize_extensions_1.exs
4: /20250707191126_pdp_add_rating.exs
5: /20250707184451_pdp_add_tags.exs
6: /20250621021828_add_source_id_to_embeddings.exs
7: /20250615215955_create_api_key_metadata.exs
8: /20250611064155_add_merchant_url_to_search_mapping.exs
...ommitting for brevity
20: /20250516072230_rename_raw_data.exs

Rollback to: 3 <--- I answered this
I thought it would roll back to 3: 3: /20250713221021_initialize_extensions_1.exs But it rolled all the way back to (but not including): 7: /20250615215955_create_api_key_metadata.exs Was I supposed to specify the full migration filename? I'm confused what the connection is between my answer of 3 and the migration it rolled back to. Can/should I use mix ecto.rollback directly in the future?
32 Replies
ZachDaniel
ZachDanielβ€’3mo ago
🫨that doesn't sound right at all... That's a big problem of course Did this happen in production? @Ev can you reproduce this?
Ev
EvOPβ€’3mo ago
on my laptop so no major loss; will see if I can reproduce hmm seems to have happened again does it matter that I added Ash to an existing project & repo?
ZachDaniel
ZachDanielβ€’3mo ago
hmm... was your database migrated fully? Yeah, okay.
Ev
EvOPβ€’3mo ago
I think so but not sure. I also have multiple repos (3) and the other 2 are in the "up" state but are "file not found" (when running mix ecto.migrations) because I'm working on a few branches in parallel
ZachDaniel
ZachDanielβ€’3mo ago
actually... πŸ€” yeah I'm not sure
Ev
EvOPβ€’3mo ago
maybe some of that state is confusing mix ash.rollback?
ZachDaniel
ZachDanielβ€’3mo ago
It really shouldn't πŸ€”
Ev
EvOPβ€’3mo ago
is it safe to use mix ecto.migrate / mix ecto.rollback instead or does ash rely on mix ash.migrate/rollback for extra housekeeping?
ZachDaniel
ZachDanielβ€’3mo ago
Yes, its safe to use those directly but I naturally want to figure this stuff out πŸ˜† πŸ€” Is the codebase in question open or sharable?
Ev
EvOPβ€’3mo ago
unfortunately not 😦 I'm reading thru the ash.rollback mix task in case it sparks any ideas
ZachDaniel
ZachDanielβ€’3mo ago
So, do you have it set up in such a way you can reproduce it every time? I just tried it myself and it doesn't happen which is good at least because it means its safe except for some condition I think there is one very simple change we can make that would eliminate some confusion here which is instead of using -n in our call to ecto, we use --to
Ev
EvOPβ€’3mo ago
it happens consistently for me; I can hop on a call and share screen to step thru it if that helps
ZachDaniel
ZachDanielβ€’3mo ago
Can't do a call at the moment, but I'm looking into it. If you have time to investigate, the best thing you could do would be to either edit your dep in /deps or clone down ash_postgres locally and point to it as a path dependency @Ev I've just pushed something up to main of ash_postgres can you try it out? It will cut out a potential cause of this issue specifically, it uses --to instead of -n to rollback to a specific named migration {:ash_postgres, github: "ash-project/ash", override: true}
Ev
EvOPβ€’3mo ago
trying now
Ev
EvOPβ€’3mo ago
Unchecked dependencies for environment dev: * ash_postgres (https://github.com/ash-project/ash.git) could not find an app file at "_build/dev/lib/ash_postgres/ebin/ash_postgres.app". This may happen if the dependency was not yet compiled or the dependency indeed has no app file (then you can pass app: false as option) ** (Mix) Can't continue due to errors on dependencies
GitHub
GitHub - ash-project/ash: A declarative, extensible framework for b...
A declarative, extensible framework for building Elixir applications. - ash-project/ash
Ev
EvOPβ€’3mo ago
assuming the fix is ash_postgres for the repo
ZachDaniel
ZachDanielβ€’3mo ago
yeah, sorry bout that typo πŸ˜„
Ev
EvOPβ€’3mo ago
same behavior but is the change pushed to main? when I look at the ash_postgres commit history, the last one was 4 days ago
ZachDaniel
ZachDanielβ€’3mo ago
🀦 sorry bit distracted πŸ˜† Pushed mix deps.update ash_postgres
Ev
EvOPβ€’3mo ago
all good, retrying that works as expected now, only rolled back 3
ZachDaniel
ZachDanielβ€’3mo ago
weird So the thing that I did would make it I guess resilient potentially to some kind of different order of migrations on your file system and in your db maybe? but that doesn't really make sense, they are ordered by an integer
Ev
EvOPβ€’3mo ago
hmm will see if I can figure out what is happening thank you for the quick fix πŸ™‚ found the bug
Ev
EvOPβ€’3mo ago
in Mix.Tasks.AshPostgres.Rollback the repo is getting passed twice. so the following command is run: mix ecto.rollback -r Elixir.Ngen.Repo -r Ngen.Repo -n 3 which effectively tells it to roll back two repos (that happen to be the same one) 3 steps, with the net effect being 6 steps back. with your change specifying --to this risk is removed
GitHub
ash_postgres/lib/mix/tasks/ash_postgres.rollback.ex at main Β· ash-...
The PostgreSQL data layer for Ash Framework. Contribute to ash-project/ash_postgres development by creating an account on GitHub.
ZachDaniel
ZachDanielβ€’3mo ago
Wtf
Ev
EvOPβ€’3mo ago
so I think rest_opts should have repo filtered out of it
ZachDaniel
ZachDanielβ€’3mo ago
Wow. Weird that I didn't see that in my testing though πŸ€”
Ev
EvOPβ€’3mo ago
because -r is already being explicitly passed
ZachDaniel
ZachDanielβ€’3mo ago
OHHH Wowee Okay. Great find. Would you like to open a PR for that fix? Otherwise an issue?
Ev
EvOPβ€’3mo ago
it looks like it's supposed to already filter it out but I'm fuzzy on what the difference between delete_flag & delete_arg is and how that interacts with the OptionParser aliases above it
Ev
EvOPβ€’3mo ago
GitHub
ash_postgres/lib/mix/tasks/ash_postgres.rollback.ex at main Β· ash-...
The PostgreSQL data layer for Ash Framework. Contribute to ash-project/ash_postgres development by creating an account on GitHub.
ZachDaniel
ZachDanielβ€’3mo ago
Gotta run but if there are issues figuring it out feel free to open an issue and I'll address it tomorrow πŸ™‚ Also, this task used to be a tiny thin wrapper around Ecto.rollback, so we don't have any tests for the task 😱 It was upgraded some time to have more logic but didn't get tests then which is my bad.
Ev
EvOPβ€’3mo ago
I created an issue for it (https://github.com/ash-project/ash_postgres/issues/592) it looks like the repo name is also passed in from the data_layer. I'm guessing that was added to handle the interactive part of specifying how far you want to rollback. maybe the fix should include pushing that logic down into the ash_postgres.rollback mix task itself similar to how the other data_layer tasks pass things along, and unifying repo selection. but I'm a noob to the codebase - don't want to mess things up
GitHub
Rollback with repo specified will rollback double the expected step...
Code of Conduct I agree to follow this project&#39;s Code of Conduct AI Policy I agree to follow this project&#39;s AI Policy, or I agree that AI was not used while creating this issue. Versions 2....
GitHub
ash_postgres/lib/mix/tasks/ash_postgres.rollback.ex at main Β· ash-...
The PostgreSQL data layer for Ash Framework. Contribute to ash-project/ash_postgres development by creating an account on GitHub.

Did you find this page helpful?