Update schema.sql for my-recipes using db-migration job
This commit is contained in:
parent
3b15565a9d
commit
4ec34a920c
@ -0,0 +1,45 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}-add-missing-tables
|
||||||
|
namespace: {{ .Values.global.namespace }}
|
||||||
|
data:
|
||||||
|
add-tables.sql: |
|
||||||
|
-- Create grocery lists table
|
||||||
|
CREATE TABLE IF NOT EXISTS grocery_lists (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
items TEXT[] NOT NULL DEFAULT '{}',
|
||||||
|
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
is_pinned BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create grocery list shares table
|
||||||
|
CREATE TABLE IF NOT EXISTS grocery_list_shares (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
list_id INTEGER NOT NULL REFERENCES grocery_lists(id) ON DELETE CASCADE,
|
||||||
|
shared_with_user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
can_edit BOOLEAN DEFAULT FALSE,
|
||||||
|
shared_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
UNIQUE(list_id, shared_with_user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_grocery_lists_owner_id ON grocery_lists (owner_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_grocery_list_shares_list_id ON grocery_list_shares (list_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_grocery_list_shares_user_id ON grocery_list_shares (shared_with_user_id);
|
||||||
|
|
||||||
|
-- Create notifications table
|
||||||
|
CREATE TABLE IF NOT EXISTS notifications (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type TEXT NOT NULL,
|
||||||
|
message TEXT NOT NULL,
|
||||||
|
related_id INTEGER,
|
||||||
|
is_read BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_notifications_user_id ON notifications (user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_notifications_is_read ON notifications (is_read);
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
apiVersion: batch/v1
|
||||||
|
kind: Job
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}-add-missing-tables
|
||||||
|
namespace: {{ .Values.global.namespace }}
|
||||||
|
annotations:
|
||||||
|
"helm.sh/hook": post-upgrade
|
||||||
|
"helm.sh/hook-weight": "6"
|
||||||
|
"helm.sh/hook-delete-policy": before-hook-creation
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
restartPolicy: Never
|
||||||
|
containers:
|
||||||
|
- name: add-tables
|
||||||
|
image: postgres:16-alpine
|
||||||
|
env:
|
||||||
|
- name: PGHOST
|
||||||
|
value: {{ .Release.Name }}-db
|
||||||
|
- name: PGPORT
|
||||||
|
value: "{{ .Values.postgres.port }}"
|
||||||
|
- name: PGDATABASE
|
||||||
|
value: {{ .Values.postgres.database }}
|
||||||
|
- name: PGUSER
|
||||||
|
value: {{ .Values.postgres.user }}
|
||||||
|
- name: PGPASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .Release.Name }}-db-credentials
|
||||||
|
key: password
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
echo "Waiting for database to be ready..."
|
||||||
|
until pg_isready -h $PGHOST -p $PGPORT -U $PGUSER; do
|
||||||
|
echo "Database not ready, waiting..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
echo "Database ready, adding missing tables..."
|
||||||
|
psql -v ON_ERROR_STOP=1 -f /sql/add-tables.sql
|
||||||
|
echo "Tables added successfully!"
|
||||||
|
volumeMounts:
|
||||||
|
- name: sql
|
||||||
|
mountPath: /sql
|
||||||
|
volumes:
|
||||||
|
- name: sql
|
||||||
|
configMap:
|
||||||
|
name: {{ .Release.Name }}-add-missing-tables
|
||||||
Loading…
x
Reference in New Issue
Block a user