Skip to content

Commit 1a1988f

Browse files
authored
[Issue #6951] Create table for capturing ignored legacy org user (#7051)
## Summary <!-- Use "Fixes" to automatically close issue upon PR merge. Use "Work for" when UAT is required. --> Fixes for #6951 ## Changes proposed Model and factory created for table `ignored_legacy_organization_user` Migration file created
1 parent 8780c47 commit 1a1988f

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"""add_ignored_legacy_organization_user_table
2+
3+
Revision ID: 19e80334aaae
4+
Revises: df81941231ad
5+
Create Date: 2025-11-13 21:16:33.936592
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "19e80334aaae"
14+
down_revision = "df81941231ad"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table(
22+
"ignored_legacy_organization_user",
23+
sa.Column("ignored_legacy_organization_user_id", sa.UUID(), nullable=False),
24+
sa.Column("organization_id", sa.UUID(), nullable=False),
25+
sa.Column("email", sa.Text(), nullable=False),
26+
sa.Column("ignored_by_user_id", sa.UUID(), nullable=False),
27+
sa.Column(
28+
"created_at",
29+
sa.TIMESTAMP(timezone=True),
30+
server_default=sa.text("now()"),
31+
nullable=False,
32+
),
33+
sa.Column(
34+
"updated_at",
35+
sa.TIMESTAMP(timezone=True),
36+
server_default=sa.text("now()"),
37+
nullable=False,
38+
),
39+
sa.ForeignKeyConstraint(
40+
["ignored_by_user_id"],
41+
["api.user.user_id"],
42+
name=op.f("ignored_legacy_organization_user_ignored_by_user_id_user_fkey"),
43+
),
44+
sa.ForeignKeyConstraint(
45+
["organization_id"],
46+
["api.organization.organization_id"],
47+
name=op.f("ignored_legacy_organization_user_organization_id_organization_fkey"),
48+
),
49+
sa.PrimaryKeyConstraint(
50+
"ignored_legacy_organization_user_id",
51+
name=op.f("ignored_legacy_organization_user_pkey"),
52+
),
53+
sa.UniqueConstraint(
54+
"organization_id",
55+
"email",
56+
name=op.f("ignored_legacy_organization_user_organization_id_uniq"),
57+
),
58+
schema="api",
59+
)
60+
op.create_index(
61+
op.f("ignored_legacy_organization_user_email_idx"),
62+
"ignored_legacy_organization_user",
63+
["email"],
64+
unique=False,
65+
schema="api",
66+
)
67+
op.create_index(
68+
op.f("ignored_legacy_organization_user_ignored_by_user_id_idx"),
69+
"ignored_legacy_organization_user",
70+
["ignored_by_user_id"],
71+
unique=False,
72+
schema="api",
73+
)
74+
# ### end Alembic commands ###
75+
76+
77+
def downgrade():
78+
# ### commands auto generated by Alembic - please adjust! ###
79+
op.drop_index(
80+
op.f("ignored_legacy_organization_user_ignored_by_user_id_idx"),
81+
table_name="ignored_legacy_organization_user",
82+
schema="api",
83+
)
84+
op.drop_index(
85+
op.f("ignored_legacy_organization_user_email_idx"),
86+
table_name="ignored_legacy_organization_user",
87+
schema="api",
88+
)
89+
op.drop_table("ignored_legacy_organization_user", schema="api")
90+
# ### end Alembic commands ###

api/src/db/models/entity_models.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import date, datetime
33
from typing import TYPE_CHECKING
44

5-
from sqlalchemy import ForeignKey
5+
from sqlalchemy import ForeignKey, UniqueConstraint
66
from sqlalchemy.dialects.postgresql import UUID
77
from sqlalchemy.orm import Mapped, mapped_column, relationship
88

@@ -172,3 +172,23 @@ class LinkOrganizationInvitationToRole(ApiSchemaTable, TimestampMixin):
172172
ForeignKey(OrganizationInvitation.organization_invitation_id), primary_key=True
173173
)
174174
organization_invitation: Mapped[OrganizationInvitation] = relationship(OrganizationInvitation)
175+
176+
177+
class IgnoredLegacyOrganizationUser(ApiSchemaTable, TimestampMixin):
178+
__tablename__ = "ignored_legacy_organization_user"
179+
__table_args__ = (
180+
# We want a unique constraint to prevent duplicate hide records for an organization
181+
UniqueConstraint("organization_id", "email"),
182+
# Need to define the table args like this to inherit whatever we set on the super table
183+
# otherwise we end up overwriting things and Alembic remakes the whole table
184+
ApiSchemaTable.__table_args__,
185+
)
186+
187+
ignored_legacy_organization_user_id: Mapped[uuid.UUID] = mapped_column(primary_key=True)
188+
organization_id: Mapped[uuid.UUID] = mapped_column(ForeignKey(Organization.organization_id))
189+
organization: Mapped["Organization"] = relationship(Organization)
190+
email: Mapped[str] = mapped_column(index=True)
191+
ignored_by_user_id: Mapped[uuid.UUID] = mapped_column(
192+
ForeignKey("api.user.user_id"), index=True
193+
)
194+
user: Mapped["User"] = relationship("User")

api/tests/src/db/models/factories.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,18 @@ class Meta:
30913091
)
30923092

30933093

3094+
class IgnoredLegacyOrganizationUserFactory(BaseFactory):
3095+
class Meta:
3096+
model = entity_models.IgnoredLegacyOrganizationUser
3097+
3098+
ignored_legacy_organization_user_id = Generators.UuidObj
3099+
organization = factory.SubFactory(OrganizationFactory)
3100+
organization_id = factory.LazyAttribute(lambda o: o.organization.organization_id)
3101+
email = factory.Faker("email")
3102+
user = factory.SubFactory(UserFactory)
3103+
ignored_by_user_id = factory.LazyAttribute(lambda o: o.user.user_id)
3104+
3105+
30943106
class SuppressedEmailFactory(BaseFactory):
30953107
class Meta:
30963108
model = user_models.SuppressedEmail

0 commit comments

Comments
 (0)