apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: h2
  name: h2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: h2
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: h2
    spec:
      initContainers:
      - name: init-db
        image: quay.io/enmasse/h2-server:1.4.200-1
        command:
          - sh
          - -ec
          - |
             java -cp h2.jar org.h2.tools.Shell -url jdbc:h2:/data/device-registry -sql "create user if not exists admin password '';"
             java -cp h2.jar org.h2.tools.Shell -url jdbc:h2:/data/device-registry -sql "alter user admin set password 'admin1234';"
             java -cp h2.jar org.h2.tools.Shell -url jdbc:h2:/data/device-registry -sql "alter user admin admin true;"
             java -cp h2.jar org.h2.tools.Shell -url jdbc:h2:/data/device-registry -sql "create user if not exists registry password '';"
             java -cp h2.jar org.h2.tools.Shell -url jdbc:h2:/data/device-registry -sql "alter user registry set password 'user12';"
             java -cp h2.jar org.h2.tools.Shell -url jdbc:h2:/data/device-registry -sql "grant all on schema public to registry;"
        volumeMounts:
        - mountPath: /data
          name: data
      containers:
      - name: h2
        image: quay.io/enmasse/h2-server:1.4.200-1
        env:
        - name: H2_TCP_PASSWORD
          value: tcp4321
        resources:
          requests:
            memory: "256Mi"
          limits:
            memory: "256Mi"
        ports:
        - containerPort: 9092
          name: h2
          protocol: TCP
        readinessProbe:
          tcpSocket:
            port: 9092
          initialDelaySeconds: 5
          periodSeconds: 10
        livenessProbe:
          tcpSocket:
            port: 9092
          initialDelaySeconds: 15
          periodSeconds: 20
        volumeMounts:
        - mountPath: /data
          name: data
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: h2
