Conversation
There was a problem hiding this comment.
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.
| // Add PRIMARY KEY inline before generated column syntax (PostgreSQL requires this order) | ||
| if pkConstraint != nil && column.IsGenerated { | ||
| stmt += " PRIMARY KEY" | ||
| } |
There was a problem hiding this comment.
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.
Fix #39