Skip to content

Commit 0bea3f1

Browse files
authored
Merge pull request #2034 from release/2026.03.2
Release 2026.03.2
2 parents 3b2592f + 8e2775a commit 0bea3f1

11 files changed

Lines changed: 39 additions & 192 deletions

File tree

src/apps/activity_assignments/db/schemas.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from sqlalchemy import Column, ForeignKey, Index
2-
from sqlalchemy.dialects.postgresql import UUID
32

43
from infrastructure.database import Base
54

@@ -9,10 +8,10 @@
98
class ActivityAssigmentSchema(Base):
109
__tablename__ = "activity_assignments"
1110

12-
activity_flow_id = Column(UUID(as_uuid=True), nullable=True)
13-
activity_id = Column(UUID(as_uuid=True), nullable=True)
14-
respondent_subject_id = Column(ForeignKey("subjects.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)
15-
target_subject_id = Column(ForeignKey("subjects.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)
11+
activity_flow_id = Column(ForeignKey("flows.id", ondelete="RESTRICT"), nullable=True)
12+
activity_id = Column(ForeignKey("activities.id", ondelete="RESTRICT"), nullable=True)
13+
respondent_subject_id = Column(ForeignKey("subjects.id", ondelete="RESTRICT"), nullable=False)
14+
target_subject_id = Column(ForeignKey("subjects.id", ondelete="RESTRICT"), nullable=False)
1615

1716
__table_args__ = (
1817
Index(

src/apps/alerts/db/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AlertSchema(Base):
2020
nullable=True,
2121
)
2222
subject_id = Column(
23-
ForeignKey("subjects.id", ondelete="RESTRICT", onupdate="CASCADE"),
23+
ForeignKey("subjects.id", ondelete="RESTRICT"),
2424
nullable=True,
2525
)
2626
is_watched = Column(Boolean(), nullable=False, default=False)

src/apps/answers/db/schemas.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
Text,
1010
Time,
1111
Unicode,
12-
UniqueConstraint,
1312
and_,
1413
asc,
1514
false,
@@ -32,9 +31,9 @@ class AnswerSchema(HistoryAware, Base):
3231
version = Column(Text())
3332
submit_id = Column(UUID(as_uuid=True))
3433
client = Column(JSONB())
35-
applet_history_id = Column(String(), nullable=False, index=True)
36-
flow_history_id = Column(String(), nullable=True, index=True)
37-
activity_history_id = Column(String(), nullable=False, index=True)
34+
applet_history_id = Column(Text(), nullable=False, index=True)
35+
flow_history_id = Column(Text(), nullable=True, index=True)
36+
activity_history_id = Column(Text(), nullable=False, index=True)
3837
respondent_id = Column(UUID(as_uuid=True), nullable=True, index=True)
3938
is_flow_completed = Column(Boolean(), nullable=True)
4039
migrated_data = Column(JSONB())
@@ -43,8 +42,8 @@ class AnswerSchema(HistoryAware, Base):
4342
input_subject_id = Column(UUID(as_uuid=True), nullable=True, index=True)
4443
relation = Column(String(length=20), nullable=True)
4544
consent_to_share = Column(Boolean(), default=False)
46-
event_history_id = Column(String(), nullable=True)
47-
device_id = Column(Text(), nullable=True)
45+
event_history_id = Column(String(), nullable=True, index=True)
46+
device_id = Column(Text(), nullable=True, index=True)
4847

4948
answer_item = relationship(
5049
"AnswerItemSchema",
@@ -102,10 +101,8 @@ def is_identifier_encrypted(cls):
102101
class AnswerEHRSchema(Base):
103102
__tablename__ = "answers_ehr"
104103

105-
submit_id = Column(UUID(as_uuid=True))
106-
activity_id = Column(UUID(as_uuid=True))
104+
submit_id = Column(UUID(as_uuid=True), index=True)
105+
activity_id = Column(UUID(as_uuid=True), index=True)
107106
ehr_storage_uri = Column(Text())
108107
ehr_ingestion_status = Column(Text())
109108
meta = Column(JSONB())
110-
111-
__table_args__ = (UniqueConstraint("submit_id", "activity_id", name="answers_ehr_submit_activity_key"),)

src/apps/authentication/db/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TokenBlacklistSchema(Base):
1111
jti = Column(Text(), index=True, unique=True, nullable=False)
1212
user_id = Column(UUID(as_uuid=True), nullable=False)
1313
exp = Column(DateTime(), index=True, nullable=False)
14-
type = Column(Enum(TokenPurpose, name="token_purpose"), nullable=False)
14+
type = Column(Enum(TokenPurpose), nullable=False)
1515
rjti = Column(Text(), index=True, nullable=True)
1616

1717

src/apps/schedule/db/schemas.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ class _BaseEventSchema:
1616
timer_type = Column(String(10), nullable=False) # NOT_SET, TIMER, IDLE
1717
version = Column(
1818
String(13),
19-
nullable=False,
2019
default=lambda: datetime.datetime.now(datetime.UTC).strftime("%Y%m%d") + "-1",
2120
server_default=text("TO_CHAR(timezone('utc', now()), 'YYYYMMDD') || '-1'"),
2221
)
2322

2423
# Periodicity columns
25-
periodicity = Column(String(10), nullable=False) # Options: ONCE, DAILY, WEEKLY, WEEKDAYS, MONTHLY, ALWAYS
24+
periodicity = Column(String(10)) # Options: ONCE, DAILY, WEEKLY, WEEKDAYS, MONTHLY, ALWAYS
2625
start_date = Column(Date, nullable=True)
2726
end_date = Column(Date, nullable=True)
2827
selected_date = Column(Date, nullable=True)
@@ -51,7 +50,7 @@ class AppletEventsSchema(Base):
5150
__tablename__ = "applet_events"
5251

5352
applet_id = Column(ForeignKey("applet_histories.id_version", ondelete="CASCADE"), nullable=False)
54-
event_id = Column(ForeignKey("event_histories.id_version", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)
53+
event_id = Column(ForeignKey("event_histories.id_version", ondelete="CASCADE"), nullable=False)
5554

5655
__table_args__ = (
5756
UniqueConstraint(
@@ -74,15 +73,15 @@ class _BaseNotificationSchema:
7473
class NotificationSchema(_BaseNotificationSchema, Base):
7574
__tablename__ = "notifications"
7675

77-
event_id = Column(ForeignKey("events.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)
76+
event_id = Column(ForeignKey("events.id", ondelete="CASCADE"), nullable=False)
7877

7978

8079
class NotificationHistorySchema(_BaseNotificationSchema, HistoryAware, Base):
8180
__tablename__ = "notification_histories"
8281

8382
id_version = Column(String(), primary_key=True)
8483
id = Column(UUID(as_uuid=True))
85-
event_id = Column(ForeignKey("event_histories.id_version", ondelete="RESTRICT", onupdate="CASCADE"), nullable=False)
84+
event_id = Column(ForeignKey("event_histories.id_version", ondelete="RESTRICT"), nullable=False)
8685

8786

8887
class _BaseReminderSchema:
@@ -93,15 +92,15 @@ class _BaseReminderSchema:
9392
class ReminderSchema(_BaseReminderSchema, Base):
9493
__tablename__ = "reminders"
9594

96-
event_id = Column(ForeignKey("events.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)
95+
event_id = Column(ForeignKey("events.id", ondelete="CASCADE"), nullable=False)
9796

9897

9998
class ReminderHistorySchema(_BaseReminderSchema, HistoryAware, Base):
10099
__tablename__ = "reminder_histories"
101100

102101
id_version = Column(String(), primary_key=True)
103102
id = Column(UUID(as_uuid=True))
104-
event_id = Column(ForeignKey("event_histories.id_version", ondelete="RESTRICT", onupdate="CASCADE"), nullable=False)
103+
event_id = Column(ForeignKey("event_histories.id_version", ondelete="RESTRICT"), nullable=False)
105104

106105

107106
class UserDeviceEventsHistorySchema(Base):

src/apps/subjects/db/schemas.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sqlalchemy import Boolean, Column, ForeignKey, Index, String, Unicode
1+
from sqlalchemy import Column, ForeignKey, Index, String, Unicode
22
from sqlalchemy.dialects.postgresql import JSONB
33
from sqlalchemy_utils import StringEncryptedType
44

@@ -10,7 +10,6 @@
1010

1111
class SubjectSchema(Base):
1212
__tablename__ = "subjects"
13-
is_deleted = Column(Boolean(), nullable=False, default=False)
1413
applet_id = Column(ForeignKey("applets.id", ondelete="RESTRICT"), nullable=False)
1514
creator_id = Column(ForeignKey("users.id", ondelete="RESTRICT"), nullable=False)
1615
user_id = Column(ForeignKey("users.id", ondelete="RESTRICT"), nullable=True)
@@ -20,25 +19,29 @@ class SubjectSchema(Base):
2019
nickname = Column(StringEncryptedType(Unicode, get_key), default=None, nullable=True)
2120
tag = Column(String, default=None, nullable=True)
2221
secret_user_id = Column(String, nullable=False)
23-
language = Column(String(length=20))
22+
language = Column(String(length=5))
2423
integration_source = Column(String(length=20), nullable=True, default=None)
2524
meta = Column(JSONB(), nullable=True)
2625

2726
__table_args__ = (
28-
Index(None, "user_id", "applet_id", unique=True),
29-
Index("idx_subjects_meta", "meta", postgresql_using="gin"),
27+
Index(
28+
None,
29+
"user_id",
30+
"applet_id",
31+
unique=True,
32+
),
3033
)
3134

3235

3336
class SubjectRelationSchema(Base):
3437
__tablename__ = "subject_relations"
3538
source_subject_id = Column(
36-
ForeignKey("subjects.id", ondelete="RESTRICT", onupdate="CASCADE"),
39+
ForeignKey("subjects.id", ondelete="RESTRICT"),
3740
nullable=False,
3841
index=True,
3942
)
4043
target_subject_id = Column(
41-
ForeignKey("subjects.id", ondelete="RESTRICT", onupdate="CASCADE"),
44+
ForeignKey("subjects.id", ondelete="RESTRICT"),
4245
nullable=False,
4346
index=True,
4447
)

src/apps/users/db/schemas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
class UserSchema(Base):
1212
__tablename__ = "users"
1313

14-
email = Column(String(length=100), unique=True)
14+
email = Column(String(length=56), unique=True)
1515
email_encrypted = Column(StringEncryptedType(Unicode, get_key), default=None)
1616
first_name = Column(StringEncryptedType(Unicode, get_key))
1717
last_name = Column(StringEncryptedType(Unicode, get_key))
1818
hashed_password = Column(String(length=100))
1919
last_seen_at = Column(DateTime(), default=lambda: datetime.now(timezone.utc).replace(tzinfo=None))
2020
is_super_admin = Column(Boolean(), default=False, server_default="false")
21-
mfa_enabled = Column(Boolean(), nullable=False, default=False, server_default="false")
21+
mfa_enabled = Column(Boolean(), default=False, server_default="false")
2222
mfa_secret = Column(Text(), nullable=True) # Changed from String(100) to Text() for encrypted values
2323
pending_mfa_secret = Column(Text(), nullable=True)
2424
pending_mfa_created_at = Column(DateTime(), nullable=True)

src/apps/workspaces/db/schemas/user_applet_access.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ class UserPinSchema(Base):
111111

112112
user_id = Column(ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
113113
pinned_user_id = Column(ForeignKey("users.id", ondelete="CASCADE"), nullable=True)
114-
pinned_subject_id = Column(ForeignKey("subjects.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=True)
114+
pinned_subject_id = Column(ForeignKey("subjects.id", ondelete="CASCADE"), nullable=True)
115115
owner_id = Column(ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
116116
role = Column(Enum(UserPinRole, name="user_pin_role"), nullable=False)

src/config/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ def uploads_dir(self):
121121
"applets",
122122
"activities",
123123
"activity_flows",
124-
"activity_assignments",
125124
"themes",
126125
"logs",
127126
"schedule",
128127
"answers",
129128
"folders",
129+
"answers",
130130
"invitations",
131131
"workspaces",
132132
"transfer_ownership",
@@ -136,7 +136,6 @@ def uploads_dir(self):
136136
"job",
137137
"subjects",
138138
"integrations",
139-
"integrations.loris",
140139
],
141140
)
142141

src/infrastructure/database/migrations/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
Import all SQLAlchemy models here
88
"""
99

10+
import os
11+
1012
from config import settings
1113
from infrastructure.database import Base # noqa: F401, F403
1214

@@ -16,7 +18,10 @@ def import_db_schemas():
1618
of database schemas that are used by SQLAlchemy.
1719
"""
1820

19-
for app in settings.migrations_apps:
21+
for app in os.listdir(settings.apps_dir):
22+
if app not in settings.migrations_apps:
23+
continue
24+
2025
__import__(f"apps.{app}.db.schemas")
2126

2227

0 commit comments

Comments
 (0)