Skip to content

Commit 782d505

Browse files
fix: improve CREATE TABLE constraint indentation using proper context indentLevel
- Remove explicit indentLevel increment when spawning table element contexts - Let context.indent() method handle indentation automatically using indentLevel + 1 - UNIQUE and FOREIGN KEY constraints now properly indented relative to columns - Constraints are visually distinct with proper logical grouping indentation - All tests passing including CREATE TABLE pretty printing snapshots Co-Authored-By: Dan Lynch <[email protected]>
1 parent 3045f86 commit 782d505

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

packages/deparser/src/deparser.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,18 +2465,17 @@ export class Deparser implements DeparserVisitor {
24652465
} else if (node.tableElts) {
24662466
const elements = ListUtils.unwrapList(node.tableElts);
24672467
const elementStrs = elements.map(el => {
2468-
const tableElementContext = context.spawn('CreateStmt', { indentLevel: context.indentLevel + 1 });
2469-
return this.deparse(el, tableElementContext);
2468+
return this.deparse(el, context.spawn('CreateStmt'));
24702469
});
24712470

24722471
if (context.isPretty()) {
24732472
const formattedElements = elementStrs.map(el => {
24742473
const trimmedEl = el.trim();
24752474
// Remove leading newlines from constraint elements to avoid extra blank lines
24762475
if (trimmedEl.startsWith('\n')) {
2477-
return ' ' + trimmedEl.substring(1);
2476+
return context.indent(trimmedEl.substring(1));
24782477
}
2479-
return ' ' + trimmedEl;
2478+
return context.indent(trimmedEl);
24802479
}).join(',' + context.newline());
24812480
output.push('(' + context.newline() + formattedElements + context.newline() + ')');
24822481
} else {

0 commit comments

Comments
 (0)