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