fschuindt

fschuindt

Hi there, everyone.

Right now I have a few Elixir apps running on a Kubernetes environment and connecting to an external Postgres server, which requires SSL to connect. That’s fine, already had a bunch of those apps connecting with this database before with no issue.

But my latest app is kinda different from the others, it’s using Elixir 1.9.1 releases instead of the old way of doing it having Distillery as a dependency and etc.

Also this app is an umbrella.

That being said, here’s my mix.exs:

[...]
  def project do
    [
      apps_path: "apps",
      version: "0.1.0",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      releases: releases()
    ]
  end

  defp releases do
    [
      runr: [
        applications: [
          database: :permanent,
          engine: :permanent,
          gateway: :permanent,
          shopify: :permanent
        ]
      ]
    ]
  end

[...]

Here’s my config/config.exs file:

import Config

config :database, ecto_repos: [Runr.DataBase.Repo]

config :database, Runr.DataBase.Repo,
  database: System.get_env("POSTGRES_DB"),
  username: System.get_env("POSTGRES_USER"),
  password: System.get_env("POSTGRES_PASSWORD"),
  hostname: System.get_env("POSTGRES_HOST"),
  port: System.get_env("POSTGRES_PORT"),
  pool_size: 5

[...]

This config is used during development/debug. I have a config/releases.exs file just for the released environment:

import Config

config :database, Runr.DataBase.Repo,
  database: System.get_env("POSTGRES_DB"),
  username: System.get_env("POSTGRES_USER"),
  password: System.get_env("POSTGRES_PASSWORD"),
  hostname: System.get_env("POSTGRES_HOST"),
  port: System.get_env("POSTGRES_PORT"),
  pool_size: 10,
  ssl: true,
  prepare: :unnamed

[...]

Notice that for the releases.exs file I’m setting the ssl: true. Because the released app will be connecting using SSL, different from the other environments.

I also have a release tasks file for the database app:

defmodule Runr.DataBase.ReleaseTasks do
  @moduledoc """
  It's used to run common database tasks as Elixir releases commands.

  Check: https://github.com/elixir-ecto/ecto_sql/pull/113
  """

  @app :database

  def migrate do
    Application.ensure_all_started(@app)

    for repo <- repos() do
      {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
    end
  end

  def rollback(repo, version) do
    Application.ensure_all_started(@app)

    {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
  end

  def seed do
    Application.ensure_all_started(@app)

    for repo <- repos() do
      {:ok, _, _} = Ecto.Migrator.with_repo(repo, &do_seed(&1))
    end
  end

  defp do_seed(repo) do
    seed_script = priv_path_for(repo, "seeds.exs")

    if File.exists?(seed_script) do
      Code.eval_file(seed_script)
    end
  end

  defp priv_path_for(repo, filename) do
    app = Keyword.get(repo.config, :otp_app)

    repo_underscore =
      repo
      |> Module.split()
      |> List.last()
      |> Macro.underscore()

    priv_dir = "#{:code.priv_dir(app)}"

    Path.join([priv_dir, repo_underscore, filename])
  end

  defp repos do
    Application.load(@app)
    Application.fetch_env!(@app, :ecto_repos)
  end
end

This module is used so I can migrate and seed the database as a command within the released app.

Where I run for instance:

$ /app/_build/prod/rel/runr/bin/runr eval "Runr.DataBase.ReleaseTasks.migrate()"

The problem is that when I run this command, that happens:

21:25:54.327 [error] Postgrex.Protocol (#PID<0.213.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.214.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.215.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.217.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.216.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.219.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.220.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.221.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.218.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:54.327 [error] Postgrex.Protocol (#PID<0.222.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:55.971 [error] Postgrex.Protocol (#PID<0.215.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:56.105 [error] Postgrex.Protocol (#PID<0.218.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:56.480 [error] Postgrex.Protocol (#PID<0.217.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:56.725 [error] Postgrex.Protocol (#PID<0.213.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:56.791 [error] Postgrex.Protocol (#PID<0.219.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
21:25:57.012 [error] Postgrex.Protocol (#PID<0.216.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Unexpected error: ssl_not_started - :ssl_not_started
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2970ms. You can configure how long requests wait in the queue using :queue_target and :queue_interval. See DBConnection.start_link/2 for more information
    (ecto_sql) lib/ecto/adapters/sql.ex:618: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
    (ecto_sql) lib/ecto/adapters/sql.ex:705: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql) lib/ecto/migrator.ex:567: Ecto.Migrator.verbose_schema_migration/3
    (ecto_sql) lib/ecto/migrator.ex:411: Ecto.Migrator.lock_for_migrations/4
    (ecto_sql) lib/ecto/migrator.ex:335: Ecto.Migrator.run/4
    (ecto_sql) lib/ecto/migrator.ex:89: Ecto.Migrator.with_repo/3
    (database) lib/runr/database/releases_tasks.ex:14: anonymous fn/2 in Runr.DataBase.ReleaseTasks.migrate/0
21:25:57.045 [error] Could not create schema migrations table. This error usually happens due to the following:

  * The database does not exist
  * The "schema_migrations" table, which Ecto uses for managing
    migrations, was defined by another library
  * There is a deadlock while migrating (such as using concurrent
    indexes with a migration_lock)

To fix the first issue, run "mix ecto.create".

To address the second, you can run "mix ecto.drop" followed by
"mix ecto.create". Alternatively you may configure Ecto to use
another table for managing migrations:

    config :database, Runr.DataBase.Repo,
      migration_source: "some_other_table_for_schema_migrations"

The full error report is shown below.

I was thinking it was somehow related with me lacking some extra_applications, I don’t really know, do I’ve tried the following on the file apps/database/mix.exs:

[...]

  def application do
    [
      extra_applications: [:logger, :ecto_sql],
      mod: {Runr.DataBase.Application, []}
    ]
  end

[..]

And here’s the apps/database/lib/runr/database/application.ex:

defmodule Runr.DataBase.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  def start(_type, _args) do
    # List all child processes to be supervised
    children = [
      # Starts a worker by calling: Runr.DataBase.Worker.start_link(arg)
      # {Runr.DataBase.Worker, arg},
      Runr.DataBase.Repo
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Runr.DataBase.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

But that didn’t work. I’m kinda lost here so any insight is welcome.

That’s it, thank you folks!

Showing Posts 1 to 2

NobbZ

NobbZ

Have you tried adding :ssl to the extra applications?

fschuindt

fschuindt OP

You rock! Thank you so much. Strange that I don’t remember of adding this on the other applications that don’t use the new release method.

Anyway, fixed with:
apps/database/mix.exs

[...]

  def application do
    [
      extra_applications: [:logger, :ecto_sql, :ssl],
      mod: {Runr.DataBase.Application, []}
    ]
  end

[...]
— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews