From b42ded93f6ee1951c1c755513b0f3109b87570ae Mon Sep 17 00:00:00 2001 From: "s0wlz (Matthias Puchstein)" Date: Wed, 29 Apr 2026 23:05:05 +0200 Subject: [PATCH] feat: add DEMO env var to seed demo data on startup --- backend/src/db.rs | 11 +++++++++++ backend/src/main.rs | 1 + deploy/templates/deployment.yaml | 4 ++++ deploy/values.yaml | 3 +++ 4 files changed, 19 insertions(+) diff --git a/backend/src/db.rs b/backend/src/db.rs index 9cabaec..1f85bdb 100644 --- a/backend/src/db.rs +++ b/backend/src/db.rs @@ -13,6 +13,17 @@ pub async fn init() -> Result { Ok(pool) } +pub async fn maybe_seed_demo(pool: &SqlitePool) { + if std::env::var("DEMO").as_deref() != Ok("true") { + return; + } + let seed = include_str!("../demo/demo_seed.sql"); + match sqlx::raw_sql(seed).execute(pool).await { + Ok(_) => tracing::info!("DEMO seed applied"), + Err(e) => tracing::warn!("DEMO seed failed: {e}"), + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/backend/src/main.rs b/backend/src/main.rs index 40fc6e3..356a0ea 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -29,6 +29,7 @@ async fn main() { } let pool = db::init().await.expect("db init failed"); + db::maybe_seed_demo(&pool).await; let static_dir = std::env::var("STATIC_DIR") .unwrap_or_else(|_| "../frontend/build".into()); diff --git a/deploy/templates/deployment.yaml b/deploy/templates/deployment.yaml index 1b1ac42..5fc412f 100644 --- a/deploy/templates/deployment.yaml +++ b/deploy/templates/deployment.yaml @@ -33,6 +33,10 @@ spec: value: {{ .Values.env.DATABASE_URL | quote }} - name: STATIC_DIR value: {{ .Values.env.STATIC_DIR | quote }} + {{- range $k, $v := .Values.env.extra }} + - name: {{ $k }} + value: {{ $v | quote }} + {{- end }} - name: JWT_SECRET valueFrom: secretKeyRef: diff --git a/deploy/values.yaml b/deploy/values.yaml index d79ec92..b1e913e 100644 --- a/deploy/values.yaml +++ b/deploy/values.yaml @@ -48,6 +48,9 @@ jwtSecretName: tutortool-jwt env: DATABASE_URL: sqlite:/data/attendance.db STATIC_DIR: /app/frontend/build + extra: {} + # extra: + # DEMO: "true" # seeds demo data on startup (idempotent, INSERT OR IGNORE) vpa: enabled: false