Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/dev/explanations/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ To develop, follow the same [instruction as `diracx`](../tutorials/getting-start

The `gubbins-db` package contains the extension for the DB.

### New DB
### New SQL DB

`lollygagDB` is a DB which is specific to `gubbins`, i.e. it does not modify or extend an existing `diracx` db

### Extended DB
### Extended SQL DB

`GubbinsJobDB` illustrates how to extend an existing `diracx` DB, add new methods, modify methods, add a table.
`GubbinsJobDB` illustrates how to extend an existing `diracx` SQL DB, add new methods, modify methods, add a table, adding a column to one table.
Modifying an existing column is instead not supported.

A router test exists (`test_gubbins_job_manager.py`), even though no router is redefined. It is just to show that the correct DB is being loaded.

Expand Down
21 changes: 18 additions & 3 deletions extensions/gubbins/gubbins-db/src/gubbins/db/sql/jobs/schema.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
from diracx.db.sql.job.db import JobDBBase
from diracx.db.sql.job.schema import str255
from diracx.db.sql.job.schema import InputData, str255
from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, mapped_column


# You need to inherit from the DeclarativeBase of the parent DB
# GubbinsInputData: Extends InputData by ADDING a column
# NOTE: Simple inheritance works here because we're ADDING a new column,
# not modifying an existing one. This is the preferred approach when possible.
class GubbinsInputData(InputData):
"""Extended InputData table with Adler checksum support"""

__tablename__ = "InputData"
__table_args__ = {"extend_existing": True}

# New column for Adler checksum
adler_checksum: Mapped[str255] = mapped_column("AdlerChecksum", default="")


# Example of defining a new table
# NOTE: You need to inherit from the DeclarativeBase of the parent DB
class GubbinsInfo(JobDBBase):
"""An extra table with respect to Vanilla diracx JobDB"""

__tablename__ = "GubbinsJobs"
__tablename__ = "GubbinsInfo"
__table_args__ = {"extend_existing": True}

job_id: Mapped[int] = mapped_column(
"JobID", ForeignKey("Jobs.JobID", ondelete="CASCADE"), primary_key=True
Expand Down
Loading