Files
Fuchs_Intranet/Fuchs_Database/dbo/Tables/fds__invoice_file_backups.sql
T
Stefan 9569c1b65e
Playwright Tests / test (push) Canceled after 0s
feat: Enhance invoice file backup procedure to include JSON snapshots
- Updated the stored procedure `fds__admin_backupAndClearInvoiceFile.sql` to back up not only the invoice file but also JSON snapshots of related data (invoices, items, details, service requests) to ensure consistency and traceability.
- Modified the table structure of `fds__invoice_file_backups` to accommodate new JSON columns for storing these snapshots.
- Added an ADR (0030) document to outline the decision and rationale behind these changes, emphasizing the importance of maintaining a consistent set of data alongside the backed-up file.
2026-09-17 22:39:01 +02:00

23 lines
1.2 KiB
Transact-SQL

CREATE TABLE [dbo].[fds__invoice_file_backups] (
[uid] BIGINT IDENTITY (1, 1) NOT NULL,
[InvoiceId] VARCHAR (10) NOT NULL,
[DocumentName] VARCHAR (50) NULL,
[file] VARBINARY (MAX) NOT NULL,
-- JSON snapshots (FOR JSON PATH) of the invoice's data rows at backup time, so the file and
-- the data it was rendered from stay together as one consistent set (ADR 0030).
-- InvoiceJson: the fds__invoices row without [file]; InvoiceItemsJson: array of
-- fds__invoice_items rows; InvoiceDetailsJson: the fds__invoice_details row (NULL if none);
-- InvoiceServiceRequestsJson: array of fds__invoice_servicerequests rows.
[InvoiceJson] NVARCHAR (MAX) NULL,
[InvoiceItemsJson] NVARCHAR (MAX) NULL,
[InvoiceDetailsJson] NVARCHAR (MAX) NULL,
[InvoiceServiceRequestsJson] NVARCHAR (MAX) NULL,
[BackedUpAt] DATETIME CONSTRAINT [DF_fds__invoice_file_backups_BackedUpAt] DEFAULT (getutcdate()) NOT NULL,
[BackedUpBy] VARCHAR (25) NULL,
CONSTRAINT [PK_fds__invoice_file_backups] PRIMARY KEY CLUSTERED ([uid] ASC)
);
GO
CREATE NONCLUSTERED INDEX [fds__invoice_file_backups__ix1]
ON [dbo].[fds__invoice_file_backups]([InvoiceId] ASC);