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.
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
π«¨that doesn't sound right at all...
That's a big problem of course
Did this happen in production?
@Ev can you reproduce this?
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?
hmm...
was your database migrated fully?
Yeah, okay.
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
actually... π€ yeah I'm not sure
maybe some of that state is confusing mix ash.rollback?
It really shouldn't π€
is it safe to use mix ecto.migrate / mix ecto.rollback instead or does ash rely on mix ash.migrate/rollback for extra housekeeping?
Yes, its safe to use those directly
but I naturally want to figure this stuff out π
π€
Is the codebase in question open or sharable?
unfortunately not π¦
I'm reading thru the ash.rollback mix task in case it sparks any ideas
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
it happens consistently for me; I can hop on a call and share screen to step thru it if that helps
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}
trying now
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
assuming the fix is ash_postgres for the repo
yeah, sorry bout that
typo π
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
π€¦ sorry
bit distracted π
Pushed
mix deps.update ash_postgres
all good, retrying
that works as expected now, only rolled back 3
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
hmm will see if I can figure out what is happening
thank you for the quick fix π
found the bug
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 removedGitHub
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.
Wtf
so I think rest_opts should have repo filtered out of it
Wow. Weird that I didn't see that in my testing though π€
because -r is already being explicitly passed
OHHH
Wowee
Okay. Great find.
Would you like to open a PR for that fix?
Otherwise an issue?
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 itGitHub
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.
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.
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's Code of Conduct AI Policy I agree to follow this project'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.