Skip to content

Conversation

@markstory
Copy link
Member

Add date_updated to organizationmapping. Synapse will need a way to fetch records that have changed since it last synced.

Refs INFRENG-172

Add date_updated to organizationmapping. Synapse will need a way to
fetch records that have changed since it last synced.

Refs INFRENG-172
@markstory markstory requested a review from a team as a code owner November 20, 2025 21:32
@linear
Copy link

linear bot commented Nov 20, 2025

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 20, 2025
@markstory markstory requested a review from a team November 20, 2025 21:33
prevent_superuser_access = models.BooleanField(default=False, db_default=False)
disable_member_invite = models.BooleanField(default=False, db_default=False)

date_updated = models.DateTimeField(db_default=Now(), default=timezone.now)

This comment was marked as outdated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's right here, if you want this to always be updated it's better to use auto_now=True

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a mistake in DefaultFieldsModelExisting then? That class defines date_updated as

date_updated = models.DateTimeField(default=timezone.now)

prevent_superuser_access = models.BooleanField(default=False, db_default=False)
disable_member_invite = models.BooleanField(default=False, db_default=False)

date_updated = models.DateTimeField(db_default=Now(), default=timezone.now)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing index on date_updated

The date_updated field is intended to be used for fetching changed records (synchronization). Since OrganizationMapping is a high-volume table, querying by this field without a database index will result in full table scans and potential performance degradation.

Fix in Cursor Fix in Web

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're planning on querying this you do need an index, but I'm not sure what your patterns look like

@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

This PR has a migration; here is the generated SQL for src/sentry/migrations/1008_add_date_updated_to_organizationmapping.py

for 1008_add_date_updated_to_organizationmapping in sentry

--
-- Add field date_updated to organizationmapping
--
ALTER TABLE "sentry_organizationmapping" ADD COLUMN "date_updated" timestamp with time zone DEFAULT (STATEMENT_TIMESTAMP()) NOT NULL;
CREATE INDEX CONCURRENTLY "sentry_organizationmapping_date_updated_cb5e0369" ON "sentry_organizationmapping" ("date_updated");

prevent_superuser_access = models.BooleanField(default=False, db_default=False)
disable_member_invite = models.BooleanField(default=False, db_default=False)

date_updated = models.DateTimeField(db_default=Now(), default=timezone.now)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's right here, if you want this to always be updated it's better to use auto_now=True

prevent_superuser_access = models.BooleanField(default=False, db_default=False)
disable_member_invite = models.BooleanField(default=False, db_default=False)

date_updated = models.DateTimeField(db_default=Now(), default=timezone.now)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want all existing rows to be set to have been updated at the time this migration ran? It's fine if you do, just making sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want all existing rows to be set to have been updated at the time this migration ran?

Yes, that's fine. This column will be out for a few weeks/months before we start using it.

prevent_superuser_access = models.BooleanField(default=False, db_default=False)
disable_member_invite = models.BooleanField(default=False, db_default=False)

date_updated = models.DateTimeField(db_default=Now(), default=timezone.now)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're planning on querying this you do need an index, but I'm not sure what your patterns look like

@markstory markstory requested a review from wedamija November 21, 2025 21:33
@markstory markstory merged commit 71e4553 into master Nov 24, 2025
68 checks passed
@markstory markstory deleted the feat-add-updatedat-organziation-mapping branch November 24, 2025 16:07
@markstory markstory added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Nov 24, 2025
@getsentry-bot
Copy link
Contributor

PR reverted: 94e744c

getsentry-bot added a commit that referenced this pull request Nov 24, 2025
This reverts commit 71e4553.

Co-authored-by: markstory <24086+markstory@users.noreply.github.com>
markstory added a commit that referenced this pull request Nov 24, 2025
Redo this change as it was reverted due to gaps in the control silo
deployment pipeline that didn't run migrations. This migration will have
run in development environment, and once the control silo migration
pipeline is fixed, I'll get a new migration number and use
a `SeparateDatabaseAndState` migration to handle this scenario.

Reapply "feat(cells) Add date_updated to organizationmapping (#103772)"

This reverts commit 94e744c.

Refs INFRENG-172
markstory added a commit that referenced this pull request Nov 26, 2025
Redo this change as it was reverted due to gaps in the control silo
deployment pipeline that didn't run migrations. This migration will have
run in development environment, and once the control silo migration
pipeline is fixed, I'll get a new migration number and use
a `SeparateDatabaseAndState` migration to handle this scenario.

Reapply "feat(cells) Add date_updated to organizationmapping (#103772)"

This reverts commit 94e744c.

Refs INFRENG-172
markstory added a commit that referenced this pull request Nov 28, 2025
Redo this change as it was reverted due to gaps in the control silo
deployment pipeline that didn't run migrations. This migration will have
run in development environment, and once the control silo migration
pipeline is fixed, I'll get a new migration number and use a
`SeparateDatabaseAndState` migration to handle this scenario.

Reapply "feat(cells) Add date_updated to organizationmapping (#103772)"

This reverts commit 94e744c.

Refs INFRENG-172
roaga pushed a commit that referenced this pull request Dec 2, 2025
Redo this change as it was reverted due to gaps in the control silo
deployment pipeline that didn't run migrations. This migration will have
run in development environment, and once the control silo migration
pipeline is fixed, I'll get a new migration number and use a
`SeparateDatabaseAndState` migration to handle this scenario.

Reapply "feat(cells) Add date_updated to organizationmapping (#103772)"

This reverts commit 94e744c.

Refs INFRENG-172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert Add to a merged PR to revert it (skips CI)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants