Skip to content

Comments

feat: [#572] add rename column compiler#13

Merged
almas-x merged 2 commits intomasterfrom
almas/#572
Feb 9, 2025
Merged

feat: [#572] add rename column compiler#13
almas-x merged 2 commits intomasterfrom
almas/#572

Conversation

@almas-x
Copy link
Contributor

@almas-x almas-x commented Feb 8, 2025

📑 Description

Closes goravel/goravel#572

Summary by CodeRabbit

  • New Features
    • Introduced enhanced support for renaming database table columns with automated SQL generation.
  • Chores
    • Updated core dependency versions to improve performance, compatibility, and overall system stability.
  • Tests
    • Expanded test coverage to ensure the reliability and accuracy of the new column renaming functionality.

✅ Checks

  • Added test cases for my code

@almas-x almas-x requested a review from a team as a code owner February 8, 2025 09:25
@coderabbitai
Copy link

coderabbitai bot commented Feb 8, 2025

Walkthrough

This pull request updates dependency versions in the go.mod file and introduces a new method, CompileRenameColumn, to the Grammar struct. The new method constructs an SQL statement for renaming a column in a database table by formatting table and column names appropriately. Additionally, a corresponding unit test in grammar_test.go has been added to verify that the generated SQL command matches the expected output.

Changes

File(s) Change Summary
go.mod Updated dependency versions for github.com/goravel/framework, golang.org/x/crypto, golang.org/x/sys, and golang.org/x/term.
grammar.go, grammar_test.go Added the CompileRenameColumn method to generate SQL for renaming columns and a unit test to verify its correct functionality.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Grammar
    participant Blueprint
    participant Command
    Client->>Grammar: Call CompileRenameColumn(schema, blueprint, command)
    Grammar->>Blueprint: Format table and column names
    Grammar->>Client: Return formatted SQL statement
Loading

Assessment against linked issues

Objective Addressed Explanation
Support renaming columns in Go migrator (#572)

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint (1.62.2)

level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package : could not load export data: no export data for "golang.org/x/sys/unix""
level=error msg="Running error: can't run linter goanalysis_metalinter\nbuildir: failed to load package : could not load export data: no export data for "golang.org/x/sys/unix""

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

LGTM, please update go.mod.

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)
grammar_test.go (1)

345-359: Consider adding more test cases for comprehensive coverage.

While the basic test case is good, consider adding tests for:

  • Schema-qualified tables
  • Special characters in column names
  • Error cases

Example additional test cases:

 func (s *GrammarSuite) TestCompileRenameColumn() {
+    tests := []struct {
+        name        string
+        schema      string
+        table       string
+        fromColumn  string
+        toColumn    string
+        expectSQL   string
+        expectError error
+    }{
+        {
+            name:       "basic rename",
+            table:      "users",
+            fromColumn: "before",
+            toColumn:   "after",
+            expectSQL:  `alter table "goravel_users" rename column "before" to "after"`,
+        },
+        {
+            name:       "schema qualified table",
+            schema:     "public",
+            table:      "users",
+            fromColumn: "before",
+            toColumn:   "after",
+            expectSQL:  `alter table "public"."goravel_users" rename column "before" to "after"`,
+        },
+        {
+            name:       "special characters in names",
+            table:      "users",
+            fromColumn: "user.name",
+            toColumn:   "user.full_name",
+            expectSQL:  `alter table "goravel_users" rename column "user.name" to "user.full_name"`,
+        },
+    }
+
+    for _, test := range tests {
+        s.Run(test.name, func() {
+            mockBlueprint := mocksschema.NewBlueprint(s.T())
+            mockBlueprint.EXPECT().GetTableName().Return(test.table).Once()
+
+            sql, err := s.grammar.CompileRenameColumn(test.schema, mockBlueprint, &contractsschema.Command{
+                From: test.fromColumn,
+                To:   test.toColumn,
+            })
+
+            if test.expectError != nil {
+                s.Equal(test.expectError, err)
+            } else {
+                s.NoError(err)
+                s.Equal(test.expectSQL, sql)
+            }
+        })
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68d6cc2 and 53fa9cc.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod (2 hunks)
  • grammar.go (1 hunks)
  • grammar_test.go (1 hunks)
🔇 Additional comments (2)
grammar.go (1)

304-310: LGTM! Implementation follows PostgreSQL standards.

The implementation correctly generates the ALTER TABLE SQL command for renaming columns, with proper escaping of identifiers.

go.mod (1)

8-8: Verify compatibility with updated dependencies.

The framework and system package updates look standard, but please ensure:

  1. The new framework version (v1.15.2-0.20250209050736-c63da33a6ac2) is stable
  2. The updated crypto package (v0.33.0) doesn't introduce breaking changes

Also applies to: 46-46, 50-51

✅ Verification successful

🌐 Web query:

Are there any known issues with golang.org/x/crypto v0.33.0?

💡 Result:

The available search results do not indicate any known issues specifically with **golang.org/x/crypto v0.33.0**. However, here’s critical context from related updates:

1. **CVE-2024-45337** (critical severity) affected older versions of `golang.org/x/crypto` (prior to **v0.31.0**), involving an authorization bypass in SSH-related code due to misuse of `ServerConfig.PublicKeyCallback`[4][5][7]. This was patched in **v0.31.0**.

2. The search results highlight dependencies like `golang.org/x/net` (updated to **v0.33.0** to fix **CVE-2024-45338**, a high-severity HTML parsing vulnerability)[1][3][5][7][8], but no issues are reported for `x/crypto` beyond **v0.31.0**.

### Key Observations:
- The term "v0.33.0" appears in references to `golang.org/x/net`, not `x/crypto`. Ensure you are referencing the correct module.
- If your project uses `x/crypto`, confirm its version:
  - Versions ≥ **v0.31.0** include fixes for critical vulnerabilities[4][5].
  - No vulnerabilities are reported for hypothetical `x/crypto v0.33.0` in the provided data.

For safety, verify dependency trees using tools like `govulncheck`[5] or Docker Scout[5] to detect outdated or vulnerable imports indirectly linked to `x/crypto`.

Citations:

- 1: https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/463
- 2: https://pkg.go.dev/vuln/GO-2024-3330
- 3: https://github.com/golang/go/issues/70906
- 4: https://groups.google.com/g/golang-announce/c/-nPEi39gI4Q
- 5: https://jarosz.dev/code/how-to-handle-go-security-alerts/
- 6: https://cert-manager.io/docs/releases/release-notes/release-notes-1.12/
- 7: https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/5253
- 8: https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/-/merge_requests/71
- 9: https://docs.42crunch.com/latest/content/whatsnew/42crunch-platform-2025-01-09.htm
- 10: https://groups.google.com/g/golang-announce

Dependency Updates Verified – No Issues Detected

Our investigation confirms that the updated dependencies appear stable. Specifically:

  • The framework update to v1.15.2-0.20250209050736-c63da33a6ac2 should be compatible and is aligned with the new functionality enhancements.
  • The updated crypto dependency shows no known issues beyond those addressed in v0.31.0. There are no reported breaking changes for versions ≥ v0.31.0.

Please ensure to run a dependency vulnerability scan (e.g., using govulncheck) as routine maintenance.

@almas-x
Copy link
Contributor Author

almas-x commented Feb 9, 2025

LGTM, please update go.mod.

Done!

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

LGTM

@almas-x almas-x merged commit f147df2 into master Feb 9, 2025
6 checks passed
@almas-x almas-x deleted the almas/#572 branch June 13, 2025 08:26
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.

Go migrator support to rename column

2 participants