Skip to content

Commit

Permalink
Revert "feat(taxref): add taxref_tree materialized view (#567)"
Browse files Browse the repository at this point in the history
This reverts commit 8cd6d28.
  • Loading branch information
amandine-sahl committed Nov 29, 2024
1 parent 18b662f commit b5305b9
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 142 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jobs:
psql -h localhost -U taxhubadmin -d taxhub -tc 'CREATE EXTENSION "unaccent";'
psql -h localhost -U taxhubadmin -d taxhub -tc 'CREATE EXTENSION "uuid-ossp";'
psql -h localhost -U taxhubadmin -d taxhub -tc 'CREATE EXTENSION "pg_trgm";'
psql -h localhost -U taxhubadmin -d taxhub -tc 'CREATE EXTENSION "ltree";'
env:
PGPASSWORD: taxhubpwd
- uses: actions/checkout@v3
Expand Down
77 changes: 0 additions & 77 deletions apptax/migrations/versions/83d7105edb76_taxref_tree.py

This file was deleted.

1 change: 0 additions & 1 deletion apptax/taxonomie/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ def refresh_taxref_vm():
db.session.execute("REFRESH MATERIALIZED VIEW taxonomie.vm_phylum")
db.session.execute("REFRESH MATERIALIZED VIEW taxonomie.vm_regne")
db.session.execute("REFRESH MATERIALIZED VIEW taxonomie.vm_taxref_list_forautocomplete")
db.session.execute("REFRESH MATERIALIZED VIEW taxonomie.vm_taxref_tree")


def get_csv_field_names(f, encoding, delimiter):
Expand Down
19 changes: 1 addition & 18 deletions apptax/taxonomie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.schema import FetchedValue
from sqlalchemy.orm import backref, deferred, raiseload, joinedload, foreign, remote
from sqlalchemy.orm import deferred, raiseload, joinedload

from utils_flask_sqla.serializers import serializable
from ref_geo.models import LAreas
Expand Down Expand Up @@ -176,7 +176,6 @@ class Taxref(db.Model):
synonymes = db.relationship(
"Taxref", foreign_keys=[cd_ref], primaryjoin="Taxref.cd_ref == Taxref.cd_ref", uselist=True
)
parent = db.relationship("Taxref", primaryjoin=foreign(cd_sup) == remote(cd_ref))
attributs = db.relationship("CorTaxonAttribut", back_populates="taxon")
listes = db.relationship("BibListes", secondary=cor_nom_liste, back_populates="noms")
medias = db.relationship("apptax.taxonomie.models.TMedias", back_populates="taxon")
Expand Down Expand Up @@ -230,9 +229,6 @@ def where_params(cls, filters=None, *, query):
query = query.filter(col.ilike(value + "%"))
return query

def __le__(self, other):
return self.tree <= other.tree


@serializable
class BibListes(db.Model):
Expand Down Expand Up @@ -542,19 +538,6 @@ class TMetaTaxref(db.Model):
update_date = db.Column(db.DateTime, default=db.func.now(), nullable=False)


class TaxrefTree(db.Model):
__tablename__ = "vm_taxref_tree"
__table_args__ = {"schema": "taxonomie"}
cd_nom = db.Column(db.Integer, ForeignKey("taxonomie.taxref.cd_nom"), primary_key=True)
taxref = db.relationship(Taxref, backref=backref("tree", uselist=False))
path = db.Column(db.String, nullable=False)

def __le__(self, other):
# self <= other means taxon other is the same or a parent of self
p1, p2 = self.path.split("."), other.path.split(".")
return len(p1) >= len(p2) and p1[: len(p2)] == p2


# Taxref deffered properties

Taxref.nb_medias = deferred(
Expand Down
37 changes: 0 additions & 37 deletions apptax/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,6 @@

@pytest.mark.usefixtures("client_class", "temporary_transaction")
class TestModels:
def test_taxref_tree_comparison(self):
animalia = db.session.execute(
sa.select(TaxrefTree).where(TaxrefTree.cd_nom == 183716)
).scalar_one()
capra_ibex = db.session.execute(
sa.select(TaxrefTree).where(TaxrefTree.cd_nom == 61098)
).scalar_one()
cinnamon = db.session.execute(
sa.select(TaxrefTree).where(TaxrefTree.cd_nom == 706584)
).scalar_one()

assert animalia <= animalia
assert capra_ibex <= animalia
assert not animalia <= capra_ibex
assert not cinnamon <= animalia
assert not animalia <= cinnamon
assert not cinnamon <= capra_ibex
assert not capra_ibex <= cinnamon

def test_taxref_comparison(self):
animalia = db.session.execute(
sa.select(Taxref).where(Taxref.cd_nom == 183716)
).scalar_one()
capra_ibex = db.session.execute(
sa.select(Taxref).where(Taxref.cd_nom == 61098)
).scalar_one()
cinnamon = db.session.execute(
sa.select(Taxref).where(Taxref.cd_nom == 706584)
).scalar_one()

assert animalia <= animalia
assert capra_ibex <= animalia
assert not animalia <= capra_ibex
assert not cinnamon <= animalia
assert not animalia <= cinnamon
assert not cinnamon <= capra_ibex
assert not capra_ibex <= cinnamon

def test_tmedias_media_url_url(self, nom_with_media):
taxon = db.session.execute(sa.select(Taxref).where(Taxref.cd_nom == 60577)).scalar_one()
Expand Down
7 changes: 1 addition & 6 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
- Ajout des propriétés optionnelles sur la route `/taxref` permettant de récupérer les attributs et les médias de chaque taxon (#498)
- Ajout d'une route `/bdc_statuts/status_symbologies` renvoyant la symbologie de statuts des taxons (couleurs des valeurs des listes rouges) (#510, par @edelclaux)
- Amélioration de la vue `taxonomie.vm_taxref_list_forautocomplete` pour afficher tous les noms d'un taxon (#332, par @JulienCorny et @andriacap)
- Ajout d’une vue matérialisée `vm_taxref_tree` contenant pour chaque `cd_nom` la liste complète des `cd_ref` de ses taxons parents (#567, par @jbdesbas, @amandine-sahl, @bouttier)
- Mise à jour de dépendances python, dont UsersHub-authentification-module en version 3.0.0 et Flask en version 3
- L'image Docker de TaxHub n'est plus générée automatiquement en raison de son intégration à GeoNature (#519)
- Suppression du code spécifique Amazon S3. Pour utiliser des services S3 de stockage des médias, il est toujours possible de monter un volume pour y déposer directement les médias
Expand All @@ -43,11 +42,7 @@
- `APPLICATION_ROOT`
- `SECRET_KEY`
- `PASS_METHOD` (si vous l'aviez renseigné)
- Ajouter la nouvelle extension `ltree` à votre base de données :
```bash
sudo -n -u postgres -s psql -d $db_name -c 'CREATE EXTENSION ltree;'
```
- Désormais si vous modifier la table `taxonomie.taxref` (pour ajoute un taxon local par exemple), vous devez rafraichir la nouvelle vue avec la requête `REFRESH MATERIALIZED VIEW taxonomie.vm_taxref_tree`

- Les données de la table `bib_noms` ont été sauvegardées sous deux formes :
- dans la table `archive_bib_noms` : ce qui pourra vous permettre de récupérer les données "nom_français" ainsi que "commentaire" (ils n'étaient plus utilisés dans les recherche de taxons depuis plusieurs versions)
- dans une liste nommée `BIB_NOMS`
Expand Down
2 changes: 0 additions & 2 deletions install_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ then

sudo -n -u postgres -s psql -d $db_name -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";' &>> $LOG_FILE

sudo -n -u postgres -s psql -d $db_name -c 'CREATE EXTENSION IF NOT EXISTS ltree;' &>> $LOG_FILE

sudo -n -u postgres -s psql -d $db_name -c 'CREATE EXTENSION IF NOT EXISTS "postgis";' &>> $LOG_FILE

echo "Extracting PostGIS version..."
Expand Down

0 comments on commit b5305b9

Please sign in to comment.