Skip to content

Comments

fix: generated column PK and NULL handling#58

Merged
tianzhou merged 1 commit intomainfrom
generate_column
Oct 8, 2025
Merged

fix: generated column PK and NULL handling#58
tianzhou merged 1 commit intomainfrom
generate_column

Conversation

@tianzhou
Copy link
Contributor

@tianzhou tianzhou commented Oct 8, 2025

Fix #39

Copilot AI review requested due to automatic review settings October 8, 2025 16:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes PostgreSQL generated column handling for primary key constraints and NULL behavior. The changes address how generated columns are processed in schema migration plans, ensuring proper SQL generation and constraint handling.

  • Removes automatic NOT NULL assignment for generated columns during parsing
  • Updates ALTER TABLE statement generation to handle PRIMARY KEY constraints correctly with generated columns
  • Adds a new test case for generated columns with text data type

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

File Description
ir/parser.go Removes automatic NOT NULL assignment for generated columns
internal/diff/table.go Updates PRIMARY KEY constraint positioning for generated columns and excludes them from explicit NOT NULL handling
testdata/diff/create_table/add_column_generated/. Test data updates showing proper handling of PRIMARY KEY generated columns and additional text column

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +609 to +612
// Add PRIMARY KEY inline before generated column syntax (PostgreSQL requires this order)
if pkConstraint != nil && column.IsGenerated {
stmt += " PRIMARY KEY"
}
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

The PRIMARY KEY constraint is now added in two separate locations (lines 610-612 and 621-623) with conditional logic based on whether the column is generated. This creates duplicated logic that could be error-prone. Consider consolidating this into a single location or extracting it into a helper function to improve maintainability.

Copilot uses AI. Check for mistakes.
@tianzhou tianzhou merged commit 40f7e03 into main Oct 8, 2025
2 checks passed
@tianzhou tianzhou deleted the generate_column branch October 23, 2025 09:15
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.

Primary key using generated column

1 participant