32 lines
1.5 KiB
MySQL
32 lines
1.5 KiB
MySQL
|
|
-- Permanent audit trail for supplier invoices processed into internet connections.
|
||
|
|
CREATE TABLE IF NOT EXISTS internet_connections_invoice_sync_runs (
|
||
|
|
id BIGSERIAL PRIMARY KEY,
|
||
|
|
file_id INTEGER REFERENCES incoming_files(file_id) ON DELETE SET NULL,
|
||
|
|
extraction_id INTEGER REFERENCES extractions(extraction_id) ON DELETE SET NULL,
|
||
|
|
supplier_invoice_id INTEGER REFERENCES supplier_invoices(id) ON DELETE SET NULL,
|
||
|
|
invoice_number VARCHAR(100),
|
||
|
|
vendor_name VARCHAR(255),
|
||
|
|
invoice_date DATE,
|
||
|
|
status VARCHAR(20) NOT NULL
|
||
|
|
CHECK (status IN ('success', 'warning', 'skipped', 'error')),
|
||
|
|
connections_synced INTEGER NOT NULL DEFAULT 0,
|
||
|
|
connections_created INTEGER NOT NULL DEFAULT 0,
|
||
|
|
connections_updated INTEGER NOT NULL DEFAULT 0,
|
||
|
|
ip_ranges_synced INTEGER NOT NULL DEFAULT 0,
|
||
|
|
total_lines INTEGER NOT NULL DEFAULT 0,
|
||
|
|
actionable_lines INTEGER NOT NULL DEFAULT 0,
|
||
|
|
skipped_lines INTEGER NOT NULL DEFAULT 0,
|
||
|
|
error_message TEXT,
|
||
|
|
result_json JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||
|
|
processed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||
|
|
);
|
||
|
|
|
||
|
|
CREATE INDEX IF NOT EXISTS idx_internet_invoice_sync_runs_processed
|
||
|
|
ON internet_connections_invoice_sync_runs(processed_at DESC);
|
||
|
|
|
||
|
|
CREATE INDEX IF NOT EXISTS idx_internet_invoice_sync_runs_status
|
||
|
|
ON internet_connections_invoice_sync_runs(status, processed_at DESC);
|
||
|
|
|
||
|
|
CREATE INDEX IF NOT EXISTS idx_internet_invoice_sync_runs_invoice
|
||
|
|
ON internet_connections_invoice_sync_runs(invoice_number, vendor_name);
|