From 1abf23efe28a13587f0722dced13b0c114e63f10 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 28 Dec 2024 17:10:18 +0100 Subject: [PATCH] repo-tools: more codeblocks in SQL reports Signed-off-by: Patrik Oldsberg --- .../sql-reports/generateSqlReport.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/repo-tools/src/commands/api-reports/sql-reports/generateSqlReport.ts b/packages/repo-tools/src/commands/api-reports/sql-reports/generateSqlReport.ts index 83903e63d0..c804c96450 100644 --- a/packages/repo-tools/src/commands/api-reports/sql-reports/generateSqlReport.ts +++ b/packages/repo-tools/src/commands/api-reports/sql-reports/generateSqlReport.ts @@ -20,6 +20,13 @@ function sortedEntries(obj: Record): [string, T][] { return Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)); } +function code(str: unknown): string { + if (str === '-') { + return str; + } + return `\`${str}\``; +} + export function generateSqlReport(options: { reportName: string; failedDownMigration?: string; @@ -46,23 +53,23 @@ export function generateSqlReport(options: { for (const [sequenceName, sequenceInfo] of sortedEntries( schemaInfo.sequences, )) { - output.push(`- \`${sequenceName}\` (${sequenceInfo.type})`); + output.push(`- ${code(sequenceName)} (${sequenceInfo.type})`); } output.push(''); } for (const [tableName, tableInfo] of sortedEntries(schemaInfo.tables)) { - output.push(`## Table \`${tableName}\``); + output.push(`## Table ${code(tableName)}`); output.push(''); output.push(' | Column | Type | Nullable | Max Length | Default |'); output.push(' |--------|------|----------|------------|---------|'); for (const [columnName, columnInfo] of sortedEntries(tableInfo.columns)) { output.push( - ` | \`${columnName}\` | ${columnInfo.type} | ${ + ` | ${code(columnName)} | ${code(columnInfo.type)} | ${ columnInfo.nullable - } | ${columnInfo.maxLength ?? '-'} | ${ - columnInfo.defaultValue ?? '-' - } |`, + } | ${columnInfo.maxLength ?? '-'} | ${code( + columnInfo.defaultValue ?? '-', + )} |`, ); } output.push(''); @@ -78,7 +85,7 @@ export function generateSqlReport(options: { .filter(Boolean) .join(' '); output.push( - `- \`${indexName}\` (\`${indexInfo.columns.join('`, `')}\`)${ + `- ${code(indexName)} (${indexInfo.columns.map(code).join(', ')})${ indexType ? ` ${indexType}` : '' }`, );