IF OBJECT_ID(N'dbo._hdc_ph_PrijataJsonData', N'U') IS NULL
 CREATE TABLE dbo._hdc_ph_PrijataJsonData (
  ID bigint IDENTITY(1, 1) NOT NULL,
  GUIDIdent uniqueidentifier DEFAULT newid() NOT NULL,
  IdPHIdent bigint DEFAULT 0 NOT NULL,
  PHOznaceni nvarchar(50) NULL,
  UzivIdent nvarchar(100) NULL,
  JSONData nvarchar(max) NULL,
  DatPotvrzeni datetime NULL,
  DatZpracovani datetime NULL,
  Nezpracovat bit NOT NULL DEFAULT 0,
  DatPorizeni datetime DEFAULT getdate() NULL,
  IDDoklad int NULL,
  CisloZam int NULL,
  PosledniChyba nvarchar(255) NULL,
  Blokovano bit NOT NULL DEFAULT 0,
  IDMzda int NULL,
  IDMezd NVARCHAR(max) NULL,
  IDEvidRozpOp int NULL,
  Objekt nvarchar(50) NULL,
  Akce nvarchar(50) NULL,  
  PHDeviceID NVARCHAR(40) NULL,
  Zpracovano AS CONVERT(bit, CASE WHEN DatZpracovani IS NULL THEN 0 ELSE 1 END),
  CONSTRAINT PK_hdc_ph_JsonData PRIMARY KEY CLUSTERED (ID DESC)
    WITH ( PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
 )


DROP INDEX IF EXISTS EI_hdc_ph_PrijataJsonData_DokladOZ ON dbo._hdc_ph_PrijataJsonData
CREATE NONCLUSTERED INDEX EI_hdc_ph_PrijataJsonData_DokladOZ ON dbo._hdc_ph_PrijataJsonData (IDDoklad)
 WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)



/* 28.10.2023 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'CisloZam') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD CisloZam INT NULL

/* 26.10.2023 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'PosledniChyba') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD PosledniChyba NVARCHAR(255) NULL

/* 27.10.2023 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'Blokovano') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD Blokovano BIT NOT NULL DEFAULT 0

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

/* 23.6.2024 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'Objekt') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD Objekt NVARCHAR(50) NULL
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'Akce') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD Akce NVARCHAR(50) NULL
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'IDEvidRozpOp') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD IDEvidRozpOp INT NULL

/* 24.7.2024 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'Nezpracovat') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD Nezpracovat BIT NOT NULL DEFAULT 0

/* 4.8.2024 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'PHDeviceID') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD PHDeviceID NVARCHAR(40) NULL
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'GUIDIdent') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD GUIDIdent UNIQUEIDENTIFIER DEFAULT newid() NOT NULL

/* 8.10.2024 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'IDMezd') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD IDMezd NVARCHAR(MAX) NULL

/* 10.1.2025 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'Zpracovano') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD Zpracovano AS CONVERT(bit, CASE WHEN DatZpracovani IS NULL THEN 0 ELSE 1 END)

/* 23.1.2025 */
IF COL_LENGTH(N'dbo._hdc_ph_PrijataJsonData', N'UzivIdent') IS NULL ALTER TABLE dbo._hdc_ph_PrijataJsonData ADD UzivIdent NVARCHAR(100) NULL

