-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migrations(shared-views): Create groupsearchviewlastvisited
table
#86241
Open
MichaelSun48
wants to merge
5
commits into
master
Choose a base branch
from
msun/sharedViews/createLastSeenTable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e17863e
Add groupsearchviewlastseen table
MichaelSun48 3974fa3
Remove last_seen from constraint
MichaelSun48 37dfd52
use defaultfieldsmodel. Rename to last_visited for consistency
MichaelSun48 3df0163
Regenereate migration file
MichaelSun48 7ce9b59
Update comparators
MichaelSun48 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/sentry/migrations/0837_create_groupsearchviewlastseen_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Generated by Django 5.1.5 on 2025-03-04 00:01 | ||
|
||
import django.db.models.deletion | ||
import django.utils.timezone | ||
from django.db import migrations, models | ||
|
||
import sentry.db.models.fields.bounded | ||
import sentry.db.models.fields.foreignkey | ||
import sentry.db.models.fields.hybrid_cloud_foreign_key | ||
from sentry.new_migrations.migrations import CheckedMigration | ||
|
||
|
||
class Migration(CheckedMigration): | ||
# This flag is used to mark that a migration shouldn't be automatically run in production. | ||
# This should only be used for operations where it's safe to run the migration after your | ||
# code has deployed. So this should not be used for most operations that alter the schema | ||
# of a table. | ||
# Here are some things that make sense to mark as post deployment: | ||
# - Large data migrations. Typically we want these to be run manually so that they can be | ||
# monitored and not block the deploy for a long period of time while they run. | ||
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to | ||
# run this outside deployments so that we don't block them. Note that while adding an index | ||
# is a schema change, it's completely safe to run the operation after the code has deployed. | ||
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment | ||
|
||
is_post_deployment = False | ||
|
||
dependencies = [ | ||
("sentry", "0836_create_groupsearchviewstarred_table"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="GroupSearchViewLastVisited", | ||
fields=[ | ||
( | ||
"id", | ||
sentry.db.models.fields.bounded.BoundedBigAutoField( | ||
primary_key=True, serialize=False | ||
), | ||
), | ||
("date_updated", models.DateTimeField(auto_now=True)), | ||
("date_added", models.DateTimeField(auto_now_add=True)), | ||
( | ||
"user_id", | ||
sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey( | ||
"sentry.User", db_index=True, on_delete="CASCADE" | ||
), | ||
), | ||
("last_visited", models.DateTimeField(default=django.utils.timezone.now)), | ||
( | ||
"group_search_view", | ||
sentry.db.models.fields.foreignkey.FlexibleForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="sentry.groupsearchview" | ||
), | ||
), | ||
( | ||
"organization", | ||
sentry.db.models.fields.foreignkey.FlexibleForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="sentry.organization" | ||
), | ||
), | ||
], | ||
options={ | ||
"db_table": "sentry_groupsearchviewlastvisited", | ||
"constraints": [ | ||
models.UniqueConstraint( | ||
fields=("user_id", "organization_id", "group_search_view_id"), | ||
name="sentry_groupsearchviewlastvisited_unique_last_visited_per_org_user_view", | ||
) | ||
], | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.db import models | ||
from django.db.models import UniqueConstraint | ||
from django.utils import timezone | ||
|
||
from sentry.backup.scopes import RelocationScope | ||
from sentry.db.models import FlexibleForeignKey, region_silo_model | ||
from sentry.db.models.base import DefaultFieldsModel | ||
from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey | ||
|
||
|
||
@region_silo_model | ||
class GroupSearchViewLastVisited(DefaultFieldsModel): | ||
__relocation_scope__ = RelocationScope.Organization | ||
|
||
user_id = HybridCloudForeignKey("sentry.User", on_delete="CASCADE") | ||
organization = FlexibleForeignKey("sentry.Organization") | ||
group_search_view = FlexibleForeignKey("sentry.GroupSearchView") | ||
|
||
last_visited = models.DateTimeField(null=False, default=timezone.now) | ||
|
||
class Meta: | ||
app_label = "sentry" | ||
db_table = "sentry_groupsearchviewlastvisited" | ||
constraints = [ | ||
UniqueConstraint( | ||
fields=["user_id", "organization_id", "group_search_view_id"], | ||
name="sentry_groupsearchviewlastvisited_unique_last_visited_per_org_user_view", | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jfyi: Since these are fks, you can refer to the column name vs the id, so
organization
instead oforganization_id
.You don't need to change it, both are fine.