4
4
from uuid import uuid4
5
5
6
6
import sqlalchemy .types as types
7
- from sqlalchemy import Boolean , Column , Integer , String , create_engine
8
- from sqlalchemy .orm import declarative_base , declarative_mixin , registry , sessionmaker
7
+ from sqlalchemy import Boolean , Column , ForeignKey , Integer , String , create_engine
8
+ from sqlalchemy .orm import declarative_base , declarative_mixin , registry , relationship , sessionmaker
9
9
10
10
from jupyter_scheduler .models import EmailNotifications , Status
11
11
from jupyter_scheduler .utils import get_utc_timestamp
@@ -67,6 +67,14 @@ def process_result_value(self, value, dialect):
67
67
mapper_registry = registry ()
68
68
69
69
70
+ class NotificationsConfig (Base ):
71
+ __tablename__ = "notifications_config"
72
+ id = Column (String (36 ), primary_key = True , default = generate_uuid )
73
+ include_output = Column (Boolean , default = False )
74
+ send_to = Column (JsonType , nullable = False )
75
+ events = Column (JsonType , nullable = False )
76
+
77
+
70
78
@declarative_mixin
71
79
class CommonColumns :
72
80
runtime_environment_name = Column (String (256 ), nullable = False )
@@ -98,7 +106,8 @@ class Job(CommonColumns, Base):
98
106
url = Column (String (256 ), default = generate_jobs_url )
99
107
pid = Column (Integer )
100
108
idempotency_token = Column (String (256 ))
101
- notifications_config = Column (JsonType (1024 ), nullable = True )
109
+ notifications_config_id = Column (String (36 ), ForeignKey ("notifications_config.id" ))
110
+ notifications_config = relationship ("NotificationsConfig" )
102
111
103
112
104
113
class JobDefinition (CommonColumns , Base ):
@@ -109,7 +118,8 @@ class JobDefinition(CommonColumns, Base):
109
118
url = Column (String (256 ), default = generate_job_definitions_url )
110
119
create_time = Column (Integer , default = get_utc_timestamp )
111
120
active = Column (Boolean , default = True )
112
- notifications_config = Column (JsonType (1024 ), nullable = True )
121
+ notifications_config_id = Column (String (36 ), ForeignKey ("notifications_config.id" ))
122
+ notifications_config = relationship ("NotificationsConfig" )
113
123
114
124
115
125
def create_tables (db_url , drop_tables = False ):
0 commit comments