require "json" require "./src/project.cr" require "./altsrc/common.cr" require "./altsrc/main.cr" # 1. get the old list of projects old_storage = Project.all "../storage/" # PROJECT: JSON.mapping({ # PROJECT: id: String, # PROJECT: name: String, # PROJECT: columns: Array(Column), # PROJECT: tasks: Array(Task), # PROJECT: }) # TASKS: JSON.mapping({ # TASKS: id: String, # TASKS: author: Int32, # TASKS: title: String, # TASKS: description: String, # TASKS: column: String, # TASKS: assigned_to: Int32?, # TASKS: color: { # TASKS: type: String, # TASKS: default: "dark" # TASKS: } # TASKS: }) # 2. create the new storage new_storage = TodoD::Storage.new "../new-storage/" # 3. for each project (old name for "list") # 3.1. get list properties # 3.2. get tasks, create new tasks and store them # 3.3. create and store the new list class User property uid : Int32 = 1002 end old_storage.each do |old_project| puts "" puts "" puts "" puts "projet #{old_project.name}" # 3.1. get list properties extra_properties = Hash(String, JSON::Any).new extra_properties["columns"] = JSON.parse(old_project.columns.to_json) # 3.2. get tasks, create new tasks and store them tasks = Array(TodoD::Task).new old_project.tasks.each do |t| # pp! t # 1. get informations about the task # 2. create a task in the new format task_extra_properties = Hash(String, JSON::Any).new task_extra_properties["column"] = JSON.parse(t.column.to_json) task_extra_properties["backgroundColor"] = JSON.parse(t.color.to_json) task_extra_properties["assigneeId"] = JSON.parse(t.assigned_to.to_json) newtask = ::TodoD::Task.new old_project.id, t.title, t.author, description: (t.description || ""), assigned_to: t.assigned_to, extra_properties: task_extra_properties # pp! newtask # 3. store the new task tasks << newtask new_storage.tasks[newtask.id] = newtask end # finally, create the list with all the parameters u = User.new list = TodoD::List.new old_project.name, u, extra_properties list.tasks = tasks.map &.id # puts "" pp! list # finally, store the new list new_storage.lists[list.id] = list end