Skip to content

Commit 28dd5c2

Browse files
Add ExternalDataSource to model
1 parent 837bf90 commit 28dd5c2

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

app/db/model.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
ElectricalRecordingStimulusType,
5151
ElectricalRecordingType,
5252
EntityType,
53+
ExternalDataSource,
5354
MeasurementStatistic,
5455
MeasurementUnit,
5556
PointLocation,
@@ -539,6 +540,22 @@ class Publication(Identifiable):
539540
__table_args__ = (Index("ix_publication_doi_normalized", func.lower(DOI), unique=True),)
540541

541542

543+
class ExternalDataSourcePage(Identifiable, NameDescriptionVectorMixin):
544+
"""Represents a web page on an external data source.
545+
546+
Attributes:
547+
id (uuid.UUID): Primary key.
548+
source_label (ExternalDataSource): Unique label for the data source, e.g. channelpedia.
549+
url (str): URL of the data source webpage,
550+
e.g. "https://channelpedia.epfl.ch/wikipages/189".
551+
552+
"""
553+
554+
__tablename__ = EntityType.external_data_source_page.value
555+
source_label: Mapped[ExternalDataSource]
556+
url: Mapped[str] = mapped_column(String, index=True, unique=True)
557+
558+
542559
class ScientificArtifact(Entity, SubjectMixin, LocationMixin, LicensedMixin):
543560
"""Represents a scientific artifact entity in the database.
544561
@@ -1290,6 +1307,53 @@ class ScientificArtifactPublicationLink(Identifiable):
12901307
)
12911308

12921309

1310+
class ScientificArtifactExternalDataSourcePageLink(Identifiable):
1311+
"""Represents the association between a scientific artifact and an external data source page.
1312+
1313+
It enforces uniqueness on the combination of external data source page and scientific artifact,
1314+
ensuring that each artifact-database URL pair is unique.
1315+
1316+
Attributes:
1317+
external_data_source_page_id (UUID): Foreign key referencing
1318+
the associated external data source page.
1319+
scientific_artifact_id (UUID): Foreign key referencing the associated scientific artifact.
1320+
external_data_source_page (ExternalDataSourcePage): Relationship to the
1321+
external data source page model.
1322+
scientific_artifact (ScientificArtifact): Relationship to the ScientificArtifact model.
1323+
1324+
Table:
1325+
Unique constraint on (external_data_source_page_id, scientific_artifact_id).
1326+
"""
1327+
1328+
__tablename__ = "scientific_artifact_external_data_source_page_link"
1329+
external_data_source_page_id: Mapped[UUID] = mapped_column(
1330+
ForeignKey("external_data_source_page.id"), index=True
1331+
)
1332+
scientific_artifact_id: Mapped[UUID] = mapped_column(
1333+
ForeignKey("scientific_artifact.id"), index=True
1334+
)
1335+
1336+
# Relationships - assuming ScientificArtifact and ExternalDataSourcePage exist
1337+
external_data_source_page: Mapped["ExternalDataSourcePage"] = relationship(
1338+
"ExternalDataSourcePage",
1339+
foreign_keys=[external_data_source_page_id],
1340+
uselist=False,
1341+
)
1342+
scientific_artifact: Mapped["ScientificArtifact"] = relationship(
1343+
"ScientificArtifact",
1344+
foreign_keys=[scientific_artifact_id],
1345+
uselist=False,
1346+
)
1347+
1348+
__table_args__ = (
1349+
UniqueConstraint(
1350+
"external_data_source_page_id",
1351+
"scientific_artifact_id",
1352+
name="uq_saedspl_external_data_source_page_id_scientific_artifact_id",
1353+
),
1354+
)
1355+
1356+
12931357
class Circuit(ScientificArtifact, NameDescriptionVectorMixin):
12941358
"""Represents a neural circuit as a scientific artifact.
12951359

0 commit comments

Comments
 (0)