@@ -58,14 +58,15 @@ CREATE TABLE IF NOT EXISTS PrintAuditLog (
5858 Copies INTEGER DEFAULT 1,
5959 Dpi INTEGER,
6060 UserId TEXT,
61- LabelType TEXT,
61+ DocumentType TEXT,
6262 Status TEXT NOT NULL,
6363 ErrorMessage TEXT,
6464 JobId TEXT,
6565 CreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
6666 )
6767 " ) ;
6868
69+ EnsureDocumentTypeColumn ( connection ) ;
6970 connection . Execute ( "CREATE INDEX IF NOT EXISTS idx_audit_timestamp ON PrintAuditLog(Timestamp)" ) ;
7071 connection . Execute ( "CREATE INDEX IF NOT EXISTS idx_audit_printer ON PrintAuditLog(PrinterName)" ) ;
7172 connection . Execute ( "CREATE INDEX IF NOT EXISTS idx_audit_user ON PrintAuditLog(UserId)" ) ;
@@ -81,10 +82,10 @@ public void LogPrint(PrintAuditLog log)
8182 connection . Execute ( @"
8283 INSERT INTO PrintAuditLog
8384 (Timestamp, PrinterName, PaperWidth, PaperHeight, PaperUnit,
84- Copies, Dpi, UserId, LabelType , Status, ErrorMessage, JobId)
85+ Copies, Dpi, UserId, DocumentType , Status, ErrorMessage, JobId)
8586 VALUES
8687 (@Timestamp, @PrinterName, @PaperWidth, @PaperHeight, @PaperUnit,
87- @Copies, @Dpi, @UserId, @LabelType , @Status, @ErrorMessage, @JobId)
88+ @Copies, @Dpi, @UserId, @DocumentType , @Status, @ErrorMessage, @JobId)
8889 " , log ) ;
8990 }
9091
@@ -175,6 +176,24 @@ private static string BuildLogsQuery(
175176 return sql ;
176177 }
177178
179+ private static void EnsureDocumentTypeColumn ( SQLiteConnection connection )
180+ {
181+ var columns = connection . Query < string > ( "SELECT name FROM pragma_table_info('PrintAuditLog')" ) . ToList ( ) ;
182+ if ( ! columns . Contains ( "DocumentType" , StringComparer . OrdinalIgnoreCase ) )
183+ connection . Execute ( "ALTER TABLE PrintAuditLog ADD COLUMN DocumentType TEXT" ) ;
184+
185+ if ( columns . Contains ( "LabelType" , StringComparer . OrdinalIgnoreCase ) )
186+ {
187+ connection . Execute ( @"
188+ UPDATE PrintAuditLog
189+ SET DocumentType = LabelType
190+ WHERE (DocumentType IS NULL OR DocumentType = '')
191+ AND LabelType IS NOT NULL
192+ AND LabelType <> ''
193+ " ) ;
194+ }
195+ }
196+
178197 public int CleanupOldLogs ( DateTime ? now = null )
179198 {
180199 var cutoff = ( now ?? DateTime . Now ) . AddDays ( - _retentionDays ) ;
0 commit comments