From 7c2a4264047a3c7498470fb9d3f5b078fc77d922 Mon Sep 17 00:00:00 2001 From: selfhoster1312 Date: Mon, 3 Mar 2025 15:03:53 +0100 Subject: [PATCH] ci: Test sql migrations with sqlite backend --- .gitlab-ci.yml | 19 +++++++++++++++++++ la_chariotte/settings.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 56bdf39..e62eb27 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ tests: image: python:3.11 variables: DJANGO_SETTINGS_MODULE: "la_chariotte.settings" + DB_ENGINE: "django.db.backends.postgresql" DB_NAME: "postgres" DB_USER: "postgres" DB_PASSWORD: "mysecretpassword" @@ -30,3 +31,21 @@ tests: - git fetch origin develop ; diff-cover coverage.xml --fail-under=90 --compare-branch origin/develop --diff-range-notation '..' - echo "Tests done." +sqlite: + stage: test + image: python:3.11 + variables: + DJANGO_SETTINGS_MODULE: "la_chariotte.settings" + script: + - export CACHE_PATH="/venvs/${CI_PROJECT_NAME}/$(date +week-%V-%Y)" + - if [[ "$CI_COMMIT_BRANCH" == *"--no-cache"* ]] ; then export CACHE_PATH="/venvs/$CI_COMMIT_SHORT_SHA"; fi + - echo "Creating virtual env..." + - if [ ! -d $CACHE_PATH/venv ] ; then python3.11 -m venv $CACHE_PATH/venv ; fi + - $CACHE_PATH/venv/bin/pip install --upgrade pip + - echo "Virtual env created." + - echo "Checking database migrations with sqlite..." + - source $CACHE_PATH/venv/bin/activate + - pip cache purge + - pip install -e ".[dev]" + - python3 manage.py migrate + - echo "sqlite database migrations successful" diff --git a/la_chariotte/settings.py b/la_chariotte/settings.py index ab194d3..130081c 100644 --- a/la_chariotte/settings.py +++ b/la_chariotte/settings.py @@ -85,7 +85,7 @@ WSGI_APPLICATION = "la_chariotte.wsgi.application" DATABASES = { "default": { - "ENGINE": "django.db.backends.sqlite3", + "ENGINE": os.getenv("DB_ENGINE", "django.db.backends.sqlite3"), "NAME": os.getenv("DB_NAME", "chariotte.sqlite3"), } }