-- DBAOps Sovereign™ — v19 Advanced telemetry for waits, OS memory pressure, HADR queues,
-- parallelism settings, spills, fragmentation signals, backups, and network rates.
-- All columns nullable — collectors populate any subset. Idempotent.

SET NOCOUNT ON;

IF OBJECT_ID(N'perf.Snapshots', N'U') IS NOT NULL
BEGIN
    IF COL_LENGTH(N'perf.Snapshots', N'ReadAheadPagesPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD ReadAheadPagesPerSec DECIMAL(18, 4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'WorkfilesCreatedPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD WorkfilesCreatedPerSec DECIMAL(18, 4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'WorktablesCreatedPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD WorktablesCreatedPerSec DECIMAL(18, 4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'LatchWaitsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD LatchWaitsPerSec DECIMAL(18, 4) NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'WaitIoMsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD WaitIoMsPerSec DECIMAL(18, 4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'WaitLockMsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD WaitLockMsPerSec DECIMAL(18, 4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'WaitMemoryMsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD WaitMemoryMsPerSec DECIMAL(18, 4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'WaitCpuParallelMsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD WaitCpuParallelMsPerSec DECIMAL(18, 4) NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'HostTotalMemoryMB') IS NULL
        ALTER TABLE perf.Snapshots ADD HostTotalMemoryMB BIGINT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'HostAvailableMemoryMB') IS NULL
        ALTER TABLE perf.Snapshots ADD HostAvailableMemoryMB BIGINT NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'OldestOpenTranMinutes') IS NULL
        ALTER TABLE perf.Snapshots ADD OldestOpenTranMinutes DECIMAL(18, 2) NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'AgRedoQueueKB') IS NULL
        ALTER TABLE perf.Snapshots ADD AgRedoQueueKB BIGINT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'AgLogSendQueueKB') IS NULL
        ALTER TABLE perf.Snapshots ADD AgLogSendQueueKB BIGINT NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'MaxDopConfigured') IS NULL
        ALTER TABLE perf.Snapshots ADD MaxDopConfigured INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'CostThresholdForParallelism') IS NULL
        ALTER TABLE perf.Snapshots ADD CostThresholdForParallelism INT NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'NetworkReceiveMbps') IS NULL
        ALTER TABLE perf.Snapshots ADD NetworkReceiveMbps DECIMAL(18, 4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'NetworkSendMbps') IS NULL
        ALTER TABLE perf.Snapshots ADD NetworkSendMbps DECIMAL(18, 4) NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'SortSpillsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD SortSpillsPerSec DECIMAL(18, 6) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'HashSpillsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD HashSpillsPerSec DECIMAL(18, 6) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'ForwardedRecordsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD ForwardedRecordsPerSec DECIMAL(18, 4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'PageSplitsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD PageSplitsPerSec DECIMAL(18, 4) NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'UserDatabaseCount') IS NULL
        ALTER TABLE perf.Snapshots ADD UserDatabaseCount INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'BackupAgeWorstMinutes') IS NULL
        ALTER TABLE perf.Snapshots ADD BackupAgeWorstMinutes INT NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'StolenServerMemoryMB') IS NULL
        ALTER TABLE perf.Snapshots ADD StolenServerMemoryMB BIGINT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'BufferPoolDataMB') IS NULL
        ALTER TABLE perf.Snapshots ADD BufferPoolDataMB BIGINT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'PlanCacheSizeMB') IS NULL
        ALTER TABLE perf.Snapshots ADD PlanCacheSizeMB BIGINT NULL;
END
GO
