Skip to content

migration and docker lintin fixed#179

Merged
A1L13N merged 5 commits into
alphaonelabs:mainfrom
sayanoops:new
Mar 21, 2025
Merged

migration and docker lintin fixed#179
A1L13N merged 5 commits into
alphaonelabs:mainfrom
sayanoops:new

Conversation

@sayanoops
Copy link
Copy Markdown
Contributor

@sayanoops sayanoops commented Mar 21, 2025

Summary by CodeRabbit

  • Chores
    • Enhanced our account registration process by streamlining email uniqueness enforcement. This update simplifies the handling of email addresses, ensuring greater compatibility across environments and reducing potential sign-up issues. Users should experience a smoother registration process with improved reliability, helping to maintain a consistent and error-free experience during account creation and ongoing account management.
  • Style
    • Improved readability of workflow files through cosmetic adjustments.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 21, 2025

Walkthrough

This 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

File Change Summary
.github/workflows/docker-test.yml Adjusted whitespace for enhanced readability; no changes to the workflow's logic or functionality.
web/migrations/0002_add_unique_email_constraint.py Improved duplicate email handling by adding functions for deduplication and unique constraint management, replacing raw SQL with a Pythonic approach.

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
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Mar 21, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8dea282 and ca46583.

📒 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.

Comment thread web/migrations/0002_add_unique_email_constraint.py Outdated
Comment thread web/migrations/0002_add_unique_email_constraint.py
coderabbitai[bot]
coderabbitai Bot previously approved these changes Mar 21, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f3d9df and 043b52a.

📒 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.

@A1L13N A1L13N merged commit 210f550 into alphaonelabs:main Mar 21, 2025
@sayanoops sayanoops deleted the new branch March 21, 2025 16:26
sudhirKsah pushed a commit to sudhirKsah/alphaonelabs-education-website that referenced this pull request Mar 21, 2025
* migration and docker lintin fixed

* fixing

* fixing

* Update 0002_add_unique_email_constraint.py

---------

Co-authored-by: A1L13N <193832434+A1L13N@users.noreply.github.com>
A1L13N added a commit that referenced this pull request Mar 25, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants