Skip to content

Commit

Permalink
[Monitoring] Add t_observations.cd_nom foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Jan 7, 2025
1 parent 681c799 commit d13fe4f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/geonature/core/gn_monitoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class TObservations(DB.Model):
digitiser = DB.relationship(
User, primaryjoin=(User.id_role == id_digitiser), foreign_keys=[id_digitiser]
)
cd_nom = DB.Column(DB.Integer)
cd_nom = DB.Column(DB.Integer, DB.ForeignKey("taxonomie.taxref.cd_nom"))
comments = DB.Column(DB.String)
uuid_observation = DB.Column(UUID(as_uuid=True), default=select(func.uuid_generate_v4()))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""[monitoring] Add cd_nom foreign key
Revision ID: 5b61bcaa18da
Revises: 2894b3c03c66
Create Date: 2025-01-07 14:28:20.475116
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "5b61bcaa18da"
down_revision = "2894b3c03c66"
branch_labels = None
depends_on = None


def upgrade():
# Création clé étrangère sur la table t_observations
op.create_foreign_key(
"fk_t_observations_cd_nom_fkey",
source_schema="gn_monitoring",
source_table="t_observations",
local_cols=["cd_nom"],
referent_schema="taxonomie",
referent_table="taxref",
remote_cols=["cd_nom"],
onupdate=None,
ondelete=None,
)


def downgrade():
op.drop_constraint(
"fk_t_observations_cd_nom_fkey",
table_name="t_observations",
schema="gn_monitoring",
)

0 comments on commit d13fe4f

Please sign in to comment.