migrate db

This commit is contained in:
Jun-te Kim 2025-12-13 18:58:28 +00:00
parent 9f29fe8f55
commit ef32447d9f
4 changed files with 46 additions and 19 deletions

View file

@ -0,0 +1,35 @@
name: Atlas Migrate (dev)
on:
push:
branches:
- main
jobs:
migrate:
runs-on: mealcraft-runners
steps:
- name: Checkout repo
uses: actions/checkout@v4
# Install Atlas
- name: Install Atlas CLI
run: |
curl -sSf https://atlasgo.sh | sh
# Load DB creds from Kubernetes secret
- name: Load Postgres credentials
run: |
export POSTGRES_USER=$(kubectl get secret postgres-secret -o jsonpath='{.data.POSTGRES_USER}' | base64 -d)
export POSTGRES_PASSWORD=$(kubectl get secret postgres-secret -o jsonpath='{.data.POSTGRES_PASSWORD}' | base64 -d)
echo "POSTGRES_USER=$POSTGRES_USER" >> $GITHUB_ENV
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> $GITHUB_ENV
# Run Atlas migrations (DEV only)
- name: Run Atlas migrations (dev)
run: |
atlas migrate apply \
--env stripe_invoice_dev \
--dir file://db/atlas/stripe_invoice/migrations

View file

@ -1,6 +1,13 @@
env "k8s" { env "stripe_invoice_dev" {
url = "postgres://$DB_USER:$DB_PASSWORD@postgres:5432/stripe_invoice?sslmode=disable" url = "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/stripe_invoice_dev?sslmode=disable"
migration { migration {
dir = "file://atlas/migrations" dir = "file://atlas/stripe_invoice/migrations"
}
}
env "stripe_invoice_prod" {
url = "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/stripe_invoice_prod?sslmode=disable"
migration {
dir = "file://atlas/stripe_invoice/migrations"
} }
} }

View file

@ -9,7 +9,7 @@ spec:
containers: containers:
- name: atlas - name: atlas
image: arigaio/atlas:latest image: arigaio/atlas:latest
command: ["atlas", "migrate", "apply", "--env", "k8s"] command: ["atlas", "migrate", "apply", "--env", "stripe_invoice"]
envFrom: envFrom:
- secretRef: - secretRef:
name: postgres-secret name: postgres-secret

View file

@ -1,19 +1,4 @@
# -------------------------------------------------- # --------------------------------------------------
# PostgreSQL Secret
# --------------------------------------------------
apiVersion: v1
kind: Secret
metadata:
name: postgres-secret
namespace: default
type: Opaque
stringData:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgrespassword
POSTGRES_DB: stripe_invoice
---
# --------------------------------------------------
# PersistentVolume (local disk on mist) # PersistentVolume (local disk on mist)
# -------------------------------------------------- # --------------------------------------------------
apiVersion: v1 apiVersion: v1