Skip to content

Commit d6e65f9

Browse files
committed
fix: added examples for table extensions and fields mods
1 parent 5d1cd7d commit d6e65f9

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

  • extensions/gubbins/gubbins-db/src/gubbins/db/sql/jobs

extensions/gubbins/gubbins-db/src/gubbins/db/sql/jobs/schema.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,58 @@
11
from diracx.db.sql.job.db import JobDBBase
2+
from diracx.db.sql.job.schema import InputData, Jobs
23
from diracx.db.sql.utils import Column
34
from sqlalchemy import (
45
ForeignKey,
6+
Index,
57
Integer,
68
String,
9+
Text,
710
)
811

912

13+
# Create a new external table for Gubbins-specific categories
14+
class GubbinsCategories(JobDBBase):
15+
"""External table for Gubbins-specific categories"""
16+
17+
__tablename__ = "GubbinsCategories"
18+
19+
category_id = Column("CategoryID", Integer, primary_key=True, autoincrement=True)
20+
category_name = Column("CategoryName", String(255), nullable=False)
21+
description = Column("Description", Text, default="")
22+
23+
__table_args__ = (Index("CategoryName", "CategoryName"),)
24+
25+
26+
# Create a new Jobs table with modified schema (replacing the original)
27+
class GubbinsJobs(Jobs):
28+
"""Custom Jobs table with modified column specifications and foreign key to GubbinsCategories"""
29+
30+
__tablename__ = "Jobs"
31+
32+
# Modified: job_name with VARCHAR(512) instead of VARCHAR(128)
33+
job_name = Column("JobName", String(512), default="Unknown")
34+
35+
# New foreign key constraint to GubbinsCategories table
36+
category_id = Column(
37+
"CategoryID", Integer, ForeignKey("GubbinsCategories.CategoryID")
38+
)
39+
40+
41+
# Extended InputData table with Adler checksum column
42+
class GubbinsInputData(InputData):
43+
"""Extended InputData table with Adler checksum support"""
44+
45+
__tablename__ = "InputData"
46+
47+
# New column for Adler checksum
48+
adler_checksum = Column("AdlerChecksum", String(75), nullable=True)
49+
50+
1051
# You need to inherit from the declarative_base of the parent DB
1152
class GubbinsInfo(JobDBBase):
1253
"""An extra table with respect to Vanilla diracx JobDB"""
1354

14-
__tablename__ = "GubbinsJobs"
55+
__tablename__ = "GubbinsInfo"
1556

1657
job_id = Column(
1758
"JobID", Integer, ForeignKey("Jobs.JobID", ondelete="CASCADE"), primary_key=True

0 commit comments

Comments
 (0)