add touchless docker deploys
This commit is contained in:
		| @@ -9,6 +9,7 @@ defmodule Lokal.Application do | ||||
|     children = [ | ||||
|       # Start the Ecto repository | ||||
|       Lokal.Repo, | ||||
|       Lokal.Repo.Migrator, | ||||
|       # Start the Telemetry supervisor | ||||
|       LokalWeb.Telemetry, | ||||
|       # Start the PubSub system | ||||
|   | ||||
							
								
								
									
										20
									
								
								lib/lokal/release.ex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								lib/lokal/release.ex
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| defmodule Lokal.Release do | ||||
|   @app :lokal | ||||
|  | ||||
|   def rollback(repo, version) do | ||||
|     load_app() | ||||
|     {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version)) | ||||
|   end | ||||
|  | ||||
|   defp load_app do | ||||
|     Application.load(@app) | ||||
|   end | ||||
|  | ||||
|   def migrate do | ||||
|     load_app() | ||||
|  | ||||
|     for repo <- Application.fetch_env!(@app, :ecto_repos) do | ||||
|       {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										18
									
								
								lib/lokal/repo/migrator.ex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								lib/lokal/repo/migrator.ex
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| defmodule Lokal.Repo.Migrator do | ||||
|   use GenServer | ||||
|   require Logger | ||||
|  | ||||
|   def start_link(_) do | ||||
|     GenServer.start_link(__MODULE__, [], []) | ||||
|   end | ||||
|  | ||||
|   def init(_) do | ||||
|     migrate!() | ||||
|     {:ok, nil} | ||||
|   end | ||||
|  | ||||
|   def migrate! do | ||||
|     path = Application.app_dir(:lokal, "priv/repo/migrations") | ||||
|     Ecto.Migrator.run(Lokal.Repo, path, :up, all: true) | ||||
|   end | ||||
| end | ||||
		Reference in New Issue
	
	Block a user