From 7567281449d7be8a7eb4336ef8497a3cb21fe6a4 Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 22 Jan 2022 20:16:19 -0500 Subject: [PATCH] only automigrate in prod env --- config/config.exs | 2 ++ config/prod.exs | 2 ++ lib/cannery/application.ex | 12 ++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config/config.exs b/config/config.exs index e6aba00..bb9c89d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -21,6 +21,8 @@ config :cannery, CanneryWeb.Endpoint, live_view: [signing_salt: "zOLgd3lr"], registration: System.get_env("REGISTRATION") || "invite" +config :cannery, Cannery.Application, automigrate: false + config :cannery, :generators, migration: true, binary_id: true, diff --git a/config/prod.exs b/config/prod.exs index 9edbf21..f1a59b3 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -15,6 +15,8 @@ config :cannery, Cannery.Repo, url: "ecto://postgres:postgres@localhost/cannery", pool_size: 10 +config :cannery, Cannery.Application, automigrate: true + # Do not print debug messages in production config :logger, level: :info diff --git a/lib/cannery/application.ex b/lib/cannery/application.ex index a47f797..9ad1c7d 100644 --- a/lib/cannery/application.ex +++ b/lib/cannery/application.ex @@ -15,13 +15,17 @@ defmodule Cannery.Application do # Start the PubSub system {Phoenix.PubSub, name: Cannery.PubSub}, # Start the Endpoint (http/https) - CanneryWeb.Endpoint, + CanneryWeb.Endpoint # Start a worker by calling: Cannery.Worker.start_link(arg) - # {Cannery.Worker, arg}, - # Automatically migrate on start - Cannery.Repo.Migrator + # {Cannery.Worker, arg} ] + # Automatically migrate on start in prod + children = + if Application.get_env(:cannery, Cannery.Application, automigrate: false)[:automigrate], + do: children ++ [Cannery.Repo.Migrator], + else: children + # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options opts = [strategy: :one_for_one, name: Cannery.Supervisor]