fly-apps / safe-ecto-migrations

Guide to Safe Ecto Migrations
Other
301 stars 12 forks source link

Backfill data page - question on "next_page = results |> Enum.reverse() |> List.first()" #13

Open lovebes opened 10 months ago

lovebes commented 10 months ago

Hi, in https://fly.io/phoenix-files/backfilling-data/#batching-deterministic-data - The code in getting the next_page id, this seems to imply that Repo.update_all would return the results in an ordered list, and in reversed order.

Would that be true? I wonder if you'd need to do some sorting on the result to get the tail of the result?

dbernheisel commented 10 months ago

That's a good catch! I suspect adding an order during update could make it deterministic, otherwise sorting application-side is fine too.

lovebes commented 10 months ago

Ah thanks for confirming! Would it be possible to edit the example in the article? The migration series of articles is imho a very important document that I refer to time and time again at work. Really appreciate the work put into the article!!

dbernheisel commented 10 months ago

Will do!

dbernheisel commented 10 months ago

I haven't forgotten about this. FWIW, I think adding a CTE to ensure order is the right solution (or sorting Elixir-side), just need to write the example and test it.

lovebes commented 9 months ago

@dbernheisel no worries thank you! Really appreciate ThinkingElixir podcast and thanks for all the time and effort to bring quality news about Elixir to the listeners! 👍