add migration
All checks were successful
Build and Publish / build-release (push) Successful in 1m20s

This commit is contained in:
2026-04-15 17:01:06 -05:00
parent 8b54f20828
commit 9a0dc4942d
7 changed files with 62 additions and 1 deletions

View File

@@ -35,7 +35,7 @@
name = "customer_service";
contents = [ package pkgs.bashInteractive pkgs.busybox pkgs.shadow ];
config = {
Cmd = [ "${package}/bin/customer_service" "start" ];
Cmd = [ "${package}/bin/customer_service" ];
};
};
in

View File

@@ -0,0 +1,30 @@
defmodule CustomerService.Release do
@moduledoc """
Used for executing DB release tasks when run in production without Mix
installed.
"""
@app :customer_service
def migrate do
load_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
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end
defp load_app do
# Many platforms require SSL when connecting to the database
Application.ensure_all_started(:ssl)
Application.ensure_loaded(@app)
end
end

View File

@@ -3,11 +3,29 @@ controllers:
enabled: true
type: deployment
replicas: 1
initContainers:
migrate:
image:
repository: gitea.corredorconect.com/software-engineering/customer-service
tag: '{{ $.Chart.AppVersion }}'
args:
- "eval"
- "CustomService.Release.migrate"
env:
MIX_ENV: prod
DATABASE_URL:
valueFrom:
secretKeyRef:
name: policy-service-pg-app
key: uri
containers:
main:
image:
repository: gitea.corredorconect.com/software-engineering/customer-service
tag: '{{ $.Chart.AppVersion }}'
args:
- "start"
env:
LOG_LEVEL: info
MIX_ENV: prod

5
rel/overlays/bin/migrate Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
set -eu
cd -P -- "$(dirname -- "$0")"
exec ./customer_service eval CustomerService.Release.migrate

1
rel/overlays/bin/migrate.bat Executable file
View File

@@ -0,0 +1 @@
call "%~dp0\customer_service" eval CustomerService.Release.migrate

5
rel/overlays/bin/server Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
set -eu
cd -P -- "$(dirname -- "$0")"
PHX_SERVER=true exec ./customer_service start

2
rel/overlays/bin/server.bat Executable file
View File

@@ -0,0 +1,2 @@
set PHX_SERVER=true
call "%~dp0\customer_service" start