From 964b77f4581dd23d644c47c4798292e78b8fd85d Mon Sep 17 00:00:00 2001
From: Alex Wood <awood@redhat.com>
Date: Wed, 14 May 2025 11:36:43 -0400
Subject: [PATCH] Don't run migrations centrally. Run them as init containers

Rather than use the wait-for.sh script to block all the pods on the
completion of a job, just have each pod use the swatch-database image
as its own init container.

As the pods come up, the first init container for a given set of
migrations will grab the changelog lock and run the migrations.  Other
pods relying on the same set of migrations will then have their init
containers start, grab the lock, do nothing (since the migrations have
already been run), and release the lock.

Eventually, all the pods will come up although there will be a bit of
crash-looping when init containers try to run migrations before the
database is available.

This design reduces the complexity of the migration process since there
is no job to worry about, no coordination required to make sure the job
runs after every deployment, and no requirement to package a third-party
utility (wait-for.sh).

However, all ClowdApps must now expose the database connection
information in environment variables since the swatch-database
application doesn't have the ability to read the Clowder provided
cdappconfig.json file.
---
 swatch-api/deploy/clowdapp.yaml               |  47 +++-----
 swatch-billable-usage/deploy/clowdapp.yaml    |  75 +++++++------
 swatch-contracts/deploy/clowdapp.yaml         |  47 +++-----
 swatch-database/deploy/clowdapp.yaml          | 102 ------------------
 swatch-database/libs/k8s-wait-for-2.0.zip     | Bin 11859 -> 0 bytes
 .../src/main/docker/Dockerfile.jvm            |   3 -
 swatch-metrics-hbi/deploy/clowdapp.yaml       |  47 +++-----
 .../deploy/clowdapp.yaml                      |  47 +++-----
 swatch-subscription-sync/deploy/clowdapp.yaml |  47 +++-----
 swatch-tally/deploy/clowdapp.yaml             |  88 +++++++--------
 10 files changed, 175 insertions(+), 328 deletions(-)
 delete mode 100644 swatch-database/libs/k8s-wait-for-2.0.zip

diff --git a/swatch-api/deploy/clowdapp.yaml b/swatch-api/deploy/clowdapp.yaml
index a18fca7b0..cd174b906 100644
--- a/swatch-api/deploy/clowdapp.yaml
+++ b/swatch-api/deploy/clowdapp.yaml
@@ -35,18 +35,18 @@ parameters:
     value: 200m
   - name: CPU_LIMIT
     value: 300m
-  - name: WAIT_IMAGE
+  - name: MIGRATION_IMAGE
     value: quay.io/cloudservices/swatch-database
-  - name: WAIT_TAG
+  - name: MIGRATION_TAG
     value: latest
-  - name: WAIT_MEMORY_REQUEST
-    value: 10Mi
-  - name: WAIT_MEMORY_LIMIT
-    value: 20Mi
-  - name: WAIT_CPU_REQUEST
-    value: 100m
-  - name: WAIT_CPU_LIMIT
+  - name: MIGRATION_MEMORY_REQUEST
+    value: 256Mi
+  - name: MIGRATION_MEMORY_LIMIT
+    value: 512Mi
+  - name: MIGRATION_CPU_REQUEST
     value: 100m
+  - name: MIGRATION_CPU_LIMIT
+    value: 500m
   - name: DATABASE_CONNECTION_TIMEOUT_MS
     value: '30000'
   - name: DATABASE_MAX_POOL_SIZE
@@ -111,30 +111,17 @@ objects:
           podSpec:
             image: ${IMAGE}:${IMAGE_TAG}
             initContainers:
-              - image: ${WAIT_IMAGE}:${WAIT_TAG}
-                command: ["/bin/sh","-c"]
-                args:
-                  - >
-                    echo "Migrating using image swatch-database-$(MIGRATION_IMAGE_TAG)";
-                    /deployments/wait_for.sh job -lclowdjob=swatch-database-$(MIGRATION_JOB_ID)
-                env:
-                  - name: MIGRATION_JOB_ID
-                    valueFrom:
-                      configMapKeyRef:
-                        name: migration-conf
-                        key: jobId
-                  - name: MIGRATION_IMAGE_TAG
-                    valueFrom:
-                      configMapKeyRef:
-                        name: migration-conf
-                        key: imageTag
+              - image: ${MIGRATION_IMAGE}:${MIGRATION_TAG}
+                command: ["/opt/jboss/container/java/run/run-java.sh"]
+                args: ["core", "update"]
+                inheritEnv: true
                 resources:
                   requests:
-                    cpu: ${WAIT_CPU_REQUEST}
-                    memory: ${WAIT_MEMORY_REQUEST}
+                    cpu: ${MIGRATION_CPU_REQUEST}
+                    memory: ${MIGRATION_MEMORY_REQUEST}
                   limits:
-                    cpu: ${WAIT_CPU_LIMIT}
-                    memory: ${WAIT_MEMORY_LIMIT}
+                    cpu: ${MIGRATION_CPU_LIMIT}
+                    memory: ${MIGRATION_MEMORY_LIMIT}
             env:
               - name: JAVA_DEBUG
                 value: ${JAVA_DEBUG}
diff --git a/swatch-billable-usage/deploy/clowdapp.yaml b/swatch-billable-usage/deploy/clowdapp.yaml
index 7915d8318..b6fc82783 100644
--- a/swatch-billable-usage/deploy/clowdapp.yaml
+++ b/swatch-billable-usage/deploy/clowdapp.yaml
@@ -19,18 +19,18 @@ parameters:
     value: 200m
   - name: CPU_LIMIT
     value: '1'
-  - name: WAIT_IMAGE
+  - name: MIGRATION_IMAGE
     value: quay.io/cloudservices/swatch-database
-  - name: WAIT_TAG
+  - name: MIGRATION_TAG
     value: latest
-  - name: WAIT_MEMORY_REQUEST
-    value: 10Mi
-  - name: WAIT_MEMORY_LIMIT
-    value: 20Mi
-  - name: WAIT_CPU_REQUEST
-    value: 100m
-  - name: WAIT_CPU_LIMIT
+  - name: MIGRATION_MEMORY_REQUEST
+    value: 256Mi
+  - name: MIGRATION_MEMORY_LIMIT
+    value: 512Mi
+  - name: MIGRATION_CPU_REQUEST
     value: 100m
+  - name: MIGRATION_CPU_LIMIT
+    value: 500m
   - name: ENV_NAME
     value: env-swatch-billable-usage
   - name: REPLICAS
@@ -89,6 +89,9 @@ parameters:
     value: '1'
   - name: DISABLE_OTEL
     value: 'false'
+  # allow overriding to support independent deploy with bonfire
+  - name: DB_POD
+    value: swatch-database
 
 objects:
 - apiVersion: cloud.redhat.com/v1alpha1
@@ -143,30 +146,17 @@ objects:
         podSpec:
           image: ${IMAGE}:${IMAGE_TAG}
           initContainers:
-            - image: ${WAIT_IMAGE}:${WAIT_TAG}
-              command: ["/bin/sh","-c"]
-              args:
-                - >
-                  echo "Migrating using image swatch-database-$(MIGRATION_IMAGE_TAG)";
-                  /deployments/wait_for.sh job -lclowdjob=swatch-database-$(MIGRATION_JOB_ID)
-              env:
-                - name: MIGRATION_JOB_ID
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: jobId
-                - name: MIGRATION_IMAGE_TAG
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: imageTag
+            - image: ${MIGRATION_IMAGE}:${MIGRATION_TAG}
+              command: ["/opt/jboss/container/java/run/run-java.sh"]
+              args: ["core", "update"]
+              inheritEnv: true
               resources:
                 requests:
-                  cpu: ${WAIT_CPU_REQUEST}
-                  memory: ${WAIT_MEMORY_REQUEST}
+                  cpu: ${MIGRATION_CPU_REQUEST}
+                  memory: ${MIGRATION_MEMORY_REQUEST}
                 limits:
-                  cpu: ${WAIT_CPU_LIMIT}
-                  memory: ${WAIT_MEMORY_LIMIT}
+                  cpu: ${MIGRATION_CPU_LIMIT}
+                  memory: ${MIGRATION_MEMORY_LIMIT}
           livenessProbe:
             failureThreshold: 3
             httpGet:
@@ -247,6 +237,31 @@ objects:
               value: ${BILLING_PRODUCER_MAX_ATTEMPTS}
             - name: DISABLE_OTEL
               value: ${DISABLE_OTEL}
+            - name: DATABASE_HOST
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.host
+            - name: DATABASE_PORT
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.port
+            - name: DATABASE_USERNAME
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.user
+            - name: DATABASE_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.password
+            - name: DATABASE_DATABASE
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.name
           volumeMounts:
             - name: logs
               mountPath: /logs
diff --git a/swatch-contracts/deploy/clowdapp.yaml b/swatch-contracts/deploy/clowdapp.yaml
index 1707603f4..efa987e44 100644
--- a/swatch-contracts/deploy/clowdapp.yaml
+++ b/swatch-contracts/deploy/clowdapp.yaml
@@ -19,18 +19,18 @@ parameters:
     value: 350m
   - name: CPU_LIMIT
     value: 1500m
-  - name: WAIT_IMAGE
+  - name: MIGRATION_IMAGE
     value: quay.io/cloudservices/swatch-database
-  - name: WAIT_TAG
+  - name: MIGRATION_TAG
     value: latest
-  - name: WAIT_MEMORY_REQUEST
-    value: 10Mi
-  - name: WAIT_MEMORY_LIMIT
-    value: 20Mi
-  - name: WAIT_CPU_REQUEST
-    value: 100m
-  - name: WAIT_CPU_LIMIT
+  - name: MIGRATION_MEMORY_REQUEST
+    value: 256Mi
+  - name: MIGRATION_MEMORY_LIMIT
+    value: 512Mi
+  - name: MIGRATION_CPU_REQUEST
     value: 100m
+  - name: MIGRATION_CPU_LIMIT
+    value: 500m
   - name: ENV_NAME
     value: env-swatch-contracts
   - name: REPLICAS
@@ -167,30 +167,17 @@ objects:
           podSpec:
             image: ${IMAGE}:${IMAGE_TAG}
             initContainers:
-              - image: ${WAIT_IMAGE}:${WAIT_TAG}
-                command: ["/bin/sh","-c"]
-                args:
-                  - >
-                    echo "Migrating using image swatch-database-$(MIGRATION_IMAGE_TAG)";
-                    /deployments/wait_for.sh job -lclowdjob=swatch-database-$(MIGRATION_JOB_ID)
-                env:
-                  - name: MIGRATION_JOB_ID
-                    valueFrom:
-                      configMapKeyRef:
-                        name: migration-conf
-                        key: jobId
-                  - name: MIGRATION_IMAGE_TAG
-                    valueFrom:
-                      configMapKeyRef:
-                        name: migration-conf
-                        key: imageTag
+              - image: ${MIGRATION_IMAGE}:${MIGRATION_TAG}
+                command: ["/opt/jboss/container/java/run/run-java.sh"]
+                args: ["contracts", "update"]
+                inheritEnv: true
                 resources:
                   requests:
-                    cpu: ${WAIT_CPU_REQUEST}
-                    memory: ${WAIT_MEMORY_REQUEST}
+                    cpu: ${MIGRATION_CPU_REQUEST}
+                    memory: ${MIGRATION_MEMORY_REQUEST}
                   limits:
-                    cpu: ${WAIT_CPU_LIMIT}
-                    memory: ${WAIT_MEMORY_LIMIT}
+                    cpu: ${MIGRATION_CPU_LIMIT}
+                    memory: ${MIGRATION_MEMORY_LIMIT}
             livenessProbe:
               failureThreshold: 3
               httpGet:
diff --git a/swatch-database/deploy/clowdapp.yaml b/swatch-database/deploy/clowdapp.yaml
index 3c3c9214c..e78583e73 100644
--- a/swatch-database/deploy/clowdapp.yaml
+++ b/swatch-database/deploy/clowdapp.yaml
@@ -6,47 +6,10 @@ metadata:
 parameters:
   - name: IMAGE_PULL_SECRET
     value: quay-cloudservices-pull
-  - name: MEMORY_REQUEST
-    value: 256Mi
-  - name: MEMORY_LIMIT
-    value: 512Mi
-  - name: CPU_REQUEST
-    value: 100m
-  - name: CPU_LIMIT
-    value: 300m
-  - name: WAIT_IMAGE
-    value: quay.io/cloudservices/swatch-database
-  - name: WAIT_TAG
-    value: latest
-  - name: WAIT_MEMORY_REQUEST
-    value: 10Mi
-  - name: WAIT_MEMORY_LIMIT
-    value: 20Mi
-  - name: WAIT_CPU_REQUEST
-    value: 100m
-  - name: WAIT_CPU_LIMIT
-    value: 100m
   - name: ENV_NAME
     value: env-swatch-database
-  - name: REPLICAS
-    value: '1'
-  - name: IMAGE
-    value: quay.io/cloudservices/swatch-database
-  - name: IMAGE_TAG
-    value: latest
-  - name: JOB_SUFFIX
-    from: '[a-z]{10}'
-    generate: expression
 
 objects:
-  - apiVersion: v1
-    kind: ConfigMap
-    metadata:
-      name: migration-conf
-    data:
-      imageTag: ${IMAGE_TAG}
-      jobId: ${JOB_SUFFIX}
-
   - apiVersion: cloud.redhat.com/v1alpha1
     kind: ClowdApp
     metadata:
@@ -70,68 +33,3 @@ objects:
         # we don't incur an outage
         name: swatch-tally-db
         version: 13
-
-      jobs:
-        - name: migrations-job-${JOB_SUFFIX}
-          activeDeadlineSeconds: 1800
-          successfulJobsHistoryLimit: 2
-          podSpec:
-            image: ${IMAGE}:${IMAGE_TAG}
-            initContainers:
-              - image: ${WAIT_IMAGE}:${WAIT_TAG}
-                command: ["/deployments/wait_for.sh"]
-                args:
-                  - "service"
-                  - "swatch-database-db"
-                resources:
-                  requests:
-                    cpu: ${WAIT_CPU_REQUEST}
-                    memory: ${WAIT_MEMORY_REQUEST}
-                  limits:
-                    cpu: ${WAIT_CPU_LIMIT}
-                    memory: ${WAIT_MEMORY_LIMIT}
-            command: ["/opt/jboss/container/java/run/run-java.sh"]
-            env:
-              - name: DATABASE_HOST
-                valueFrom:
-                  secretKeyRef:
-                    name: swatch-database-db
-                    key: db.host
-              - name: DATABASE_PORT
-                valueFrom:
-                  secretKeyRef:
-                    name: swatch-database-db
-                    key: db.port
-              - name: DATABASE_DATABASE
-                valueFrom:
-                  secretKeyRef:
-                    name: swatch-database-db
-                    key: db.name
-              - name: DATABASE_USERNAME
-                valueFrom:
-                  secretKeyRef:
-                    name: swatch-database-db
-                    key: db.user
-              - name: DATABASE_PASSWORD
-                valueFrom:
-                  secretKeyRef:
-                    name: swatch-database-db
-                    key: db.password
-              - name: LIQUIBASE_LOG_LEVEL
-                value: "INFO"
-            resources:
-              requests:
-                cpu: ${CPU_REQUEST}
-                memory: ${MEMORY_REQUEST}
-              limits:
-                cpu: ${CPU_LIMIT}
-                memory: ${MEMORY_LIMIT}
-
-  - apiVersion: cloud.redhat.com/v1alpha1
-    kind: ClowdJobInvocation
-    metadata:
-      name: swatch-database-${JOB_SUFFIX}
-    spec:
-      appName: swatch-database
-      jobs:
-        - migrations-job-${JOB_SUFFIX}
diff --git a/swatch-database/libs/k8s-wait-for-2.0.zip b/swatch-database/libs/k8s-wait-for-2.0.zip
deleted file mode 100644
index 552adbd7b9baf8248ab0999e261b5253511eda75..0000000000000000000000000000000000000000
GIT binary patch
diff --git a/swatch-database/src/main/docker/Dockerfile.jvm b/swatch-database/src/main/docker/Dockerfile.jvm
index dc7f605eb..9887cebed 100644
--- a/swatch-database/src/main/docker/Dockerfile.jvm
+++ b/swatch-database/src/main/docker/Dockerfile.jvm
@@ -96,7 +96,6 @@ COPY build.gradle settings.gradle dependencies.gradle ./
 COPY buildSrc buildSrc
 
 COPY . .
-RUN unzip -j swatch-database/libs/k8s-wait-for-*.zip -d /stage/k8s-wait-for
 ARG GRADLE_BUILD_ARGS=''
 ARG GRADLE_TASKS='assemble'
 RUN ./gradlew ${GRADLE_TASKS} -x test ${GRADLE_BUILD_ARGS}
@@ -133,11 +132,9 @@ USER default
 ENV LANGUAGE='en_US:en'
 
 COPY --from=0 --chown=default:root --chmod=775 /stage/swatch-database/build/libs/*.jar /deployments/
-COPY --from=0 --chown=default:root --chmod=775 /stage/k8s-wait-for/*.sh /deployments
 
 # Required by Red Hat OpenShift Software Certification Policy Guide
 COPY --from=0 /stage/LICENSE /licenses/
-COPY --from=0 /stage/k8s-wait-for/LICENSE /licenses/LICENSE-k8s-wait-for
 
 # RUN chmod 775 /deployments /deployments/*
 
diff --git a/swatch-metrics-hbi/deploy/clowdapp.yaml b/swatch-metrics-hbi/deploy/clowdapp.yaml
index 6c146e6ef..3ee626e58 100644
--- a/swatch-metrics-hbi/deploy/clowdapp.yaml
+++ b/swatch-metrics-hbi/deploy/clowdapp.yaml
@@ -19,18 +19,18 @@ parameters:
     value: 350m
   - name: CPU_LIMIT
     value: 1500m
-  - name: WAIT_IMAGE
+  - name: MIGRATION_IMAGE
     value: quay.io/cloudservices/swatch-database
-  - name: WAIT_TAG
+  - name: MIGRATION_TAG
     value: latest
-  - name: WAIT_MEMORY_REQUEST
-    value: 10Mi
-  - name: WAIT_MEMORY_LIMIT
-    value: 20Mi
-  - name: WAIT_CPU_REQUEST
-    value: 100m
-  - name: WAIT_CPU_LIMIT
+  - name: MIGRATION_MEMORY_REQUEST
+    value: 256Mi
+  - name: MIGRATION_MEMORY_LIMIT
+    value: 512Mi
+  - name: MIGRATION_CPU_REQUEST
     value: 100m
+  - name: MIGRATION_CPU_LIMIT
+    value: 500m
   - name: ENV_NAME
     value: env-swatch-metrics-hbi
   - name: REPLICAS
@@ -112,30 +112,17 @@ objects:
         podSpec:
           image: ${IMAGE}:${IMAGE_TAG}
           initContainers:
-            - image: ${WAIT_IMAGE}:${WAIT_TAG}
-              command: ["/bin/sh","-c"]
-              args:
-                - >
-                  echo "Migrating using image swatch-database-$(MIGRATION_IMAGE_TAG)";
-                  /deployments/wait_for.sh job -lclowdjob=swatch-database-$(MIGRATION_JOB_ID)
-              env:
-                - name: MIGRATION_JOB_ID
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: jobId
-                - name: MIGRATION_IMAGE_TAG
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: imageTag
+            - image: ${MIGRATION_IMAGE}:${MIGRATION_TAG}
+              command: ["/opt/jboss/container/java/run/run-java.sh"]
+              args: ["core", "update"]
+              inheritEnv: true
               resources:
                 requests:
-                  cpu: ${WAIT_CPU_REQUEST}
-                  memory: ${WAIT_MEMORY_REQUEST}
+                  cpu: ${MIGRATION_CPU_REQUEST}
+                  memory: ${MIGRATION_MEMORY_REQUEST}
                 limits:
-                  cpu: ${WAIT_CPU_LIMIT}
-                  memory: ${WAIT_MEMORY_LIMIT}
+                  cpu: ${MIGRATION_CPU_LIMIT}
+                  memory: ${MIGRATION_MEMORY_LIMIT}
           livenessProbe:
             failureThreshold: 3
             httpGet:
diff --git a/swatch-producer-red-hat-marketplace/deploy/clowdapp.yaml b/swatch-producer-red-hat-marketplace/deploy/clowdapp.yaml
index 31c38f2d0..c4b05d211 100644
--- a/swatch-producer-red-hat-marketplace/deploy/clowdapp.yaml
+++ b/swatch-producer-red-hat-marketplace/deploy/clowdapp.yaml
@@ -41,18 +41,18 @@ parameters:
     value: 350m
   - name: CPU_LIMIT
     value: 1500m
-  - name: WAIT_IMAGE
+  - name: MIGRATION_IMAGE
     value: quay.io/cloudservices/swatch-database
-  - name: WAIT_TAG
+  - name: MIGRATION_TAG
     value: latest
-  - name: WAIT_MEMORY_REQUEST
-    value: 10Mi
-  - name: WAIT_MEMORY_LIMIT
-    value: 20Mi
-  - name: WAIT_CPU_REQUEST
-    value: 100m
-  - name: WAIT_CPU_LIMIT
+  - name: MIGRATION_MEMORY_REQUEST
+    value: 256Mi
+  - name: MIGRATION_MEMORY_LIMIT
+    value: 512Mi
+  - name: MIGRATION_CPU_REQUEST
     value: 100m
+  - name: MIGRATION_CPU_LIMIT
+    value: 500m
   - name: ENV_NAME
     value: env-swatch-producer-red-hat-marketplace
   - name: ENABLE_PAYG_SUBSCRIPTION_FORCE_SYNC
@@ -176,30 +176,17 @@ objects:
         podSpec:
           image: ${IMAGE}:${IMAGE_TAG}
           initContainers:
-            - image: ${WAIT_IMAGE}:${WAIT_TAG}
-              command: ["/bin/sh","-c"]
-              args:
-                - >
-                  echo "Migrating using image swatch-database-$(MIGRATION_IMAGE_TAG)";
-                  /deployments/wait_for.sh job -lclowdjob=swatch-database-$(MIGRATION_JOB_ID)
-              env:
-                - name: MIGRATION_JOB_ID
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: jobId
-                - name: MIGRATION_IMAGE_TAG
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: imageTag
+            - image: ${MIGRATION_IMAGE}:${MIGRATION_TAG}
+              command: ["/opt/jboss/container/java/run/run-java.sh"]
+              args: ["core", "update"]
+              inheritEnv: true
               resources:
                 requests:
-                  cpu: ${WAIT_CPU_REQUEST}
-                  memory: ${WAIT_MEMORY_REQUEST}
+                  cpu: ${MIGRATION_CPU_REQUEST}
+                  memory: ${MIGRATION_MEMORY_REQUEST}
                 limits:
-                  cpu: ${WAIT_CPU_LIMIT}
-                  memory: ${WAIT_MEMORY_LIMIT}
+                  cpu: ${MIGRATION_CPU_LIMIT}
+                  memory: ${MIGRATION_MEMORY_LIMIT}
           env:
             - name: JAVA_DEBUG
               value: ${JAVA_DEBUG}
diff --git a/swatch-subscription-sync/deploy/clowdapp.yaml b/swatch-subscription-sync/deploy/clowdapp.yaml
index 8247b5e90..654315347 100644
--- a/swatch-subscription-sync/deploy/clowdapp.yaml
+++ b/swatch-subscription-sync/deploy/clowdapp.yaml
@@ -41,18 +41,18 @@ parameters:
     value: 1744Mi
   - name: CPU_REQUEST
     value: 500m
-  - name: WAIT_IMAGE
+  - name: MIGRATION_IMAGE
     value: quay.io/cloudservices/swatch-database
-  - name: WAIT_TAG
+  - name: MIGRATION_TAG
     value: latest
-  - name: WAIT_MEMORY_REQUEST
-    value: 10Mi
-  - name: WAIT_MEMORY_LIMIT
-    value: 20Mi
-  - name: WAIT_CPU_REQUEST
-    value: 100m
-  - name: WAIT_CPU_LIMIT
+  - name: MIGRATION_MEMORY_REQUEST
+    value: 256Mi
+  - name: MIGRATION_MEMORY_LIMIT
+    value: 512Mi
+  - name: MIGRATION_CPU_REQUEST
     value: 100m
+  - name: MIGRATION_CPU_LIMIT
+    value: 500m
   - name: CPU_LIMIT
     value: '900m'
   - name: DATABASE_CONNECTION_TIMEOUT_MS
@@ -179,30 +179,17 @@ objects:
         podSpec:
           image: ${IMAGE}:${IMAGE_TAG}
           initContainers:
-            - image: ${WAIT_IMAGE}:${WAIT_TAG}
-              command: ["/bin/sh","-c"]
-              args:
-                - >
-                  echo "Migrating using image swatch-database-$(MIGRATION_IMAGE_TAG)";
-                  /deployments/wait_for.sh job -lclowdjob=swatch-database-$(MIGRATION_JOB_ID)
-              env:
-                - name: MIGRATION_JOB_ID
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: jobId
-                - name: MIGRATION_IMAGE_TAG
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: imageTag
+            - image: ${MIGRATION_IMAGE}:${MIGRATION_TAG}
+              command: ["/opt/jboss/container/java/run/run-java.sh"]
+              args: ["core", "update"]
+              inheritEnv: true
               resources:
                 requests:
-                  cpu: ${WAIT_CPU_REQUEST}
-                  memory: ${WAIT_MEMORY_REQUEST}
+                  cpu: ${MIGRATION_CPU_REQUEST}
+                  memory: ${MIGRATION_MEMORY_REQUEST}
                 limits:
-                  cpu: ${WAIT_CPU_LIMIT}
-                  memory: ${WAIT_MEMORY_LIMIT}
+                  cpu: ${MIGRATION_CPU_LIMIT}
+                  memory: ${MIGRATION_MEMORY_LIMIT}
           env:
             - name: JAVA_DEBUG
               value: ${JAVA_DEBUG}
diff --git a/swatch-tally/deploy/clowdapp.yaml b/swatch-tally/deploy/clowdapp.yaml
index 19f9adfa1..77e6399b6 100644
--- a/swatch-tally/deploy/clowdapp.yaml
+++ b/swatch-tally/deploy/clowdapp.yaml
@@ -47,18 +47,18 @@ parameters:
     value: 350m
   - name: CPU_LIMIT
     value: 1500m
-  - name: WAIT_IMAGE
+  - name: MIGRATION_IMAGE
     value: quay.io/cloudservices/swatch-database
-  - name: WAIT_TAG
+  - name: MIGRATION_TAG
     value: latest
-  - name: WAIT_MEMORY_REQUEST
-    value: 10Mi
-  - name: WAIT_MEMORY_LIMIT
-    value: 20Mi
-  - name: WAIT_CPU_REQUEST
-    value: 100m
-  - name: WAIT_CPU_LIMIT
+  - name: MIGRATION_MEMORY_REQUEST
+    value: 256Mi
+  - name: MIGRATION_MEMORY_LIMIT
+    value: 512Mi
+  - name: MIGRATION_CPU_REQUEST
     value: 100m
+  - name: MIGRATION_CPU_LIMIT
+    value: 400m
   - name: PROM_URL
     value: http://localhost:8082
   - name: DATABASE_CONNECTION_TIMEOUT_MS
@@ -241,6 +241,9 @@ parameters:
     description: Disable Floorist cronjob execution
     required: true
     value: 'false'
+  # allow overriding to support independent deploy with bonfire
+  - name: DB_POD
+    value: swatch-database
 
 objects:
 - apiVersion: cloud.redhat.com/v1alpha1
@@ -300,30 +303,17 @@ objects:
         podSpec:
           image: ${IMAGE}:${IMAGE_TAG}
           initContainers:
-            - image: ${WAIT_IMAGE}:${WAIT_TAG}
-              command: ["/bin/sh","-c"]
-              args:
-                - >
-                  echo "Migrating using image swatch-database-$(MIGRATION_IMAGE_TAG)";
-                  /deployments/wait_for.sh job -lclowdjob=swatch-database-$(MIGRATION_JOB_ID)
-              env:
-                - name: MIGRATION_JOB_ID
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: jobId
-                - name: MIGRATION_IMAGE_TAG
-                  valueFrom:
-                    configMapKeyRef:
-                      name: migration-conf
-                      key: imageTag
+            - image: ${MIGRATION_IMAGE}:${MIGRATION_TAG}
+              command: ["/opt/jboss/container/java/run/run-java.sh"]
+              args: ["core", "update"]
+              inheritEnv: true
               resources:
                 requests:
-                  cpu: ${WAIT_CPU_REQUEST}
-                  memory: ${WAIT_MEMORY_REQUEST}
+                  cpu: ${MIGRATION_CPU_REQUEST}
+                  memory: ${MIGRATION_MEMORY_REQUEST}
                 limits:
-                  cpu: ${WAIT_CPU_LIMIT}
-                  memory: ${WAIT_MEMORY_LIMIT}
+                  cpu: ${MIGRATION_CPU_LIMIT}
+                  memory: ${MIGRATION_MEMORY_LIMIT}
           env:
             - name: JAVA_DEBUG
               value: ${JAVA_DEBUG}
@@ -394,6 +384,31 @@ objects:
               value: ${DATABASE_CONNECTION_TIMEOUT_MS}
             - name: DATABASE_MAX_POOL_SIZE
               value: ${DATABASE_MAX_POOL_SIZE}
+            - name: DATABASE_HOST
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.host
+            - name: DATABASE_PORT
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.port
+            - name: DATABASE_USERNAME
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.user
+            - name: DATABASE_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.password
+            - name: DATABASE_DATABASE
+              valueFrom:
+                secretKeyRef:
+                  name: ${DB_POD}-db
+                  key: db.name
             - name: INVENTORY_DATABASE_HOST
               valueFrom:
                 secretKeyRef:
@@ -747,19 +762,6 @@ objects:
         podSpec:
           image: ${EGRESS_IMAGE}:${EGRESS_IMAGE_TAG}
           name: db-changelog-cleanup
-          initContainers:
-            - image: ${WAIT_IMAGE}:${WAIT_TAG}
-              command: ["/deployments/wait_for.sh"]
-              args:
-                - "service"
-                - "swatch-database-db"
-              resources:
-                requests:
-                  cpu: ${WAIT_CPU_REQUEST}
-                  memory: ${WAIT_MEMORY_REQUEST}
-                limits:
-                  cpu: ${WAIT_CPU_LIMIT}
-                  memory: ${WAIT_MEMORY_LIMIT}
           command: ["/bin/sh", "-c"]
           args:
           - psql -h $POSTGRESQL_SERVICE_HOST -U $POSTGRESQL_USER $POSTGRESQL_DATABASE -c "$DB_CHANGELOG_CLEANUP_SQL"
-- 
2.49.0

