treble37

treble37

With Ecto 3.1, can you still use ensure_started if importing Mix.EctoSQL?

So recently, we upgraded to Ecto 3.1 (and started making the app multi-node). Looking at Mix.EctoSQL in ecto_sql repository, it seems like you can use ensure_started/2. (Note: this code was working previously, but was recently just discovered to have stopped working). I have code that I want to run as a custom distillery command:

defmodule Demo.ReleaseTask do
  @moduledoc """
  A module for seeding data during release...
  """
  import Mix.EctoSQL

  @start_apps [:logger, :ssl, :postgrex, :ecto, :ecto_sql, :ex_machina]

  def bootstrap_and_init do
    IO.puts("Starting dependencies...")
    Enum.each(@start_apps, &Application.ensure_all_started/1)
    IO.puts("Starting data repo(s)...")

    ensure_started(Demo.Repo, [])
   
     Demo.Seed.Document.seed()

    IO.puts("Populated database seed data...")
    :init.stop()
  end
end

Currently, when calling Demo.Seed.Document.seed(), I end up getting something like ** (EXIT from #PID<0.91.0>) shutdown. When I tried extracting a more informed message from the EXIT and printed it out, it said the “repo was not running”. Is there a way to spin up the Repo and keep it running long enough to populate data? I should add the Demo.Seed.Document.seed/0 is using ex_machina to insert the data via a factory.

Most Liked

josevalim

josevalim

Creator of Elixir

Mix.EctoSQL was always private and should not be invoked directly. There is now a public API for this: Add Ecto.Migrator.with_repo/2 to start/stop apps for migrations by josevalim · Pull Request #113 · elixir-ecto/ecto_sql · GitHub

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement