From 7b25ef7e82bd67015837f61c81e5789d7caa5fdb Mon Sep 17 00:00:00 2001 From: dvirlabs Date: Wed, 3 Dec 2025 04:06:13 +0200 Subject: [PATCH] Add configmap for init db --- .../templates/db-schema-configmap.yaml | 29 +++++++++++++++++++ .../templates/db-statefulset.yaml | 6 ++++ 2 files changed, 35 insertions(+) create mode 100644 charts/my-recipes-chart/templates/db-schema-configmap.yaml diff --git a/charts/my-recipes-chart/templates/db-schema-configmap.yaml b/charts/my-recipes-chart/templates/db-schema-configmap.yaml new file mode 100644 index 0000000..d0be270 --- /dev/null +++ b/charts/my-recipes-chart/templates/db-schema-configmap.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-db-schema +data: + schema.sql: | + -- Create recipes table + CREATE TABLE IF NOT EXISTS recipes ( + id SERIAL PRIMARY KEY, + name TEXT NOT NULL, + meal_type TEXT NOT NULL, + time_minutes INTEGER NOT NULL, + + tags JSONB NOT NULL DEFAULT '[]', + ingredients JSONB NOT NULL DEFAULT '[]', + steps JSONB NOT NULL DEFAULT '[]' + ); + + CREATE INDEX IF NOT EXISTS idx_recipes_meal_type + ON recipes (meal_type); + + CREATE INDEX IF NOT EXISTS idx_recipes_time_minutes + ON recipes (time_minutes); + + CREATE INDEX IF NOT EXISTS idx_recipes_tags_jsonb + ON recipes USING GIN (tags); + + CREATE INDEX IF NOT EXISTS idx_recipes_ingredients_jsonb + ON recipes USING GIN (ingredients); diff --git a/charts/my-recipes-chart/templates/db-statefulset.yaml b/charts/my-recipes-chart/templates/db-statefulset.yaml index adabeaa..b53d194 100644 --- a/charts/my-recipes-chart/templates/db-statefulset.yaml +++ b/charts/my-recipes-chart/templates/db-statefulset.yaml @@ -31,6 +31,12 @@ spec: volumeMounts: - name: data mountPath: /var/lib/postgresql/data + - name: init-sql + mountPath: /docker-entrypoint-initdb.d + volumes: + - name: init-sql + configMap: + name: {{ .Release.Name }}-db-schema volumeClaimTemplates: - metadata: name: data