Add migration services

This commit is contained in:
Urtzi Alfaro
2025-09-30 08:12:45 +02:00
parent d1c83dce74
commit ec6bcb4c7d
139 changed files with 6363 additions and 163 deletions

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: alert-processor-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/alert-processor-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: alert-processor-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: alert-processor-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: auth-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/auth-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: auth-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: auth-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: external-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/external-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: external-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: external-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: forecasting-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/forecasting-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: forecasting-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: forecasting-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: inventory-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/inventory-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: inventory-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: inventory-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: notification-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/notification-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: notification-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: notification-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: orders-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/orders-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: orders-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: orders-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: pos-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/pos-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: pos-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: pos-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: production-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/production-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: production-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: production-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: recipes-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/recipes-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: recipes-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: recipes-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: sales-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/sales-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: sales-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: sales-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: suppliers-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/suppliers-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: suppliers-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: suppliers-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: tenant-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/tenant-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: tenant-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: tenant-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -1,3 +1,19 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: training-db-pv
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/opt/bakery-data/training-db"
---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,6 +67,8 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
memory: "256Mi"
@@ -86,6 +104,9 @@ spec:
- name: postgres-data
persistentVolumeClaim:
claimName: training-db-pvc
- name: init-scripts
configMap:
name: postgres-init-config
---
apiVersion: v1
@@ -117,8 +138,9 @@ metadata:
app.kubernetes.io/name: training-db
app.kubernetes.io/component: database
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 5Gi

View File

@@ -13,6 +13,9 @@ data:
ENVIRONMENT: "production"
DEBUG: "false"
LOG_LEVEL: "INFO"
# Database initialization settings
DB_FORCE_RECREATE: "false"
BUILD_DATE: "2024-01-20T10:00:00Z"
VCS_REF: "latest"
IMAGE_TAG: "latest"

View File

@@ -0,0 +1,22 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: development-config
namespace: bakery-ia
labels:
app.kubernetes.io/component: config
app.kubernetes.io/part-of: bakery-ia
environment: development
data:
# Set to "true" to force recreate all tables from scratch (development mode)
# This will drop all existing tables and recreate them from SQLAlchemy models
DB_FORCE_RECREATE: "false"
# Development mode flag
DEVELOPMENT_MODE: "true"
# Enable debug logging in development
DEBUG_LOGGING: "true"
# Skip migration version checking in development
SKIP_MIGRATION_VERSION_CHECK: "false"

View File

@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-init-config
namespace: bakery-ia
labels:
app.kubernetes.io/component: database
app.kubernetes.io/part-of: bakery-ia
data:
init.sql: |
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pg_stat_statements";

View File

@@ -11,6 +11,26 @@ resources:
- secrets.yaml
- ingress-https.yaml
# Additional configs
- configs/postgres-init-config.yaml
- configs/development-config.yaml
# Migration jobs
- migrations/auth-migration-job.yaml
- migrations/tenant-migration-job.yaml
- migrations/training-migration-job.yaml
- migrations/forecasting-migration-job.yaml
- migrations/sales-migration-job.yaml
- migrations/external-migration-job.yaml
- migrations/notification-migration-job.yaml
- migrations/inventory-migration-job.yaml
- migrations/recipes-migration-job.yaml
- migrations/suppliers-migration-job.yaml
- migrations/pos-migration-job.yaml
- migrations/orders-migration-job.yaml
- migrations/production-migration-job.yaml
- migrations/alert-processor-migration-job.yaml
# Infrastructure components
- components/databases/redis.yaml
- components/databases/rabbitmq.yaml

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for alert-processor service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: alert-processor-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: alert-processor-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: alert-processor-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h alert-processor-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/alert-processor:dev
command: ["python", "/app/scripts/run_migrations.py", "alert_processor"]
env:
- name: ALERT_PROCESSOR_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: ALERT_PROCESSOR_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for auth service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: auth-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: auth-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: auth-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h auth-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/auth-service:dev
command: ["python", "/app/scripts/run_migrations.py", "auth"]
env:
- name: AUTH_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: AUTH_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for external service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: external-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: external-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: external-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h external-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/external-service:dev
command: ["python", "/app/scripts/run_migrations.py", "external"]
env:
- name: EXTERNAL_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: EXTERNAL_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for forecasting service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: forecasting-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: forecasting-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: forecasting-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h forecasting-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/forecasting-service:dev
command: ["python", "/app/scripts/run_migrations.py", "forecasting"]
env:
- name: FORECASTING_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: FORECASTING_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for inventory service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: inventory-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: inventory-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: inventory-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h inventory-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/inventory-service:dev
command: ["python", "/app/scripts/run_migrations.py", "inventory"]
env:
- name: INVENTORY_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: INVENTORY_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for notification service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: notification-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: notification-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: notification-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h notification-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/notification-service:dev
command: ["python", "/app/scripts/run_migrations.py", "notification"]
env:
- name: NOTIFICATION_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: NOTIFICATION_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for orders service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: orders-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: orders-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: orders-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h orders-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/orders-service:dev
command: ["python", "/app/scripts/run_migrations.py", "orders"]
env:
- name: ORDERS_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: ORDERS_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for pos service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: pos-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: pos-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: pos-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h pos-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/pos-service:dev
command: ["python", "/app/scripts/run_migrations.py", "pos"]
env:
- name: POS_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: POS_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for production service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: production-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: production-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: production-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h production-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/production-service:dev
command: ["python", "/app/scripts/run_migrations.py", "production"]
env:
- name: PRODUCTION_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: PRODUCTION_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for recipes service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: recipes-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: recipes-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: recipes-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h recipes-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/recipes-service:dev
command: ["python", "/app/scripts/run_migrations.py", "recipes"]
env:
- name: RECIPES_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: RECIPES_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for sales service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: sales-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: sales-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: sales-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h sales-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/sales-service:dev
command: ["python", "/app/scripts/run_migrations.py", "sales"]
env:
- name: SALES_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: SALES_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for suppliers service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: suppliers-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: suppliers-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: suppliers-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h suppliers-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/suppliers-service:dev
command: ["python", "/app/scripts/run_migrations.py", "suppliers"]
env:
- name: SUPPLIERS_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: SUPPLIERS_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for tenant service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: tenant-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: tenant-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: tenant-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h tenant-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/tenant-service:dev
command: ["python", "/app/scripts/run_migrations.py", "tenant"]
env:
- name: TENANT_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: TENANT_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,55 @@
# Enhanced migration job for training service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: training-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: training-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: training-migration
app.kubernetes.io/component: migration
spec:
initContainers:
- name: wait-for-db
image: postgres:15-alpine
command: ["sh", "-c", "until pg_isready -h training-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/training-service:dev
command: ["python", "/app/scripts/run_migrations.py", "training"]
env:
- name: TRAINING_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: TRAINING_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for alert-processor database
set -e
SERVICE_NAME="alert-processor"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=alert-processor-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find alert-processor database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for alert-processor database
set -e
SERVICE_NAME="alert-processor"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=alert-processor-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find alert-processor database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for alert-processor database
set -e
SERVICE_NAME="alert-processor"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=alert-processor-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find alert-processor database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for alert-processor service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your alert-processor service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for auth database
set -e
SERVICE_NAME="auth"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.AUTH_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.AUTH_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=auth-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find auth database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for auth database
set -e
SERVICE_NAME="auth"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.AUTH_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.AUTH_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=auth-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find auth database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for auth database
set -e
SERVICE_NAME="auth"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.AUTH_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.AUTH_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=auth-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find auth database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for auth service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your auth service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for external database
set -e
SERVICE_NAME="external"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=external-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find external database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for external database
set -e
SERVICE_NAME="external"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=external-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find external database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for external database
set -e
SERVICE_NAME="external"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=external-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find external database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for external service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your external service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for forecasting database
set -e
SERVICE_NAME="forecasting"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=forecasting-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find forecasting database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for forecasting database
set -e
SERVICE_NAME="forecasting"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=forecasting-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find forecasting database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for forecasting database
set -e
SERVICE_NAME="forecasting"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=forecasting-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find forecasting database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for forecasting service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your forecasting service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for inventory database
set -e
SERVICE_NAME="inventory"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=inventory-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find inventory database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for inventory database
set -e
SERVICE_NAME="inventory"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=inventory-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find inventory database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for inventory database
set -e
SERVICE_NAME="inventory"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=inventory-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find inventory database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for inventory service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your inventory service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for notification database
set -e
SERVICE_NAME="notification"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=notification-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find notification database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for notification database
set -e
SERVICE_NAME="notification"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=notification-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find notification database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for notification database
set -e
SERVICE_NAME="notification"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=notification-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find notification database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for notification service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your notification service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for orders database
set -e
SERVICE_NAME="orders"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ORDERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ORDERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=orders-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find orders database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for orders database
set -e
SERVICE_NAME="orders"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ORDERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ORDERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=orders-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find orders database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for orders database
set -e
SERVICE_NAME="orders"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ORDERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ORDERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=orders-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find orders database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for orders service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your orders service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for pos database
set -e
SERVICE_NAME="pos"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.POS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.POS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=pos-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find pos database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for pos database
set -e
SERVICE_NAME="pos"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.POS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.POS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=pos-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find pos database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for pos database
set -e
SERVICE_NAME="pos"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.POS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.POS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=pos-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find pos database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for pos service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your pos service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for production database
set -e
SERVICE_NAME="production"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=production-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find production database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for production database
set -e
SERVICE_NAME="production"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=production-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find production database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for production database
set -e
SERVICE_NAME="production"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=production-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find production database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for production service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your production service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for recipes database
set -e
SERVICE_NAME="recipes"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.RECIPES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.RECIPES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=recipes-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find recipes database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for recipes database
set -e
SERVICE_NAME="recipes"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.RECIPES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.RECIPES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=recipes-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find recipes database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for recipes database
set -e
SERVICE_NAME="recipes"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.RECIPES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.RECIPES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=recipes-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find recipes database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for recipes service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your recipes service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for sales database
set -e
SERVICE_NAME="sales"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SALES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SALES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=sales-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find sales database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for sales database
set -e
SERVICE_NAME="sales"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SALES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SALES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=sales-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find sales database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for sales database
set -e
SERVICE_NAME="sales"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SALES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SALES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=sales-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find sales database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for sales service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your sales service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for suppliers database
set -e
SERVICE_NAME="suppliers"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=suppliers-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find suppliers database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for suppliers database
set -e
SERVICE_NAME="suppliers"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=suppliers-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find suppliers database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for suppliers database
set -e
SERVICE_NAME="suppliers"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=suppliers-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find suppliers database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for suppliers service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your suppliers service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for tenant database
set -e
SERVICE_NAME="tenant"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TENANT_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TENANT_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=tenant-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find tenant database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for tenant database
set -e
SERVICE_NAME="tenant"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TENANT_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TENANT_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=tenant-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find tenant database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for tenant database
set -e
SERVICE_NAME="tenant"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TENANT_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TENANT_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=tenant-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find tenant database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for tenant service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your tenant service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Backup script for training database
set -e
SERVICE_NAME="training"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TRAINING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TRAINING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=training-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find training database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Restore script for training database
set -e
SERVICE_NAME="training"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TRAINING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TRAINING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=training-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find training database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Seeding script for training database
set -e
SERVICE_NAME="training"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TRAINING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TRAINING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=training-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find training database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for training service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your training service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi