From 46eed25a9476d213c3ba0c356ca90c47ac7a82d2 Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 22 Jan 2022 20:12:32 -0500 Subject: [PATCH] only start automigrator in prod env --- config/config.exs | 2 ++ config/prod.exs | 2 ++ lib/lokal/application.ex | 10 +++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/config.exs b/config/config.exs index ad87349..9b1383d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -20,6 +20,8 @@ config :lokal, LokalWeb.Endpoint, pubsub_server: Lokal.PubSub, live_view: [signing_salt: "zOLgd3lr"] +config :lokal, Lokal.Application, automigrate: false + # Configures the mailer # # By default it uses the "Local" adapter which stores the emails diff --git a/config/prod.exs b/config/prod.exs index d5108f0..8b6f640 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -18,6 +18,8 @@ config :lokal, Lokal.Repo, url: "ecto://postgres:postgres@localhost/lokal", pool_size: 10 +config :lokal, Lokal.Application, automigrate: true + # Do not print debug messages in production config :logger, level: :info diff --git a/lib/lokal/application.ex b/lib/lokal/application.ex index a1799b9..c55cf91 100644 --- a/lib/lokal/application.ex +++ b/lib/lokal/application.ex @@ -15,13 +15,17 @@ defmodule Lokal.Application do # Start the PubSub system {Phoenix.PubSub, name: Lokal.PubSub}, # Start the Endpoint (http/https) - LokalWeb.Endpoint, + LokalWeb.Endpoint # Start a worker by calling: Lokal.Worker.start_link(arg) # {Lokal.Worker, arg} - # Automatically migrate on start - Lokal.Repo.Migrator ] + # Automatically migrate on start in prod + children = + if Application.get_env(:lokal, Lokal.Application, automigrate: false)[:automigrate], + do: children ++ [Lokal.Repo.Migrator], + else: children + # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options opts = [strategy: :one_for_one, name: Lokal.Supervisor]