sozsoft-platform/configs/seeds/sql/object/Hr_T_PerformanceReview.sql
2026-10-05 15:58:59 +03:00

57 lines
No EOL
2.8 KiB
Transact-SQL

IF OBJECT_ID(N'[dbo].[Hr_T_PerformanceReview]', 'U') IS NULL
BEGIN
CREATE TABLE [dbo].[Hr_T_PerformanceReview]
(
[Id] uniqueidentifier NOT NULL DEFAULT NEWID(),
[TenantId] uniqueidentifier NULL,
[PeriodId] uniqueidentifier NOT NULL,
[EmployeeId] uniqueidentifier NOT NULL,
[EmployeeName] nvarchar(128) NULL,
[ManagerId] uniqueidentifier NULL,
[DepartmentId] uniqueidentifier NULL,
[JobPositionId] uniqueidentifier NULL,
[Status] nvarchar(16) NOT NULL DEFAULT 'GoalSetting',
[LastStatus] nvarchar(16) NULL,
[GoalScore] decimal(6, 2) NULL,
[CompetencyScore] decimal(6, 2) NULL,
[Feedback360Score] decimal(6, 2) NULL,
[OverallScore] decimal(6, 2) NULL,
[CalibratedScore] decimal(6, 2) NULL,
[RatingId] uniqueidentifier NULL,
[SelfComment] nvarchar(2048) NULL,
[ManagerComment] nvarchar(2048) NULL,
[CalibrationNote] nvarchar(1024) NULL,
[SelfSubmittedDate] datetime2 NULL,
[ManagerSubmittedDate] datetime2 NULL,
[CompletedDate] datetime2 NULL,
[IsActive] bit NOT NULL DEFAULT 1,
[CreationTime] datetime2 NOT NULL DEFAULT GETUTCDATE(),
[CreatorId] uniqueidentifier NULL,
[LastModificationTime] datetime2 NULL,
[LastModifierId] uniqueidentifier NULL,
[IsDeleted] bit NOT NULL DEFAULT 0,
[DeletionTime] datetime2 NULL,
[DeleterId] uniqueidentifier NULL,
CONSTRAINT [PK_Hr_T_PerformanceReview] PRIMARY KEY NONCLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF OBJECT_ID(N'[dbo].[CK_Hr_T_PerformanceReview_Status]', 'C') IS NULL
ALTER TABLE [dbo].[Hr_T_PerformanceReview] ADD CONSTRAINT [CK_Hr_T_PerformanceReview_Status] CHECK ([Status] IN ('GoalSetting', 'SelfReview', 'ManagerReview', 'Calibration', 'Completed'))
GO
IF OBJECT_ID(N'[dbo].[CK_Hr_T_PerformanceReview_CalibratedScore]', 'C') IS NULL
ALTER TABLE [dbo].[Hr_T_PerformanceReview] ADD CONSTRAINT [CK_Hr_T_PerformanceReview_CalibratedScore] CHECK ([CalibratedScore] IS NULL OR [CalibratedScore] BETWEEN 0 AND 150)
GO
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'UX_Hr_T_PerformanceReview_Employee' AND object_id = OBJECT_ID(N'[dbo].[Hr_T_PerformanceReview]'))
CREATE UNIQUE NONCLUSTERED INDEX [UX_Hr_T_PerformanceReview_Employee] ON [dbo].[Hr_T_PerformanceReview] ([PeriodId], [EmployeeId]) WHERE [IsDeleted] = 0
GO
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_Hr_T_PerformanceReview_Manager' AND object_id = OBJECT_ID(N'[dbo].[Hr_T_PerformanceReview]'))
CREATE NONCLUSTERED INDEX [IX_Hr_T_PerformanceReview_Manager] ON [dbo].[Hr_T_PerformanceReview] ([ManagerId])
GO