From c1d3052f1a356006c1f35a344deb896cb3b33d53 Mon Sep 17 00:00:00 2001 From: Neylix Date: Thu, 23 Mar 2023 16:28:54 +0100 Subject: [PATCH] Handle old migration format --- lib/mix/tasks/migrate.ex | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/mix/tasks/migrate.ex b/lib/mix/tasks/migrate.ex index 11d79b688e..b3da19d25a 100644 --- a/lib/mix/tasks/migrate.ex +++ b/lib/mix/tasks/migrate.ex @@ -34,7 +34,7 @@ defmodule Mix.Tasks.Archethic.Migrate do migrations_to_run = if File.exists?(migration_file_path) do - File.read!(migration_file_path) |> filter_migrations_to_run(function) + read_file(migration_file_path) |> filter_migrations_to_run(function) else # File does not exist when it's the first time the node is started # We create the folder to write the migration file on first start @@ -99,4 +99,17 @@ defmodule Mix.Tasks.Archethic.Migrate do :code.delete(module) :code.purge(module) end + + defp read_file(path) do + # handle old migration file format + file_content = File.read!(path) + + if String.contains?(file_content, ";") do + last_version = file_content |> String.split(";") |> Enum.reject(&(&1 == "")) |> List.last() + File.write(path, last_version) + last_version + else + file_content + end + end end