From 7997a16591e9114031a15c0cd288cfc4658cf435 Mon Sep 17 00:00:00 2001 From: Johan Castiblanco Date: Thu, 11 Jun 2026 09:04:18 -0500 Subject: [PATCH] feat: rm user foreign key db constraint (cherry picked from commit 797d0be187fdeedc9b4ca56d6d25649f5d65043b) --- .../0002_rm_db_user_foreign_key_constraint.py | 21 +++++++++++++++++++ openedx/core/djangoapps/bookmarks/models.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 openedx/core/djangoapps/bookmarks/migrations/0002_rm_db_user_foreign_key_constraint.py diff --git a/openedx/core/djangoapps/bookmarks/migrations/0002_rm_db_user_foreign_key_constraint.py b/openedx/core/djangoapps/bookmarks/migrations/0002_rm_db_user_foreign_key_constraint.py new file mode 100644 index 000000000000..6e5ac4630550 --- /dev/null +++ b/openedx/core/djangoapps/bookmarks/migrations/0002_rm_db_user_foreign_key_constraint.py @@ -0,0 +1,21 @@ +# Remove User foreign key constraint on bookmarks table. Improves writes performance. + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('bookmarks', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='bookmark', + name='user', + field=models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/openedx/core/djangoapps/bookmarks/models.py b/openedx/core/djangoapps/bookmarks/models.py index e83902c1a13f..306fc2fbccad 100644 --- a/openedx/core/djangoapps/bookmarks/models.py +++ b/openedx/core/djangoapps/bookmarks/models.py @@ -46,7 +46,7 @@ class Bookmark(TimeStampedModel): .. no_pii: """ - user = models.ForeignKey(User, db_index=True, on_delete=models.CASCADE) + user = models.ForeignKey(User, db_index=True, on_delete=models.CASCADE, db_constraint=False) course_key = CourseKeyField(max_length=255, db_index=True) usage_key = UsageKeyField(max_length=255, db_index=True) _path = JSONField(db_column='path', help_text='Path in course tree to the block')