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")