Skip to content
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

Drop unused columns and tables in database #2750

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

skwowet
Copy link
Member

@skwowet skwowet commented Jan 9, 2025

Changes proposed ✍️

What

copilot:summary

copilot:poem

Why

How

copilot:walkthrough

Summary by CodeRabbit

  • Database Cleanup
    • Removed multiple unused tables, including tasks, notes, microservices, and backup tables
    • Dropped numerous obsolete columns from the organizations table
    • Performed database optimization to remove legacy data structures

@skwowet skwowet self-assigned this Jan 9, 2025
Copy link

coderabbitai bot commented Jan 9, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This migration script performs a comprehensive database cleanup by removing multiple unused tables and obsolete columns from the organizations table. The goal is to optimize the database structure by eliminating legacy data structures that are no longer in use, potentially improving database performance and reducing storage overhead.

Changes

File Change Summary
backend/src/database/migrations/V1736414839__cleanupUnusedTablesAndColumns.sql - Dropped 19 unused tables including tasks, taskAssignees, microservices, automations, etc.
- Removed 30 obsolete columns from organizations table related to old metadata, profiles, and historical data

Poem

🐰 Database Cleanup Hop! 🧹

Tables vanish like morning dew,
Columns drop, our database anew
Legacy data takes its final bow
Clean and swift, we optimize now!
Rabbit's code, lean and bright ✨


🪧 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. (Beta)
  • @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.

Copy link

@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)
backend/src/database/migrations/V1736414839__cleanupUnusedTablesAndColumns.sql (1)

1-52: Consider adding a rollback strategy

This is a significant database cleanup. Consider:

  1. Creating a rollback migration script
  2. Taking a database backup before applying
  3. Testing the migration in a staging environment first
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b7ce44b and 15a158c.

📒 Files selected for processing (1)
  • backend/src/database/migrations/V1736414839__cleanupUnusedTablesAndColumns.sql (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-format-services
  • GitHub Check: lint-format
🔇 Additional comments (3)
backend/src/database/migrations/V1736414839__cleanupUnusedTablesAndColumns.sql (3)

12-20: Verify backup retention requirements

These backup tables are being dropped. Please confirm:

  1. The data in these backup tables is no longer needed
  2. This action complies with your data retention policies
  3. You have recent database backups before proceeding

1-10: Verify that core feature tables are safe to drop

These tables appear to be related to core features (tasks, notes, automations). Before proceeding:

  1. Confirm there are no foreign key constraints that could break
  2. Verify that related features are completely deprecated
  3. Ensure no application code still references these tables

22-52: Verify data migration for organization columns

You're dropping 31 columns from the organizations table. While the 'old_' prefix suggests these are deprecated, please verify:

  1. All necessary data has been migrated to new columns
  2. No application code or queries still reference these columns
  3. Reports or analytics aren't dependent on this data
✅ Verification successful

Migration pattern verified - columns safely replaced

The migration follows a safe pattern:

  1. New columns were added first
  2. Original columns were renamed with 'old_' prefix
  3. Old columns are now being cleaned up
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any references to the old columns in application code
echo "Checking for column references in code:"
rg -i "old_(emails|phonenumbers|twitter|linkedin|crunchbase|employeecountbycountry|geolocation|ticker|profiles|address|attributes|affiliatedprofiles|allsubsidiaries|alternativedomains|alternativenames|averageemployeetenure|averagetenurebylevel|averagetenurebyrole|directsubsidiaries|employeecountbymonth|employeecountbymonthbylevel|employeecountbymonthbyrole|gicssector|grossadditionsbymonth|grossdeparturesbymonth|ultimateparent|immediateparent|weakidentities|manuallychangedfields|naics|names)"

Length of output: 9354


Script:

#!/bin/bash
# Check for creation of new columns in migrations between the rename and drop
echo "Checking migrations for new column creation:"
fd -e sql . backend/src/database/migrations/ -x cat {} \; | rg -i "add column|create type|create table|alter table \w+ add" -B1 -A1

Length of output: 29771

@skwowet
Copy link
Member Author

skwowet commented Jan 9, 2025

I didn’t add undo migration. Should I add that as well?

cc: @anilb0stanci @themarolt

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.

1 participant