fix: correct ALTER TABLE ADD IDENTITY column generation#195
Merged
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Remove duplicate 'GENERATED' and 'AS IDENTITY' text in AT_AddIdentity case - Fix sequence name formatting to use 'SEQUENCE NAME schema.table' format - Handle NO MINVALUE/NO MAXVALUE cases when arg is null in CONSTR_IDENTITY - Fixes __tests__/kitchen-sink/original-alter-alter-table-column.test.ts Co-Authored-By: Dan Lynch <pyramation@gmail.com>
- Format each ALTER TABLE clause on its own line when pretty: true
- Enhanced CONSTR_IDENTITY formatting with proper indentation for sequence options
- Each sequence option appears on its own line with consistent indentation
- Follows existing pretty formatting patterns used throughout the deparser
Example output:
ALTER TABLE public.table1
ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.table1
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
)
Co-Authored-By: Dan Lynch <pyramation@gmail.com>
- Add collClause handling to AT_AddColumn case in AlterTableCmd function - Follows same pattern as ColumnDef function for consistency - Fixes parse/deparse cycle for ALTER TABLE statements with COLLATE clauses Co-Authored-By: Dan Lynch <pyramation@gmail.com>
Co-Authored-By: Dan Lynch <pyramation@gmail.com>
- Add multi-line indented formatting for column attributes - Format COLLATE, REFERENCES, UNIQUE, DEFAULT, GENERATED on separate lines - Maintain backward compatibility with non-pretty formatting - Update test cases to include all 9 ALTER TABLE column scenarios - Handle special cases like REFERENCES with ON DELETE CASCADE - Combine UNIQUE with DEFAULT appropriately Co-Authored-By: Dan Lynch <pyramation@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement Pretty Printing for ALTER TABLE ADD COLUMN Statements
Summary
This PR implements multi-line pretty printing for
ALTER TABLE ADD COLUMNstatements in the PostgreSQL deparser. Whencontext.isPretty()is enabled, column attributes (COLLATE, REFERENCES, UNIQUE, DEFAULT, GENERATED) are now formatted on separate indented lines for improved readability.Key formatting improvements:
NOT NULL,COLLATE,REFERENCES,UNIQUE,DEFAULT,GENERATEDmove to separate indented linesREFERENCES+ON DELETE CASCADE(split into separate lines)Review & Testing Checklist for Human
Recommended test plan: Run a variety of ALTER TABLE ADD COLUMN statements with different constraint combinations in both pretty and non-pretty modes, comparing outputs to ensure correctness.
Diagram
%%{ init : { "theme" : "default" }}%% graph TD deparser["packages/deparser/src/deparser.ts<br/>AT_AddColumn case implementation"]:::major-edit test_file["packages/deparser/__tests__/pretty/<br/>alter-table-column.test.ts"]:::minor-edit snapshots["packages/deparser/__tests__/pretty/__snapshots__/<br/>alter-table-column.test.ts.snap"]:::minor-edit deparser --> test_file test_file --> snapshots subgraph "Key Logic Areas" pretty_logic["Pretty formatting logic<br/>context.isPretty() branching"]:::context constraint_handling["Constraint processing<br/>REFERENCES, UNIQUE, DEFAULT"]:::context indent_formatting["Indentation & newlines<br/>context.indent(), context.newline()"]:::context end deparser --> pretty_logic deparser --> constraint_handling deparser --> indent_formatting subgraph Legend L1["Major Edit"]:::major-edit L2["Minor Edit"]:::minor-edit L3["Context/No Edit"]:::context end classDef major-edit fill:#90EE90,stroke:#333,stroke-width:2px classDef minor-edit fill:#87CEEB,stroke:#333,stroke-width:2px classDef context fill:#FFFFFF,stroke:#333,stroke-width:1pxNotes
(c: any)type annotation in constraints checking - this may indicate a need for better typing in the future