From c219fc47d0c64f128fb149c68118e1c55566e3e1 Mon Sep 17 00:00:00 2001 From: Nicolas Oudard Date: Wed, 4 Dec 2024 09:29:20 +0100 Subject: [PATCH] =?UTF-8?q?Commande=20pour=20r=C3=A9-initialiser=20les=20t?= =?UTF-8?q?ables=20dagrun=20et=20dagrunchange=20(#1084)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync_databases.yml | 3 +++ qfdmo/management/commands/reinitialize_dagrun.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 qfdmo/management/commands/reinitialize_dagrun.py diff --git a/.github/workflows/sync_databases.yml b/.github/workflows/sync_databases.yml index b7f14776d..8ff7063e2 100644 --- a/.github/workflows/sync_databases.yml +++ b/.github/workflows/sync_databases.yml @@ -44,6 +44,9 @@ jobs: - name: Execute migrations in one-off container run: | scalingo --app ${PREPROD_APP} run python manage.py migrate + - name: Truncate the dagruns table + run: | + scalingo --app ${PREPROD_APP} run python manage.py reinitialize_dagrun sync_prod_to_preprod_s3: name: Copy Prod s3 bucket to Copy Preprod s3 bucket diff --git a/qfdmo/management/commands/reinitialize_dagrun.py b/qfdmo/management/commands/reinitialize_dagrun.py new file mode 100644 index 000000000..eea492018 --- /dev/null +++ b/qfdmo/management/commands/reinitialize_dagrun.py @@ -0,0 +1,15 @@ +from django.core.management.base import BaseCommand +from django.db import connection + + +class Command(BaseCommand): + help = "Export Ressources using CSV format" + + def handle(self, *args, **options): + with connection.cursor() as cursor: + # Truncate the table qfdmo_dagrun and qfdmo_dagrunchange + cursor.execute("TRUNCATE TABLE qfdmo_dagrun CASCADE") + + # Set auto-increment to 1 + cursor.execute("ALTER SEQUENCE qfdmo_dagrun_id_seq RESTART WITH 1") + cursor.execute("ALTER SEQUENCE qfdmo_dagrunchange_id_seq RESTART WITH 1")