From 1b392db66913cf54695991a46e16cee9f0ad4b29 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Wed, 30 Dec 2020 12:48:13 +0100
Subject: [PATCH] gitlab-ci-cd/drupal#1 Add test for DB tables and use PULL_DB
 as variable name and commit message indicator to force the update

---
 test-and-deploy.yml | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/test-and-deploy.yml b/test-and-deploy.yml
index c3b23a8..5e1496c 100644
--- a/test-and-deploy.yml
+++ b/test-and-deploy.yml
@@ -60,17 +60,19 @@ variables:
   script: |
     if [[ "$CI_COMMIT_REF_NAME" == "master" ]]; then
       DBREQUIRED="yes"
-    elif [[ "$CI_COMMIT_REF_NAME" == *"[re-build-db]"* ]]; then
+    elif [[ "$CI_COMMIT_REF_NAME" == *"[PULL_DB]"* ]]; then
       DBREQUIRED="yes"
-    elif [[ "$FORCE_DB_UPDATE" == "yes" ]]; then
+    elif [[ "$PULL_DB" == "yes" ]]; then
       DBREQUIRED="yes"
     else
       ID=$(docker container ls --all -q -f name=^${COMPOSE_PROJECT_NAME}_mariadb_1$)
       if [[ ! -n ${ID} ]]; then
         DBREQUIRED="yes"
       else
-        # TODO: check if DB in container is empty.
-        echo "DB check not yet implemented"
+        TABLES=$(docker exec ${COMPOSE_PROJECT_NAME}_mariadb_1 mysql -u drupal --password=drupal -e "show tables;" drupal 2>/dev/null|grep users)
+        if [[ ! -n ${ID} ]]; then
+          DBREQUIRED="yes"
+        fi
       fi
     fi
   except:
-- 
GitLab