@@ -22,8 +22,7 @@ export interface MermaidDiagramHighlight {
2222
2323const ADDED_CLASS_NAME = 'addedEntity' ;
2424const ADDED_CLASS_DEF = ` classDef ${ ADDED_CLASS_NAME } fill:#d4edda,stroke:#28a745,color:#155724` ;
25- const ADDED_COLUMN_MARKER = 'NEW' ;
26- const ADDED_FK_MARKER = '[NEW]' ;
25+ const ADDED_MARKER = '[NEW]' ;
2726
2827export function buildMermaidErDiagram (
2928 databaseName : string | null ,
@@ -60,12 +59,12 @@ export function buildMermaidErDiagram(
6059 for ( const column of table . structure ) {
6160 const dataType = toAttributeWord ( column . data_type || column . udt_name || 'unknown' ) ;
6261 const colName = toAttributeWord ( column . column_name ) ;
63- const markers : Array < string > = [ ] ;
64- if ( pkColumnNames . has ( column . column_name ) ) markers . push ( 'PK' ) ;
65- if ( fkColumnNames . has ( column . column_name ) ) markers . push ( 'FK' ) ;
66- if ( tableAddedCols . has ( normalizeIdent ( column . column_name ) ) ) markers . push ( ADDED_COLUMN_MARKER ) ;
67- const comment = buildColumnComment ( column ) ;
68- const tail = [ markers . join ( ',' ) , comment ] . filter ( ( p ) => p && p . length > 0 ) . join ( ' ' ) ;
62+ const keyMarkers : Array < string > = [ ] ;
63+ if ( pkColumnNames . has ( column . column_name ) ) keyMarkers . push ( 'PK' ) ;
64+ if ( fkColumnNames . has ( column . column_name ) ) keyMarkers . push ( 'FK' ) ;
65+ const isAdded = tableAddedCols . has ( normalizeIdent ( column . column_name ) ) ;
66+ const comment = buildColumnComment ( column , isAdded ) ;
67+ const tail = [ keyMarkers . join ( ',' ) , comment ] . filter ( ( p ) => p && p . length > 0 ) . join ( ' ' ) ;
6968 lines . push ( ` ${ dataType } ${ colName } ${ tail ? ' ' + tail : '' } ` ) ;
7069 }
7170 }
@@ -80,7 +79,7 @@ export function buildMermaidErDiagram(
8079 const targetAlias = aliasByTable . get ( fk . referenced_table_name ) ;
8180 if ( ! targetAlias ) continue ;
8281 const isAdded = tableAddedFks . has ( fkKey ( fk ) ) ;
83- const labelText = `${ sanitizeQuotedText ( fk . column_name ) } -> ${ sanitizeQuotedText ( fk . referenced_column_name ) } ${ isAdded ? ' ' + ADDED_FK_MARKER : '' } ` ;
82+ const labelText = `${ sanitizeQuotedText ( fk . column_name ) } -> ${ sanitizeQuotedText ( fk . referenced_column_name ) } ${ isAdded ? ' ' + ADDED_MARKER : '' } ` ;
8483 lines . push ( ` ${ sourceAlias } }o--|| ${ targetAlias } : "${ labelText } "` ) ;
8584 relationshipCount ++ ;
8685 }
@@ -154,7 +153,7 @@ function pluralize(n: number, singular: string, plural: string): string {
154153 return n === 1 ? singular : plural ;
155154}
156155
157- function buildColumnComment ( column : TableStructureDS ) : string {
156+ function buildColumnComment ( column : TableStructureDS , isAdded : boolean ) : string {
158157 const parts : Array < string > = [ ] ;
159158 if ( column . column_default !== null && column . column_default !== undefined && column . column_default !== '' ) {
160159 parts . push ( `default: ${ String ( column . column_default ) } ` ) ;
@@ -163,6 +162,9 @@ function buildColumnComment(column: TableStructureDS): string {
163162 if ( column . character_maximum_length ) {
164163 parts . push ( `max length: ${ column . character_maximum_length } ` ) ;
165164 }
165+ if ( isAdded ) {
166+ parts . push ( ADDED_MARKER ) ;
167+ }
166168 const text = parts . join ( '; ' ) ;
167169 return text ? `"${ sanitizeQuotedText ( text ) } "` : '' ;
168170}
0 commit comments