Skip to content

Conversation

@almas-x
Copy link
Contributor

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

📑 Description

Go migrator supports After and First column modifiers. (MySQL only)

func (r *M20250210084318AddColumnToTestTableCommentTable) Up() error {
	return facades.Schema().Table("test_table_comment", func(table schema.Blueprint) {
		table.String("after_column").After("first_column")
		table.String("add_to_head").First()
	})
}

Closes goravel/goravel#571

Summary by CodeRabbit

  • New Features

    • Enabled enhanced schema design by allowing columns to be positioned either at the start or after a specified column.
    • Introduced new methods for managing column ordering and retrieving positional information.
  • Documentation

    • Improved clarity on database compatibility, ensuring users understand which database systems support the new table comment and column ordering capabilities.
    • Updated comments to specify compatibility with MySQL, PostgreSQL, and SQL Server for relevant methods.

✅ Checks

  • Added test cases for my code

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

coderabbitai bot commented Feb 10, 2025

Walkthrough

This pull request modifies the schema migration interfaces and implementations to enhance column ordering capabilities and clarify database compatibility in method documentation. The Comment method in the Blueprint interface now specifies its applicability to MySQL and PostgreSQL. Additionally, new methods (After, First, GetAfter, IsFirst) are introduced in the ColumnDefinition interface, along with corresponding implementations and mock structures to facilitate column ordering.

Changes

File Path Change Summary
contracts/database/schema/blueprint.go Updated the Comment method comment to specify that it applies to MySQL and PostgreSQL.
contracts/database/schema/column.go Added new methods: After(column string), First(), GetAfter(), and IsFirst(); updated comments for Change(), Comment(), Unsigned(), and UseCurrentOnUpdate() to clarify database compatibility.
database/schema/column.go Added new fields after (string) and first (bool) to the ColumnDefinition struct; implemented methods: After(column string), First(), GetAfter(), and IsFirst() to support column ordering functionality.
mocks/database/schema/ColumnDefinition.go Added mocked methods: After(column string), First(), GetAfter(), and IsFirst() along with corresponding call structures to support comprehensive testing of the column ordering feature.

Sequence Diagram(s)

sequenceDiagram
    participant U as User/Migration Script
    participant B as Blueprint
    participant C as ColumnDefinition
    participant DB as Database Schema

    U->>B: Define new column with ordering details
    B->>C: Call After/First methods to set column position
    C->>DB: Update ordering parameters (fields: after, first)
    DB-->>C: Confirm update
    C-->>B: Return updated ColumnDefinition
Loading

Assessment against linked issues

Objective Addressed Explanation
Go migrator support after method (#571)

Possibly related PRs

  • feat: [#280] Add Column, Comment, Double methods #728: The changes in the main PR, specifically the modification of the Comment method in the Blueprint interface, are related to the addition of the Comment method in the ColumnDefinition interface, as both involve enhancements to comment handling in the database schema context.

Suggested reviewers

  • hwbrzzl
✨ 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.

@codecov
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.51%. Comparing base (8e9d6ea) to head (08a376c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #876   +/-   ##
=======================================
  Coverage   67.51%   67.51%           
=======================================
  Files         151      151           
  Lines       10355    10355           
=======================================
  Hits         6991     6991           
  Misses       2996     2996           
  Partials      368      368           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
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)
contracts/database/schema/column.go (1)

16-17: Consider adding database compatibility comments to getter methods.

The getter methods GetAfter and IsFirst should follow the same pattern as other methods and include comments indicating MySQL-only support for consistency.

Also applies to: 50-51

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c378d7d and 3e719ab.

📒 Files selected for processing (4)
  • contracts/database/schema/blueprint.go (1 hunks)
  • contracts/database/schema/column.go (3 hunks)
  • database/schema/column.go (4 hunks)
  • mocks/database/schema/ColumnDefinition.go (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • contracts/database/schema/blueprint.go
🔇 Additional comments (6)
contracts/database/schema/column.go (2)

4-5: LGTM! Clear documentation of MySQL-only support.

The After method is well-documented with a clear comment indicating MySQL-only support.


14-15: LGTM! Clear documentation of MySQL-only support.

The First method is well-documented with a clear comment indicating MySQL-only support.

database/schema/column.go (3)

9-9: LGTM! Appropriate field types.

The after and first fields are appropriately typed as string and bool respectively.

Also applies to: 15-15


36-40: LGTM! Clean implementation of column positioning methods.

The After and First methods have a clean implementation that follows the builder pattern by returning self.

Also applies to: 66-70


72-74: LGTM! Simple getter implementations.

The getter methods GetAfter and IsFirst have straightforward implementations that directly return their respective field values.

Also applies to: 188-190

mocks/database/schema/ColumnDefinition.go (1)

23-69: LGTM! Consistent mock implementations.

The auto-generated mock code follows the established patterns and includes proper error handling and type assertions.

Also applies to: 261-306, 308-351, 1079-1122

@almas-x almas-x enabled auto-merge (squash) February 10, 2025 10:08
Copy link
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)
database/schema/column.go (1)

36-40: Consider adding column name validation.

While the implementation is correct, consider validating the column name to prevent SQL injection or invalid column names.

 func (r *ColumnDefinition) After(column string) schema.ColumnDefinition {
+	// Validate column name to prevent SQL injection
+	if !isValidColumnName(column) {
+		panic("invalid column name")
+	}
 	r.after = column
 
 	return r
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e719ab and 516e0c5.

📒 Files selected for processing (4)
  • contracts/database/schema/blueprint.go (1 hunks)
  • contracts/database/schema/column.go (3 hunks)
  • database/schema/column.go (4 hunks)
  • mocks/database/schema/ColumnDefinition.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • contracts/database/schema/column.go
  • contracts/database/schema/blueprint.go
⏰ Context from checks skipped due to timeout of 300000ms (2)
  • GitHub Check: test / windows (1.23)
  • GitHub Check: test / windows (1.22)
🔇 Additional comments (4)
database/schema/column.go (3)

9-15: LGTM! Field additions are well-structured.

The new fields after and first are appropriately typed and follow the existing field ordering pattern.


66-70: LGTM! First method implementation is clean and consistent.

The method follows the builder pattern and correctly implements method chaining.


72-74: LGTM! Getter methods are properly implemented.

Both GetAfter and IsFirst methods follow the established getter pattern in the codebase.

Also applies to: 188-190

mocks/database/schema/ColumnDefinition.go (1)

1-1514: LGTM! Auto-generated mock implementation is complete.

The mock implementation correctly includes all new methods and follows the established mockery patterns.

@almas-x almas-x disabled auto-merge February 10, 2025 15:38
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 remember to add tests in tests.

// AutoIncrement set the column as auto increment
AutoIncrement() ColumnDefinition
// Change the column
// Change the column (MySQL / PostgreSQL / SQL Server)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good comment

@almas-x
Copy link
Contributor Author

almas-x commented Feb 11, 2025

LGTM, please remember to add tests in tests.

Okay, I will submit another PR.

Copy link
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 (3)
database/schema/column.go (3)

9-9: Initialize new fields in the constructor.

The new fields after and first should be initialized with zero values in the NewColumnDefinition constructor to ensure consistent behavior.

 func NewColumnDefinition(name string, ttype string) schema.ColumnDefinition {
 	return &ColumnDefinition{
 		name:  &name,
 		ttype: convert.Pointer(ttype),
+		after: "",
+		first: false,
 	}
 }

Also applies to: 15-15


36-40: Add validation for the After method.

Consider adding validation to ensure the column name is not empty and follows database naming conventions.

 func (r *ColumnDefinition) After(column string) schema.ColumnDefinition {
+	if column == "" {
+		// Either return an error or log a warning
+		return r
+	}
 	r.after = column
 
 	return r
 }

8-27: Add documentation about database compatibility.

Since these column modifiers are specifically for MySQL (as mentioned in the PR objectives), consider adding documentation to clarify the database compatibility of these features.

 type ColumnDefinition struct {
+	// after specifies the column after which this column should be placed (MySQL only)
 	after              string
 	allowed            []any
 	autoIncrement      *bool
 	change             bool
 	comment            *string
 	def                any
+	// first indicates if this column should be placed first in the table (MySQL only)
 	first              bool
 	length             *int
 	name               *string
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 516e0c5 and 08a376c.

📒 Files selected for processing (4)
  • contracts/database/schema/blueprint.go (1 hunks)
  • contracts/database/schema/column.go (3 hunks)
  • database/schema/column.go (4 hunks)
  • mocks/database/schema/ColumnDefinition.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • contracts/database/schema/blueprint.go
  • contracts/database/schema/column.go
  • mocks/database/schema/ColumnDefinition.go
⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: test / windows (1.22)
🔇 Additional comments (1)
database/schema/column.go (1)

66-70: LGTM!

The implementations of First, GetAfter, and IsFirst methods are clean, follow the established patterns, and correctly implement the required functionality.

Also applies to: 72-74, 188-190

@almas-x almas-x merged commit ded0b3e into master Feb 11, 2025
14 checks passed
@almas-x almas-x deleted the almas#571 branch February 11, 2025 01:30
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 after method

3 participants