#!/usr/bin/env bash # ───────────────────────────────────────────────────────────────────────────── # BudgetWise – Appwrite Deploy Script # # Deploys the schema defined in appwrite.json (databases, collections) using # the Appwrite CLI. Runs functions deploy if functions/ contains any functions. # # Works locally and in CI (Woodpecker, Docker, etc.) — credentials come from # environment variables, never from committed files. # # Required environment variables: # APPWRITE_ENDPOINT e.g. https://appwrite.example.com/v1 # APPWRITE_PROJECT_ID The Appwrite project ID # APPWRITE_API_KEY API key with databases.write + collections.write scopes # # Local usage: # export APPWRITE_ENDPOINT=... APPWRITE_PROJECT_ID=... APPWRITE_API_KEY=... # bash scripts/deploy.sh # # Or with a local .env file at apps/appwrite/.env: # set -a && source .env && set +a && bash scripts/deploy.sh # ───────────────────────────────────────────────────────────────────────────── set -euo pipefail APPWRITE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CLI="npx --yes appwrite@6" # ── Validate required env vars ──────────────────────────────────────────────── : "${APPWRITE_ENDPOINT:?APPWRITE_ENDPOINT is required}" : "${APPWRITE_PROJECT_ID:?APPWRITE_PROJECT_ID is required}" : "${APPWRITE_API_KEY:?APPWRITE_API_KEY is required}" echo "==> Deploying Appwrite schema" echo " Endpoint : $APPWRITE_ENDPOINT" echo " Project : $APPWRITE_PROJECT_ID" # ── Configure CLI session ───────────────────────────────────────────────────── # Writes to ~/.appwrite/prefs.json — ephemeral in CI runners. $CLI client \ --endpoint "$APPWRITE_ENDPOINT" \ --project-id "$APPWRITE_PROJECT_ID" \ --key "$APPWRITE_API_KEY" # ── Deploy databases + collections ──────────────────────────────────────────── cd "$APPWRITE_DIR" echo "==> Deploying databases..." $CLI deploy database --all --yes # ── Deploy functions (skipped if functions/ is empty) ───────────────────────── if [ -d "functions" ] && [ -n "$(ls -A functions 2>/dev/null | grep -v '\.gitkeep')" ]; then echo "==> Deploying functions..." $CLI deploy function --all --yes else echo "==> No functions to deploy, skipping." fi echo "==> Appwrite deploy complete."