SET QUOTED_IDENTIFIER ON;
GO

PRINT '=== Mig 32+33 prod apply check ===';
SELECT TOP 5 MigrationId FROM __EFMigrationsHistory ORDER BY MigrationId DESC;
GO

PRINT '=== Contracts table V2 columns ===';
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='Contracts'
  AND COLUMN_NAME IN ('ApprovalWorkflowId','CurrentApprovalLevelOrder');
GO

PRINT '=== ContractLevelOpinions table exists ===';
SELECT COUNT(*) AS TableRowsCount FROM ContractLevelOpinions;
GO

PRINT '=== Sample workflow QT-HD-V2-001 seed verify ===';
SELECT Code, Version, ApplicableType, IsActive, IsUserSelectable
FROM ApprovalWorkflows
WHERE Code = 'QT-HD-V2-001';
GO

PRINT '=== V1 Contracts integrity check (7 prod giữ behavior) ===';
SELECT COUNT(*) AS TotalContracts,
       SUM(CASE WHEN WorkflowDefinitionId IS NOT NULL THEN 1 ELSE 0 END) AS V1Pinned,
       SUM(CASE WHEN ApprovalWorkflowId IS NOT NULL THEN 1 ELSE 0 END) AS V2Pinned
FROM Contracts;
GO
