IF OBJECT_ID('dbo.CvMatchResults', 'U') IS NULL
BEGIN
    CREATE TABLE dbo.CvMatchResults (
        Id NVARCHAR(64) NOT NULL CONSTRAINT PK_CvMatchResults PRIMARY KEY,
        CvDocumentId NVARCHAR(64) NOT NULL,
        JobDocumentId NVARCHAR(64) NOT NULL,
        ResultJson NVARCHAR(MAX) NOT NULL,
        Score INT NOT NULL,
        CreatedAt DATETIME2 NOT NULL CONSTRAINT DF_CvMatchResults_CreatedAt DEFAULT SYSUTCDATETIME()
    );
    CREATE UNIQUE INDEX UX_CvMatchResults_CvJob ON dbo.CvMatchResults(CvDocumentId, JobDocumentId);
END
GO

IF OBJECT_ID('dbo.CvMatcherChatCache', 'U') IS NULL
BEGIN
    CREATE TABLE dbo.CvMatcherChatCache (
        CacheKey NVARCHAR(64) NOT NULL CONSTRAINT PK_CvMatcherChatCache PRIMARY KEY,
        Model NVARCHAR(120) NOT NULL,
        Temperature DECIMAL(4,2) NOT NULL,
        ResponseText NVARCHAR(MAX) NOT NULL,
        CreatedAt DATETIME2 NOT NULL CONSTRAINT DF_CvMatcherChatCache_CreatedAt DEFAULT SYSUTCDATETIME()
    );
END
GO
