sozsoft-platform/configs/seeds/sql/object/Hr_T_PerformanceGoal.sql

53 lines
2.5 KiB
MySQL
Raw Permalink Normal View History

2026-10-04 15:04:16 +00:00
IF OBJECT_ID(N'[dbo].[Hr_T_PerformanceGoal]', 'U') IS NULL
BEGIN
CREATE TABLE [dbo].[Hr_T_PerformanceGoal]
(
[Id] uniqueidentifier NOT NULL DEFAULT NEWID(),
[TenantId] uniqueidentifier NULL,
[ReviewId] uniqueidentifier NOT NULL,
[GoalType] nvarchar(8) NOT NULL DEFAULT 'KPI',
[Title] nvarchar(256) NOT NULL,
[Description] nvarchar(1024) NULL,
[Direction] nvarchar(16) NOT NULL DEFAULT 'Increasing',
[Unit] nvarchar(32) NULL,
[TargetValue] decimal(18, 2) NOT NULL,
[ActualValue] decimal(18, 2) NULL,
[Weight] decimal(5, 2) NOT NULL,
[AchievementRate] decimal(6, 2) NULL,
[SelfComment] nvarchar(1024) NULL,
[ManagerComment] nvarchar(1024) 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_PerformanceGoal] 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_PerformanceGoal_GoalType]', 'C') IS NULL
ALTER TABLE [dbo].[Hr_T_PerformanceGoal] ADD CONSTRAINT [CK_Hr_T_PerformanceGoal_GoalType] CHECK ([GoalType] IN ('KPI', 'OKR'))
GO
IF OBJECT_ID(N'[dbo].[CK_Hr_T_PerformanceGoal_Direction]', 'C') IS NULL
ALTER TABLE [dbo].[Hr_T_PerformanceGoal] ADD CONSTRAINT [CK_Hr_T_PerformanceGoal_Direction] CHECK ([Direction] IN ('Increasing', 'Decreasing'))
GO
IF OBJECT_ID(N'[dbo].[CK_Hr_T_PerformanceGoal_Weight]', 'C') IS NULL
ALTER TABLE [dbo].[Hr_T_PerformanceGoal] ADD CONSTRAINT [CK_Hr_T_PerformanceGoal_Weight] CHECK ([Weight] > 0 AND [Weight] <= 100)
GO
IF OBJECT_ID(N'[dbo].[CK_Hr_T_PerformanceGoal_TargetValue]', 'C') IS NULL
ALTER TABLE [dbo].[Hr_T_PerformanceGoal] ADD CONSTRAINT [CK_Hr_T_PerformanceGoal_TargetValue] CHECK ([TargetValue] > 0)
GO
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_Hr_T_PerformanceGoal_Review' AND object_id = OBJECT_ID(N'[dbo].[Hr_T_PerformanceGoal]'))
CREATE NONCLUSTERED INDEX [IX_Hr_T_PerformanceGoal_Review] ON [dbo].[Hr_T_PerformanceGoal] ([ReviewId])
GO