Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Replace constraints name refs by column refs (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinclert authored Nov 5, 2023
1 parent 9a79de3 commit 5450301
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 54 deletions.
64 changes: 32 additions & 32 deletions src/dialect_map_core/models/jargon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@
from .__utils import generate_id


class JargonGroup(Base, ArchivalModel):
"""
Jargon group to relate jargons with similar meaning.
Contains all the static properties of a jargon group
"""

__tablename__ = "jargon_groups"

group_id = Column(String(32), nullable=False, primary_key=True, default=generate_id)
description = Column(String(256), nullable=False)

# All main table relationships to child tables. References:
# Official docs: https://docs.sqlalchemy.org/en/20/orm/basic_relationships.html
# Stackoverflow: https://stackoverflow.com/a/38770040
jargons = relationship(
argument="Jargon",
backref="jargons",
passive_deletes=True,
)

@property
def id(self) -> str:
"""
Gets the unique ID of the data object
:return: unique ID
"""

return self.group_id


class Jargon(Base, ArchivalModel):
"""
Jargon term related information record.
Expand All @@ -25,8 +55,8 @@ class Jargon(Base, ArchivalModel):

__table_args__ = (
FKConstraint(
columns=("group_id",),
refcolumns=("jargon_groups.group_id",),
columns=[group_id],
refcolumns=[JargonGroup.group_id],
ondelete="CASCADE",
),
)
Expand All @@ -53,33 +83,3 @@ def id(self) -> str:
"""

return self.jargon_id


class JargonGroup(Base, ArchivalModel):
"""
Jargon group to relate jargons with similar meaning.
Contains all the static properties of a jargon group
"""

__tablename__ = "jargon_groups"

group_id = Column(String(32), nullable=False, primary_key=True, default=generate_id)
description = Column(String(256), nullable=False)

# All main table relationships to child tables. References:
# Official docs: https://docs.sqlalchemy.org/en/20/orm/basic_relationships.html
# Stackoverflow: https://stackoverflow.com/a/38770040
jargons = relationship(
argument="Jargon",
backref="jargons",
passive_deletes=True,
)

@property
def id(self) -> str:
"""
Gets the unique ID of the data object
:return: unique ID
"""

return self.group_id
12 changes: 7 additions & 5 deletions src/dialect_map_core/models/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from .base import Base
from .base import StaticModel
from .category import Category
from .paper import Paper
from .__utils import generate_id


Expand All @@ -29,16 +31,16 @@ class CategoryMembership(Base, StaticModel):
# Stackoverflow: https://stackoverflow.com/a/7506168
__table_args__ = (
FKConstraint(
columns=("arxiv_id", "arxiv_rev"),
refcolumns=("papers.arxiv_id", "papers.arxiv_rev"),
columns=[arxiv_id, arxiv_rev],
refcolumns=[Paper.arxiv_id, Paper.arxiv_rev],
ondelete="CASCADE",
),
FKConstraint(
columns=("category_id",),
refcolumns=("categories.category_id",),
columns=[category_id],
refcolumns=[Category.category_id],
ondelete="CASCADE",
),
UniqueConstraint("arxiv_id", "arxiv_rev", "category_id"),
UniqueConstraint(arxiv_id, arxiv_rev, category_id),
)

@property
Expand Down
19 changes: 11 additions & 8 deletions src/dialect_map_core/models/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from .base import Base
from .base import StaticModel
from .category import Category
from .jargon import Jargon
from .paper import Paper
from .__utils import generate_id


Expand All @@ -27,13 +30,13 @@ class JargonCategoryMetrics(Base, StaticModel):

__table_args__ = (
FKConstraint(
columns=("jargon_id",),
refcolumns=("jargons.jargon_id",),
columns=[jargon_id],
refcolumns=[Jargon.jargon_id],
ondelete="CASCADE",
),
FKConstraint(
columns=("category_id",),
refcolumns=("categories.category_id",),
columns=[category_id],
refcolumns=[Category.category_id],
ondelete="CASCADE",
),
)
Expand Down Expand Up @@ -68,13 +71,13 @@ class JargonPaperMetrics(Base, StaticModel):
# Stackoverflow: https://stackoverflow.com/a/7506168
__table_args__ = (
FKConstraint(
columns=("jargon_id",),
refcolumns=("jargons.jargon_id",),
columns=[jargon_id],
refcolumns=[Jargon.jargon_id],
ondelete="CASCADE",
),
FKConstraint(
columns=("arxiv_id", "arxiv_rev"),
refcolumns=("papers.arxiv_id", "papers.arxiv_rev"),
columns=[arxiv_id, arxiv_rev],
refcolumns=[Paper.arxiv_id, Paper.arxiv_rev],
ondelete="CASCADE",
),
)
Expand Down
8 changes: 4 additions & 4 deletions src/dialect_map_core/models/paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class PaperAuthor(Base, StaticModel):
# Stackoverflow: https://stackoverflow.com/a/7506168
__table_args__ = (
FKConstraint(
columns=("arxiv_id", "arxiv_rev"),
refcolumns=("papers.arxiv_id", "papers.arxiv_rev"),
columns=[arxiv_id, arxiv_rev],
refcolumns=[Paper.arxiv_id, Paper.arxiv_rev],
ondelete="CASCADE",
),
)
Expand Down Expand Up @@ -124,8 +124,8 @@ class PaperReferenceCounters(Base, StaticModel):
# Stackoverflow: https://stackoverflow.com/a/7506168
__table_args__ = (
FKConstraint(
columns=("arxiv_id", "arxiv_rev"),
refcolumns=("papers.arxiv_id", "papers.arxiv_rev"),
columns=[arxiv_id, arxiv_rev],
refcolumns=[Paper.arxiv_id, Paper.arxiv_rev],
ondelete="CASCADE",
),
)
Expand Down
14 changes: 9 additions & 5 deletions src/dialect_map_core/models/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .base import Base
from .base import StaticModel
from .paper import Paper
from .__utils import generate_id


Expand All @@ -30,17 +31,20 @@ class PaperReference(Base, StaticModel):
# Stackoverflow: https://stackoverflow.com/a/7506168
__table_args__ = (
FKConstraint(
columns=("source_arxiv_id", "source_arxiv_rev"),
refcolumns=("papers.arxiv_id", "papers.arxiv_rev"),
columns=[source_arxiv_id, source_arxiv_rev],
refcolumns=[Paper.arxiv_id, Paper.arxiv_rev],
ondelete="CASCADE",
),
FKConstraint(
columns=("target_arxiv_id", "target_arxiv_rev"),
refcolumns=("papers.arxiv_id", "papers.arxiv_rev"),
columns=[target_arxiv_id, target_arxiv_rev],
refcolumns=[Paper.arxiv_id, Paper.arxiv_rev],
ondelete="CASCADE",
),
UniqueConstraint(
"source_arxiv_id", "source_arxiv_rev", "target_arxiv_id", "target_arxiv_rev"
source_arxiv_id,
source_arxiv_rev,
target_arxiv_id,
target_arxiv_rev,
),
)

Expand Down

0 comments on commit 5450301

Please sign in to comment.