i used a rails console
and a iex -S mix
session
in ruby
json = Model.all.map {|p| {f1: p.f1, ...}}.to_json
File.open('user.json', 'wb+') {|f| f.write(json)}
in elixir
json_file = "/path/to/file/user.json"
binary = json_file |> File.read!
data = binary |> Poison.decode!
alias Web.User
defmodule Bingo do
def insert_multiple(repo, model, map, [string_key_map | tail]) do
data = for {key, val} <- string_key_map, into: %{}, do: {String.to_atom(key), val}
model.changeset(map, data) |> repo.insert
IO.puts "Inserted #{data}"
insert_multiple(repo, model, map, tail)
end
def insert_multiple(_,_,_, []) do
IO.puts "This is the end. Thank you"
end
end
Bingo.insert_multiple(Web.Repo, User, %User{}, data)