From 6664cd6871a4778a85087754fdf57e80987f90fb Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Fri, 1 Sep 2023 11:17:14 +0200 Subject: [PATCH] Improve schema missing columns logging (#21) --- .../Helpers/SqlStatementExtensions.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/SqlBulkSyncFunction/Helpers/SqlStatementExtensions.cs b/src/SqlBulkSyncFunction/Helpers/SqlStatementExtensions.cs index 49988eb..a494411 100644 --- a/src/SqlBulkSyncFunction/Helpers/SqlStatementExtensions.cs +++ b/src/SqlBulkSyncFunction/Helpers/SqlStatementExtensions.cs @@ -235,7 +235,11 @@ CONSTRAINT [PK_{2}] PRIMARY KEY CLUSTERED public static string GetDeletedAtSourceSelectStatement(this TableSchema tableSchema) { if (tableSchema.Columns == null || tableSchema.Columns.Length == 0) - throw new Exception("Columns missing"); + { + throw new Exception( + $"Columns for table {tableSchema.SourceTableName} missing ({tableSchema.Columns?.Length ?? -1})." + ); + } var primaryKeyColumns = tableSchema.Columns .Where(column => column.IsPrimary) @@ -299,7 +303,11 @@ public static string GetSourceSelectAllStatement(this TableSchema tableSchema) public static string GetNewOrUpdatedAtSourceSelectStatement(this TableSchema tableSchema) { if (tableSchema.Columns == null || tableSchema.Columns.Length == 0) - throw new Exception("Columns missing"); + { + throw new Exception( + $"Columns for table {tableSchema.SourceTableName} missing ({tableSchema.Columns?.Length ?? -1})." + ); + } var statement = (tableSchema.TargetVersion.CurrentVersion <= 1) // ReSharper disable once UseStringInterpolation