From 25be2e521085e084a39201d26470032c8baaa228 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Mon, 9 Mar 2026 15:12:10 -0600 Subject: [PATCH] db startup --- .gitea/workflows/pipeline.yml | 5 +++++ kubernetes/db.yml | 8 ++++++++ schema.sql | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/pipeline.yml b/.gitea/workflows/pipeline.yml index 3e70569..0fad642 100644 --- a/.gitea/workflows/pipeline.yml +++ b/.gitea/workflows/pipeline.yml @@ -42,6 +42,11 @@ jobs: --from-literal=SECRET_KEY_BASE=$(openssl rand -hex 64) \ --from-literal=AI_TOKEN="$AI_TOKEN" + kubectl create configmap db-schema \ + --from-file=schema.sql=schema.sql \ + --namespace ai-ha-elixir \ + --dry-run=client -o yaml | kubectl apply -f - + for file in kubernetes/*.yml; do cat "$file" | envsubst | kubectl apply -f - done diff --git a/kubernetes/db.yml b/kubernetes/db.yml index 1485f64..aa04f53 100644 --- a/kubernetes/db.yml +++ b/kubernetes/db.yml @@ -25,6 +25,10 @@ spec: value: "elixir_ai" - name: POSTGRES_DB value: "elixir_ai" + volumeMounts: + - name: schema + mountPath: /docker-entrypoint-initdb.d + readOnly: true readinessProbe: exec: command: ["pg_isready", "-U", "elixir_ai"] @@ -37,6 +41,10 @@ spec: limits: memory: "512Mi" cpu: "500m" + volumes: + - name: schema + configMap: + name: db-schema --- apiVersion: v1 diff --git a/schema.sql b/schema.sql index 3e36581..d5415f6 100644 --- a/schema.sql +++ b/schema.sql @@ -1,11 +1,11 @@ -CREATE TABLE conversations ( +CREATE TABLE IF NOT EXISTS conversations ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), name TEXT NOT NULL UNIQUE, inserted_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); -CREATE TABLE messages ( +CREATE TABLE IF NOT EXISTS messages ( id BIGSERIAL PRIMARY KEY, conversation_id UUID NOT NULL REFERENCES conversations(id) ON DELETE CASCADE, role TEXT NOT NULL CHECK (role IN ('user', 'assistant', 'tool')),