Skip to content

Commit 7cd50dd

Browse files
committed
Add client_id column to user submitted data.
1 parent 9bc0a5f commit 7cd50dd

File tree

5 files changed

+90
-2
lines changed

5 files changed

+90
-2
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
33
/// <reference types="next/navigation-types/compat/navigation" />
4-
/// <reference path="./.next/types/routes.d.ts" />
54

65
// NOTE: This file should not be edited
76
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""add client id columns to user submitted data
2+
3+
Revision ID: d76443a8a2e3
4+
Revises: d4e6f8a0b2c3
5+
Create Date: 2026-04-09 08:38:43.724458
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'd76443a8a2e3'
14+
down_revision = 'd4e6f8a0b2c3'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
op.add_column(
21+
"comment",
22+
sa.Column(
23+
"client_id",
24+
sa.String(),
25+
sa.ForeignKey("client.id", ondelete="SET NULL"),
26+
nullable=True,
27+
),
28+
)
29+
op.add_column(
30+
"attachment",
31+
sa.Column(
32+
"client_id",
33+
sa.String(),
34+
sa.ForeignKey("client.id", ondelete="SET NULL"),
35+
nullable=True,
36+
),
37+
)
38+
op.add_column(
39+
"event_audit",
40+
sa.Column(
41+
"client_id",
42+
sa.String(),
43+
sa.ForeignKey("client.id", ondelete="SET NULL"),
44+
nullable=True,
45+
),
46+
)
47+
48+
49+
def downgrade():
50+
op.drop_column("event_audit", "client_id")
51+
op.drop_column("attachment", "client_id")
52+
op.drop_column("comment", "client_id")

src/fides/api/models/attachment.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from fides.api.service.storage.util import AllowedFileType
2121

2222
if TYPE_CHECKING:
23+
from fides.api.models.client import ClientDetail
2324
from fides.api.models.comment import Comment
2425
from fides.api.models.fides_user import FidesUser
2526
from fides.api.models.privacy_request import PrivacyRequest
@@ -104,6 +105,9 @@ class Attachment(Base):
104105
user_id = Column(
105106
String, ForeignKey("fidesuser.id", ondelete="SET NULL"), nullable=True
106107
)
108+
client_id = Column(
109+
String, ForeignKey("client.id", ondelete="SET NULL"), nullable=True
110+
)
107111
# Not all users in the system have a username, and users can be deleted.
108112
# Store a non-normalized copy of username for these cases.
109113
username = Column(String, nullable=True)
@@ -118,6 +122,13 @@ class Attachment(Base):
118122
lazy="selectin",
119123
uselist=False,
120124
)
125+
client: "ClientDetail" = relationship(
126+
"ClientDetail",
127+
lazy="selectin",
128+
uselist=False,
129+
foreign_keys=[client_id],
130+
primaryjoin="Attachment.client_id == ClientDetail.id",
131+
)
121132

122133
references = relationship(
123134
"AttachmentReference",

src/fides/api/models/comment.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
if TYPE_CHECKING:
1414
from fides.api.models.attachment import Attachment, AttachmentReference
15+
from fides.api.models.client import ClientDetail
1516
from fides.api.models.fides_user import FidesUser
1617
from fides.api.models.privacy_request import PrivacyRequest
1718

@@ -96,6 +97,9 @@ class Comment(Base):
9697
user_id = Column(
9798
String, ForeignKey("fidesuser.id", ondelete="SET NULL"), nullable=True
9899
)
100+
client_id = Column(
101+
String, ForeignKey("client.id", ondelete="SET NULL"), nullable=True
102+
)
99103
# Not all users in the system have a username, and users can be deleted.
100104
# Store a non-normalized copy of username for these cases.
101105
username = Column(String, nullable=True)
@@ -107,6 +111,13 @@ class Comment(Base):
107111
lazy="selectin",
108112
uselist=False,
109113
)
114+
client: "ClientDetail" = relationship(
115+
"ClientDetail",
116+
lazy="selectin",
117+
uselist=False,
118+
foreign_keys=[client_id],
119+
primaryjoin="Comment.client_id == ClientDetail.id",
120+
)
110121

111122
references = relationship(
112123
"CommentReference",

src/fides/api/models/event_audit.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
"""EventAudit model and related enums for comprehensive audit logging."""
22

33
from enum import Enum as EnumType
4+
from typing import TYPE_CHECKING
45

5-
from sqlalchemy import Column, String, Text
6+
from sqlalchemy import Column, ForeignKey, String, Text
67
from sqlalchemy.dialects.postgresql import JSONB
78
from sqlalchemy.ext.declarative import declared_attr
9+
from sqlalchemy.orm import relationship
810

911
from fides.api.db.base_class import Base
1012
from fides.api.db.util import EnumColumn
1113

14+
if TYPE_CHECKING:
15+
from fides.api.models.client import ClientDetail
16+
1217

1318
class EventAuditType(str, EnumType):
1419
"""Hierarchical event types for audit logging - variable depth as needed."""
@@ -85,6 +90,16 @@ def __tablename__(cls) -> str:
8590
# Uses EventAuditType values but left as String to avoid future migrations
8691
event_type = Column(String, index=True, nullable=False)
8792
user_id = Column(String, nullable=True, index=True)
93+
client_id = Column(
94+
String, ForeignKey("client.id", ondelete="SET NULL"), nullable=True, index=True
95+
)
96+
client: "ClientDetail" = relationship(
97+
"ClientDetail",
98+
lazy="selectin",
99+
uselist=False,
100+
foreign_keys=[client_id],
101+
primaryjoin="EventAudit.client_id == ClientDetail.id",
102+
)
88103

89104
# Resource information
90105
resource_type = Column(String, nullable=True, index=True)

0 commit comments

Comments
 (0)