Skip to content

WIP: feat: implement REMOVE COLUMN operation support #2109

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

Open
wants to merge 1 commit into
base: support-remove-table-operation
Choose a base branch
from

Conversation

MH4GF
Copy link
Member

@MH4GF MH4GF commented Jun 20, 2025

This PR depends on #2108. Once #2108 is merged, this PR will be ready for review and the WIP prefix will be removed.

Issue

  • resolve: Implement support for REMOVE COLUMN operations in the database schema operation system

Why is this change needed?

This change adds support for the remove operation on columns, allowing users to generate ALTER TABLE DROP COLUMN DDL statements through the operation system.

What would you like reviewers to focus on?

  • Schema definition for RemoveColumnOperation in column.ts
  • DDL generation logic in generateRemoveColumnStatement function
  • Integration with the operation deparser
  • Test coverage for the new functionality

Testing Verification

  • All existing tests continue to pass (233 passed | 1 skipped)
  • New comprehensive tests added for remove column operations
  • Verified DDL generation produces correct ALTER TABLE {tableName} DROP COLUMN {columnName}; statements
  • Ran quality checks: pnpm fmt, pnpm lint, and pnpm test all pass

What was done

🤖 Generated by PR Agent at df53d71

• Add support for REMOVE COLUMN operations in database schema system
• Implement DDL generation for ALTER TABLE DROP COLUMN statements
• Add comprehensive test coverage for column removal functionality
• Integrate remove column operation with existing deparser system

Detailed Changes

Relevant files
Tests
operationDeparser.test.ts
Add tests for remove column operation                                       

frontend/packages/db-structure/src/deparser/postgresql/operationDeparser.test.ts

• Add test case for DROP COLUMN statement generation from remove
operation
• Verify correct DDL output for column removal operations

+14/-0   
Enhancement
operationDeparser.ts
Integrate remove column operation in deparser                       

frontend/packages/db-structure/src/deparser/postgresql/operationDeparser.ts

• Import RemoveColumnOperation type and type guard function
• Add
generateRemoveColumnFromOperation function for DDL generation

Integrate remove column operation handling in main deparser logic

+28/-2   
utils.ts
Add utility for DROP COLUMN statement generation                 

frontend/packages/db-structure/src/deparser/postgresql/utils.ts

• Add generateRemoveColumnStatement utility function
• Generate ALTER
TABLE DROP COLUMN DDL statements

+10/-0   
column.ts
Define remove column operation schema                                       

frontend/packages/db-structure/src/operation/schema/column.ts

• Define RemoveColumnOperation schema with validation
• Add
isRemoveColumnOperation type guard function
• Export remove column
operation in columnOperations array

+23/-1   

Additional Notes

This implementation follows the established operation support pattern and maintains consistency with existing column operations.

🤖 Generated with Claude Code


Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • - Add RemoveColumnOperation schema and type guard to column.ts
    - Implement generateRemoveColumnStatement utility function
    - Support DROP COLUMN DDL generation in operationDeparser
    - Add comprehensive tests for remove column operations
    - Update existing operations to handle column removal functionality
    
    🤖 Generated with [Claude Code](https://claude.ai/code)
    
    Co-Authored-By: Claude <[email protected]>
    Copy link

    changeset-bot bot commented Jun 20, 2025

    ⚠️ No Changeset found

    Latest commit: df53d71

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    Copy link

    vercel bot commented Jun 20, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    liam-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 7:53am
    liam-erd-sample ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 7:53am
    liam-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 7:53am
    1 Skipped Deployment
    Name Status Preview Comments Updated (UTC)
    liam-docs ⬜️ Ignored (Inspect) Jun 20, 2025 7:53am

    Copy link

    supabase bot commented Jun 20, 2025

    Updates to Preview Branch (support-remove-column-operation) ↗︎

    Deployments Status Updated
    Database Fri, 20 Jun 2025 07:50:07 UTC
    Services Fri, 20 Jun 2025 07:50:07 UTC
    APIs Fri, 20 Jun 2025 07:50:07 UTC

    Tasks are run on every commit but only new migration files are pushed.
    Close and reopen this PR if you want to apply changes from existing seed or migration files.

    Tasks Status Updated
    Configurations Fri, 20 Jun 2025 07:50:14 UTC
    Migrations Fri, 20 Jun 2025 07:50:19 UTC
    Seeding Fri, 20 Jun 2025 07:50:19 UTC
    Edge Functions Fri, 20 Jun 2025 07:50:19 UTC

    View logs for this Workflow Run ↗︎.
    Learn more about Supabase for Git ↗︎.

    @MH4GF MH4GF changed the base branch from main to support-remove-table-operation June 20, 2025 07:54
    @MH4GF MH4GF marked this pull request as ready for review June 20, 2025 07:58
    @MH4GF MH4GF requested a review from a team as a code owner June 20, 2025 07:58
    @MH4GF MH4GF requested review from hoshinotsuyoshi, FunamaYukina, junkisai and NoritakaIkeda and removed request for a team June 20, 2025 07:58
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 Security concerns

    SQL injection:
    The generateRemoveColumnStatement function in utils.ts directly concatenates tableName and columnName into SQL without proper escaping or validation. If these values originate from user input, this could allow SQL injection attacks. Consider using parameterized queries or proper SQL identifier escaping.

    ⚡ Recommended focus areas for review

    SQL Injection

    The generateRemoveColumnStatement function directly interpolates tableName and columnName into the SQL string without proper escaping or validation, which could lead to SQL injection vulnerabilities if these values come from user input.

    export function generateRemoveColumnStatement(
      tableName: string,
      columnName: string,
    ): string {
      return `ALTER TABLE ${tableName} DROP COLUMN ${columnName};`
    }
    Error Handling

    The generateRemoveColumnFromOperation function throws an error when pathInfo is null, but this error is not caught or handled in the main deparser function, potentially causing unhandled exceptions.

    function generateRemoveColumnFromOperation(
      operation: RemoveColumnOperation,
    ): string {
      const pathInfo = extractTableAndColumnNameFromPath(operation.path)
      if (!pathInfo) {
        throw new Error(`Invalid column path: ${operation.path}`)
      }
    
      return generateRemoveColumnStatement(pathInfo.tableName, pathInfo.columnName)
    }

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Security
    Add input validation for parameters

    The function should validate input parameters to prevent SQL injection or
    malformed statements. Add basic validation to ensure tableName and columnName
    are not empty or contain dangerous characters.

    frontend/packages/db-structure/src/deparser/postgresql/utils.ts [121-126]

     export function generateRemoveColumnStatement(
       tableName: string,
       columnName: string,
     ): string {
    +  if (!tableName?.trim() || !columnName?.trim()) {
    +    throw new Error('Table name and column name must be non-empty strings')
    +  }
       return `ALTER TABLE ${tableName} DROP COLUMN ${columnName};`
     }
    • Apply / Chat
    Suggestion importance[1-10]: 9

    __

    Why: The suggestion correctly identifies a potential security vulnerability (SQL injection) in the new generateRemoveColumnStatement function. Directly using input parameters to construct SQL queries without validation is unsafe. This is a critical security improvement.

    High
    • More

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant