migration and docker lintin fixed#179
Conversation
WalkthroughThis pull request includes two sets of changes. The first involves cosmetic modifications—adding and removing blank lines—in the GitHub Actions workflow file to improve readability without altering functionality. The second set updates a database migration for handling duplicate emails by replacing a SQL-based approach with Python functions for deduplication and encapsulating unique constraint logic in dedicated functions. Changes
Sequence Diagram(s)sequenceDiagram
participant M as Migration Runner
participant S as Migration Script
participant DB as Database
M->>S: Initiate Migration
S->>DB: Update duplicate emails (append user ID)
DB-->>S: Acknowledgment
S->>DB: Execute CREATE UNIQUE INDEX IF NOT EXISTS
DB-->>S: Index created
S-->>M: Migration completed
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
web/migrations/0002_add_unique_email_constraint.py(2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Docker Build & Test
web/migrations/0002_add_unique_email_constraint.py
[error] 42-42: django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS auth_user_email_unique ON auth_user(email)' at line 1")
🪛 GitHub Actions: .github/workflows/test.yml
web/migrations/0002_add_unique_email_constraint.py
[error] 42-42: django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS auth_user_email_unique ON auth_user(email)' at line 1")
🔇 Additional comments (2)
web/migrations/0002_add_unique_email_constraint.py (2)
6-27: Well-implemented email deduplication logic.The Python-based approach for handling duplicate emails is well-structured and more maintainable than using raw SQL. The function correctly identifies duplicates, preserves the first occurrence, and appends user IDs to subsequent occurrences.
60-61: Migration operations look good.The migration correctly runs the functions in the appropriate order: first deduplicating emails, then adding the unique constraint.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
web/migrations/0002_add_unique_email_constraint.py (1)
6-27: Well-implemented email deduplication logic.The function effectively handles duplicate emails by keeping the first occurrence and modifying others with a user ID suffix. This ensures uniqueness before applying the constraint.
Consider batch processing for large datasets:
def deduplicate_emails(apps, schema_editor): """ Handle duplicate emails by appending _id to duplicate entries """ # Get the User model from the migration User = apps.get_model("auth", "User") # Find emails that are duplicated duplicate_emails = ( User.objects.values("email").annotate(count=Count("id")).filter(count__gt=1).values_list("email", flat=True) ) for email in duplicate_emails: # Find all users with this email except the first one users_with_email = User.objects.filter(email=email).order_by("id") first_user = users_with_email.first() + # Process users in batches for better performance with large datasets + users_to_update = [] # Update all other users with this email for user in users_with_email.exclude(id=first_user.id): user.email = f"{user.email}_{user.id}" - user.save() + users_to_update.append(user) + + # Use bulk_update for better performance if there are many users to update + if users_to_update: + User.objects.bulk_update(users_to_update, ['email'])
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
web/migrations/0002_add_unique_email_constraint.py(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build-and-test
- GitHub Check: Run Tests
🔇 Additional comments (3)
web/migrations/0002_add_unique_email_constraint.py (3)
29-56: Proper cross-database handling for index creation.The implementation correctly handles different database engines (SQLite, MySQL, PostgreSQL) with appropriate syntax for each. This addresses the MySQL compatibility issues from previous reviews.
58-81: Consistent approach for constraint removal.The reverse migration function mirrors the add_unique_constraint function with database-specific handling, ensuring proper cleanup when needed.
89-91: Well-ordered migration operations.The operations correctly sequence the migration steps: first deduplicating emails and then adding the unique constraint. The reverse operations are properly configured for rollback.
* migration and docker lintin fixed * fixing * fixing * Update 0002_add_unique_email_constraint.py --------- Co-authored-by: A1L13N <193832434+A1L13N@users.noreply.github.com>
* feat: add progress visualization * chore: update .gitignore * chore: restore venv/ in .gitignore as per review * fix: resolved linting and formatting issues * fix: djLint issues * fix: corrected jsPDF setFillColor to handle RGB values properly * Update .pre-commit-config.yaml * feat(admin): add email verification filter and display in user admin * fix(cart, payment, student_progress): capture exceptions and improve error messages for payment and progress handling * feat(enrollment): implement automatic approval for free course enrollments and update payment handling * feat(enrollment, UI): enhance free course enrollment process and update course price display * refactor(courses, templates): consolidate session forms into a single template and update rendering logic * feat(security, video-fetch): implement URL validation and security measures to prevent SSRF attacks in video title fetching * Update test.yml * Update test.yml * feature of Team Collaboration (#94) * basemodels * Reset views.py to original state * file-structure-optimising * errors * error in invite accepting * added option to mark contribution * added display of teams from homepage * Update web/templates/teams/create.html Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update web/templates/teams/detail.html Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update web/views.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Fix: Remove trailing whitespace in HTML files Co-Authored-By: Ishaan Arora <ishaana612@gmail.com> * Fix: Remove trailing whitespace and add newlines at end of files Co-Authored-By: Ishaan Arora <ishaana612@gmail.com> * prechanges * added delete functionality * added edit goal and delete goal * pre * rabbit * pree * added notifications * ui improvements * added try,excepts for optimisation * added deadline time verification * added transaction for data integrity * linting * put back sendgrid * addedpagination * rabbit * pre * Update web/email_backend.py Co-authored-by: A1L13N <193832434+A1L13N@users.noreply.github.com> * added small ui change * error handling * errors * lint --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: A1L13N <193832434+A1L13N@users.noreply.github.com> * Revert "feature of Team Collaboration (#94)" (#170) This reverts commit 2f33bea. * Update test.yml * Update test.yml * Update test.yml * Update test.yml * Update test.yml * Update 0002_add_unique_email_constraint.py (#173) * Update 0002_add_unique_email_constraint.py * Update 0002_add_unique_email_constraint.py * Update docker-test.yml * Update docker-test.yml * Update docker-test.yml * Create pre-commit.yml * Update pre-commit.yml * migration and docker lintin fixed (#179) * migration and docker lintin fixed * fixing * fixing * Update 0002_add_unique_email_constraint.py --------- Co-authored-by: A1L13N <193832434+A1L13N@users.noreply.github.com> * fix: moved script into js file to fix djlint issues * chore: update .gitignore * fix: resolved linting and formatting issues * fix: djLint issues * Update 0002_add_unique_email_constraint.py * refactor: removed duplicate progress_visualization function from views.py * Update .pre-commit-config.yaml * test: add test and docstrings for progress_visualization view * Refactor progress visualization with helper functions and caching and modify test accordingly * fix: fix indentation in test and potential division by zero * Fix: guard against invalid session time and fix download button * resolve merge conflict and implement dynamic caching * docs: Added docstrings to web/signals.py --------- Co-authored-by: A1L13N <193832434+A1L13N@users.noreply.github.com> Co-authored-by: Ishaan Arora <178517080+ishaan-arora-1@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Sayan <108164359+sayanoops@users.noreply.github.com>
Summary by CodeRabbit