From a8bac38f285d34404612f4642083fad1f934b5d7 Mon Sep 17 00:00:00 2001 From: Amandine Date: Wed, 14 Aug 2024 13:54:18 +0200 Subject: [PATCH] Rename alembic branches and remove code profil 3,4 (#541) --- .github/workflows/pytest.yml | 4 +- .../1f7b958108ed_remove_code_profil_3_4.py | 63 +++++++++++++++++++ .../versions/3fe8c07741be_taxhub_admin.py | 2 +- .../versions/fa5a90853c45_taxhub.py | 2 +- docs/changelog.md | 1 + install_db.sh | 4 +- 6 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 apptax/migrations/versions/1f7b958108ed_remove_code_profil_3_4.py diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index cc36b03c1..1f02860cd 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -83,8 +83,8 @@ jobs: -r requirements-dev.in - name: Install database run: | - flask db upgrade taxhub@head -x local-srid=2154 - flask db upgrade taxhub-standalone@head + flask db upgrade taxhub-standalone@head -x local-srid=2154 + flask db upgrade taxhub-standalone-sample@head flask db upgrade ref_geo_fr_departments@head flask db autoupgrade flask db status diff --git a/apptax/migrations/versions/1f7b958108ed_remove_code_profil_3_4.py b/apptax/migrations/versions/1f7b958108ed_remove_code_profil_3_4.py new file mode 100644 index 000000000..17a365fb8 --- /dev/null +++ b/apptax/migrations/versions/1f7b958108ed_remove_code_profil_3_4.py @@ -0,0 +1,63 @@ +"""Remove code_profil 3, 4 + +Revision ID: 1f7b958108ed +Revises: 64d38dbe7739 +Create Date: 2024-08-14 12:13:46.319115 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "1f7b958108ed" +down_revision = "64d38dbe7739" +branch_labels = None +depends_on = None + + +def upgrade(): + # Mise à jour des droits utilisateurs + op.execute( + """ + UPDATE utilisateurs.cor_role_app_profil cor SET id_profil = (SELECT id_profil FROM utilisateurs.t_profils WHERE code_profil = '2' LIMIT 1) + FROM utilisateurs.t_applications app + WHERE cor.id_application = app.id_application AND app.code_application = 'TH' + AND id_profil IN (SELECT id_profil FROM utilisateurs.t_profils WHERE code_profil IN ('3', '4')) + AND NOT EXISTS ( + SELECT 1 + FROM utilisateurs.cor_role_app_profil cor, utilisateurs.t_applications app + WHERE cor.id_application = app.id_application AND app.code_application = 'TH' + AND id_profil = (SELECT id_profil FROM utilisateurs.t_profils WHERE code_profil = '2' LIMIT 1) + ) + """ + ) + # Suppression des profils + op.execute( + """ + DELETE FROM utilisateurs.cor_profil_for_app cor + USING utilisateurs.t_applications app + WHERE cor.id_application = app.id_application + AND app.code_application = 'TH' + AND id_profil IN (SELECT id_profil FROM utilisateurs.t_profils WHERE code_profil IN ('3', '4')); + """ + ) + + +def downgrade(): + + op.execute( + """ + INSERT INTO utilisateurs.cor_profil_for_app + (id_profil, id_application) + VALUES + ( + (SELECT id_profil FROM utilisateurs.t_profils WHERE code_profil = '3'), + (SELECT id_application FROM utilisateurs.t_applications WHERE code_application = 'TH') + ), ( + (SELECT id_profil FROM utilisateurs.t_profils WHERE code_profil = '4'), + (SELECT id_application FROM utilisateurs.t_applications WHERE code_application = 'TH') + ) + """ + ) diff --git a/apptax/migrations/versions/3fe8c07741be_taxhub_admin.py b/apptax/migrations/versions/3fe8c07741be_taxhub_admin.py index 1d47a9fe0..b6c2f4668 100644 --- a/apptax/migrations/versions/3fe8c07741be_taxhub_admin.py +++ b/apptax/migrations/versions/3fe8c07741be_taxhub_admin.py @@ -12,7 +12,7 @@ # revision identifiers, used by Alembic. revision = "3fe8c07741be" down_revision = None -branch_labels = ("taxhub-standalone",) +branch_labels = ("taxhub-standalone-sample",) depends_on = ( "fa5a90853c45", # taxhub "72f227e37bdf", # utilisateurs schema samples data diff --git a/apptax/migrations/versions/fa5a90853c45_taxhub.py b/apptax/migrations/versions/fa5a90853c45_taxhub.py index 289887aab..9582c7e41 100644 --- a/apptax/migrations/versions/fa5a90853c45_taxhub.py +++ b/apptax/migrations/versions/fa5a90853c45_taxhub.py @@ -12,7 +12,7 @@ # revision identifiers, used by Alembic. revision = "fa5a90853c45" down_revision = None -branch_labels = ("taxhub",) +branch_labels = ("taxhub-standalone",) depends_on = ("fa35dfe5ff27",) # schema utilisateurs diff --git a/docs/changelog.md b/docs/changelog.md index 5dc1f6c87..1ec5e34ff 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -22,6 +22,7 @@ - Ajout du paramètre `API_PREFIX` si on souhaite rajouter in préfixe devant les routes de l'API TaxHub (ne pas renseigné si vous utilisez TaxHub avec GeoNature) - L'image Docker de TaxHub n'est plus générée pour en raison de son integration à GeoNature (#519) - suppression du support Amazon S3 +- Les branches taxhub et taxhub-admin ont été renommée en taxhub-standalone et taxhub-standalone-sample. diff --git a/install_db.sh b/install_db.sh index d6b8bd93e..d872fd839 100755 --- a/install_db.sh +++ b/install_db.sh @@ -98,8 +98,8 @@ then flask db stamp 72f227e37bdf # utilisateurs-samples fi - flask db upgrade taxonomie@head -x local-srid=2154 - flask db upgrade taxhub-standalone@head + flask db upgrade taxhub-standalone@head -x local-srid=2154 + flask db upgrade taxhub-standalone-sample@head flask db upgrade ref_geo_fr_departments@head flask db autoupgrade