-- DBAOps Sovereign™ — v18 Expanded perf.Snapshot metrics for instance resource monitoring & optimization triage.
-- Nullable additive columns — collectors can populate any subset. Idempotent per column.

SET NOCOUNT ON;

IF OBJECT_ID(N'perf.Snapshots', N'U') IS NOT NULL
BEGIN
    IF COL_LENGTH(N'perf.Snapshots', N'PageLifeExpectancySec') IS NULL
        ALTER TABLE perf.Snapshots ADD PageLifeExpectancySec INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'BufferCacheHitRatioPct') IS NULL
        ALTER TABLE perf.Snapshots ADD BufferCacheHitRatioPct DECIMAL(5,2) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'PlanCacheHitRatioPct') IS NULL
        ALTER TABLE perf.Snapshots ADD PlanCacheHitRatioPct DECIMAL(5,2) NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'SqlCompilationsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD SqlCompilationsPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'SqlRecompilationsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD SqlRecompilationsPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'TransactionsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD TransactionsPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'LockRequestsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD LockRequestsPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'DeadlocksPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD DeadlocksPerSec DECIMAL(18,6) NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'FullScansPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD FullScansPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'IndexSearchesPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD IndexSearchesPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'PageReadsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD PageReadsPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'PageWritesPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD PageWritesPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'CheckpointPagesPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD CheckpointPagesPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'LazyWritesPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD LazyWritesPerSec DECIMAL(18,4) NULL;

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

    IF COL_LENGTH(N'perf.Snapshots', N'DiskReadMbps') IS NULL
        ALTER TABLE perf.Snapshots ADD DiskReadMbps DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'DiskWriteMbps') IS NULL
        ALTER TABLE perf.Snapshots ADD DiskWriteMbps DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'DataIOResponseMsAvg') IS NULL
        ALTER TABLE perf.Snapshots ADD DataIOResponseMsAvg DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'LogIOResponseMsAvg') IS NULL
        ALTER TABLE perf.Snapshots ADD LogIOResponseMsAvg DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'PendingDiskIOCount') IS NULL
        ALTER TABLE perf.Snapshots ADD PendingDiskIOCount INT NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'UserConnections') IS NULL
        ALTER TABLE perf.Snapshots ADD UserConnections INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'LoginsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD LoginsPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'LogoutsPerSec') IS NULL
        ALTER TABLE perf.Snapshots ADD LogoutsPerSec DECIMAL(18,4) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'ProcessesBlocked') IS NULL
        ALTER TABLE perf.Snapshots ADD ProcessesBlocked INT NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'CpuCountLogical') IS NULL
        ALTER TABLE perf.Snapshots ADD CpuCountLogical INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'SchedulerCountOnline') IS NULL
        ALTER TABLE perf.Snapshots ADD SchedulerCountOnline INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'RunnableTasksCount') IS NULL
        ALTER TABLE perf.Snapshots ADD RunnableTasksCount INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'ActiveWorkers') IS NULL
        ALTER TABLE perf.Snapshots ADD ActiveWorkers INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'MaxWorkers') IS NULL
        ALTER TABLE perf.Snapshots ADD MaxWorkers INT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'PrivilegedTimePercent') IS NULL
        ALTER TABLE perf.Snapshots ADD PrivilegedTimePercent DECIMAL(5,2) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'CpuTimeMsPerBatch') IS NULL
        ALTER TABLE perf.Snapshots ADD CpuTimeMsPerBatch DECIMAL(18,4) NULL;

    IF COL_LENGTH(N'perf.Snapshots', N'TargetServerMemoryMB') IS NULL
        ALTER TABLE perf.Snapshots ADD TargetServerMemoryMB BIGINT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'TotalServerMemoryMB') IS NULL
        ALTER TABLE perf.Snapshots ADD TotalServerMemoryMB BIGINT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'MaxServerMemoryMB') IS NULL
        ALTER TABLE perf.Snapshots ADD MaxServerMemoryMB BIGINT NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'CommittedMemoryMB') IS NULL
        ALTER TABLE perf.Snapshots ADD CommittedMemoryMB BIGINT NULL;

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

    IF COL_LENGTH(N'perf.Snapshots', N'TempdbUserObjectsMB') IS NULL
        ALTER TABLE perf.Snapshots ADD TempdbUserObjectsMB DECIMAL(18,2) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'TempdbInternalObjectsMB') IS NULL
        ALTER TABLE perf.Snapshots ADD TempdbInternalObjectsMB DECIMAL(18,2) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'TempdbVersionStoreMB') IS NULL
        ALTER TABLE perf.Snapshots ADD TempdbVersionStoreMB DECIMAL(18,2) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'TempdbDataAllocatedMB') IS NULL
        ALTER TABLE perf.Snapshots ADD TempdbDataAllocatedMB DECIMAL(18,2) NULL;
    IF COL_LENGTH(N'perf.Snapshots', N'TempdbDataUsedMB') IS NULL
        ALTER TABLE perf.Snapshots ADD TempdbDataUsedMB DECIMAL(18,2) NULL;
END
GO
