IF OBJECT_ID(N'dbo._hdc_ph_Log', N'U') IS NULL
 CREATE TABLE dbo._hdc_ph_Log (
  ID int IDENTITY(1, 1) NOT NULL,
  LogText nvarchar(500) NULL,
  LogTextLong nvarchar(max) NULL,
  Typ tinyint NULL,
  IntValue int NULL,
  NumValue numeric(19, 6) NULL,
  StrValue nvarchar(255) NULL,
  DatValue datetime NULL,
  MailAddress nvarchar(255) NULL,
  MailSent datetime NULL,
  ForMail BIT NOT NULL DEFAULT 0,
  IdJsonData int NULL,
  Autor nvarchar(80) DEFAULT suser_sname() NOT NULL,
  DatPorizeni datetime DEFAULT getdate() NOT NULL,
  CONSTRAINT PK__hdc_ph_Log PRIMARY KEY CLUSTERED (ID DESC) WITH ( PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
 )


/* 12.12.2023 */
IF COL_LENGTH(N'dbo._hdc_ph_Log', N'MailAddress') IS NULL ALTER TABLE dbo._hdc_ph_Log ADD MailAddress NVARCHAR(255) NULL
IF COL_LENGTH(N'dbo._hdc_ph_Log', N'MailSent') IS NULL ALTER TABLE dbo._hdc_ph_Log ADD MailSent DATETIME NULL

/* 31.1.2024 */
IF COL_LENGTH(N'dbo._hdc_ph_Log', N'IdJsonData') IS NULL ALTER TABLE dbo._hdc_ph_Log ADD IdJsonData INT NULL
DROP INDEX IF EXISTS EI_hdc_ph_Log_IdJsonData ON dbo._hdc_ph_Log
CREATE NONCLUSTERED INDEX EI_hdc_ph_Log_IdJsonData ON dbo._hdc_ph_Log (IdJsonData)
 WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

/* 25.6.2024 */
IF COL_LENGTH(N'dbo._hdc_ph_Log', N'ForMail') IS NULL ALTER TABLE dbo._hdc_ph_Log ADD ForMail BIT NOT NULL DEFAULT 0

/* 7.10.2024 */
IF COL_LENGTH(N'dbo._hdc_ph_Log', N'LogTextLong') IS NULL ALTER TABLE dbo._hdc_ph_Log ADD LogTextLong NVARCHAR(max)

