From 41118fda23b85f86e7b260e15aacb0a82b310fec Mon Sep 17 00:00:00 2001 From: selfhoster1312 Date: Sun, 2 Mar 2025 15:54:49 +0100 Subject: [PATCH 1/2] feature: Enable sqlite3 support and make it default --- CHANGELOG.md | 8 ++++ .../0017_orderauthor_alter_order_author.py | 8 ++-- ...der_total_price_alter_orderauthor_email.py | 2 +- ...derauthor_email_alter_orderauthor_phone.py | 4 +- .../migrations/0025_groupedorder_code.py | 4 +- ...r_code_alter_orderauthor_email_and_more.py | 46 +++++++++++++++++++ la_chariotte/order/models.py | 8 ++-- la_chariotte/settings.py | 4 +- 8 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 la_chariotte/order/migrations/0030_alter_groupedorder_code_alter_orderauthor_email_and_more.py diff --git a/CHANGELOG.md b/CHANGELOG.md index a688249..7739925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) since 0.4.1, and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## UNRELEASED (XXXX-YY-ZZ) + +### Added + +- SQLite is now a supported database engine for easier deployment; + use `"ENGINE": "django.db.backends.sqlite3"` in the settings to enable it; + the `"NAME"` setting is a relative path for the DB file, from the working directory + ## 1.3.0 (2024-11-02) This is a small release, with a few features and bugfixes. The code is now diff --git a/la_chariotte/order/migrations/0017_orderauthor_alter_order_author.py b/la_chariotte/order/migrations/0017_orderauthor_alter_order_author.py index 4de8599..167f8ab 100644 --- a/la_chariotte/order/migrations/0017_orderauthor_alter_order_author.py +++ b/la_chariotte/order/migrations/0017_orderauthor_alter_order_author.py @@ -22,18 +22,18 @@ class Migration(migrations.Migration): verbose_name="ID", ), ), - ("first_name", models.CharField(verbose_name="Prénom")), - ("last_name", models.CharField(verbose_name="Nom")), + ("first_name", models.CharField(max_length=256, verbose_name="Prénom")), + ("last_name", models.CharField(max_length=256, verbose_name="Nom")), ( "phone", - models.CharField( + models.CharField(max_length=256, help_text="Pour vous que l'organisateur·ice vous contacte en cas de besoin", verbose_name="Numéro de téléphone", ), ), ( "email", - models.CharField( + models.CharField(max_length=256, verbose_name="Pour vous que l'organisateur·ice vous contacte en cas de besoin" ), ), diff --git a/la_chariotte/order/migrations/0020_groupedorder_total_price_alter_orderauthor_email.py b/la_chariotte/order/migrations/0020_groupedorder_total_price_alter_orderauthor_email.py index a2398f6..16aebbe 100644 --- a/la_chariotte/order/migrations/0020_groupedorder_total_price_alter_orderauthor_email.py +++ b/la_chariotte/order/migrations/0020_groupedorder_total_price_alter_orderauthor_email.py @@ -17,7 +17,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="orderauthor", name="email", - field=models.CharField( + field=models.CharField(max_length=256, help_text="Pour vous que l'organisateur·ice vous contacte en cas de besoin", verbose_name="Adresse mail", ), diff --git a/la_chariotte/order/migrations/0021_alter_orderauthor_email_alter_orderauthor_phone.py b/la_chariotte/order/migrations/0021_alter_orderauthor_email_alter_orderauthor_phone.py index 1e836a9..088928c 100644 --- a/la_chariotte/order/migrations/0021_alter_orderauthor_email_alter_orderauthor_phone.py +++ b/la_chariotte/order/migrations/0021_alter_orderauthor_email_alter_orderauthor_phone.py @@ -12,7 +12,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="orderauthor", name="email", - field=models.CharField( + field=models.CharField(max_length=256, help_text="Pour que l'organisateur·ice vous contacte en cas de besoin", verbose_name="Adresse mail", ), @@ -20,7 +20,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="orderauthor", name="phone", - field=models.CharField( + field=models.CharField(max_length=256, help_text="Pour que l'organisateur·ice vous contacte en cas de besoin", verbose_name="Numéro de téléphone", ), diff --git a/la_chariotte/order/migrations/0025_groupedorder_code.py b/la_chariotte/order/migrations/0025_groupedorder_code.py index 47cba02..f9a477c 100644 --- a/la_chariotte/order/migrations/0025_groupedorder_code.py +++ b/la_chariotte/order/migrations/0025_groupedorder_code.py @@ -45,12 +45,12 @@ class Migration(migrations.Migration): migrations.AddField( model_name="groupedorder", name="code", - field=models.CharField(auto_created=True, null=True), + field=models.CharField(max_length=256, auto_created=True, null=True), ), migrations.RunPython(set_code_default, reverse_set_code_default), migrations.AlterField( model_name="groupedorder", name="code", - field=models.CharField(auto_created=True), + field=models.CharField(max_length=256, auto_created=True), ), ] diff --git a/la_chariotte/order/migrations/0030_alter_groupedorder_code_alter_orderauthor_email_and_more.py b/la_chariotte/order/migrations/0030_alter_groupedorder_code_alter_orderauthor_email_and_more.py new file mode 100644 index 0000000..892b4de --- /dev/null +++ b/la_chariotte/order/migrations/0030_alter_groupedorder_code_alter_orderauthor_email_and_more.py @@ -0,0 +1,46 @@ +# Generated by Django 4.2.19 on 2025-03-02 15:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("order", "0029_set_phone_mandatory_for_existing_orders"), + ] + + operations = [ + migrations.AlterField( + model_name="groupedorder", + name="code", + field=models.CharField(auto_created=True, max_length=256), + ), + migrations.AlterField( + model_name="orderauthor", + name="email", + field=models.CharField( + help_text="Pour que l'organisateur·ice vous contacte en cas de besoin", + max_length=256, + verbose_name="Adresse mail", + ), + ), + migrations.AlterField( + model_name="orderauthor", + name="first_name", + field=models.CharField(max_length=256, verbose_name="Prénom"), + ), + migrations.AlterField( + model_name="orderauthor", + name="last_name", + field=models.CharField(max_length=256, verbose_name="Nom"), + ), + migrations.AlterField( + model_name="orderauthor", + name="phone", + field=models.CharField( + help_text="Pour que l'organisateur·ice vous contacte en cas de besoin", + max_length=256, + verbose_name="Numéro de téléphone", + ), + ), + ] diff --git a/la_chariotte/order/models.py b/la_chariotte/order/models.py index 5450f72..fb3b4fe 100644 --- a/la_chariotte/order/models.py +++ b/la_chariotte/order/models.py @@ -25,7 +25,7 @@ class GroupedOrder(models.Model): max_length=100, null=True, blank=True, verbose_name="Lieu de livraison" ) description = models.TextField("Description", null=True, blank=True) - code = models.CharField(auto_created=True) + code = models.CharField(max_length=256, auto_created=True) is_phone_mandatory = models.BooleanField( default=False, verbose_name="Numéro de téléphone obligatoire" ) @@ -101,13 +101,15 @@ class GroupedOrder(models.Model): class OrderAuthor(models.Model): """Used when a user orders (with or without an account)""" - first_name = models.CharField(verbose_name="Prénom") - last_name = models.CharField(verbose_name="Nom") + first_name = models.CharField(max_length=256, verbose_name="Prénom") + last_name = models.CharField(max_length=256, verbose_name="Nom") phone = models.CharField( + max_length=256, verbose_name="Numéro de téléphone", help_text="Pour que l'organisateur·ice vous contacte en cas de besoin", ) email = models.CharField( + max_length=256, verbose_name="Adresse mail", help_text="Pour que l'organisateur·ice vous contacte en cas de besoin", ) diff --git a/la_chariotte/settings.py b/la_chariotte/settings.py index ab6dadc..ab194d3 100644 --- a/la_chariotte/settings.py +++ b/la_chariotte/settings.py @@ -85,8 +85,8 @@ WSGI_APPLICATION = "la_chariotte.wsgi.application" DATABASES = { "default": { - "ENGINE": "django.db.backends.postgresql", - "NAME": os.getenv("DB_NAME", "chariotte"), + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.getenv("DB_NAME", "chariotte.sqlite3"), } } From 7c2a4264047a3c7498470fb9d3f5b078fc77d922 Mon Sep 17 00:00:00 2001 From: selfhoster1312 Date: Mon, 3 Mar 2025 15:03:53 +0100 Subject: [PATCH 2/2] 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"), } }