IF Not EXISTS (SELECT * FROM sys.tables WHERE name = 'PicassoExecuterLog')
BEGIN
	CREATE TABLE [dbo].[PicassoExecuterLog](
		[ID] [int] IDENTITY(1,1) NOT NULL,
		[DateStamp] [datetime] NOT NULL,
		[LogType] [int] NOT NULL,
		[ClassName] [varchar](50) NULL,
		[ProcedureName] [varchar](50) NULL,
		[LogText] [nvarchar](max) NULL,
		[FK_UserIDNumber] [int] NOT NULL,
    [ModuleName] [varchar](500) NULL,
    [SessionId] [varchar](100) NULL,
	 CONSTRAINT [PK_PicassoExecuterLog] PRIMARY KEY CLUSTERED 
	(
		[ID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
	

	ALTER TABLE [dbo].[PicassoExecuterLog] ADD  CONSTRAINT [DF_PicassoExecuterLog_DateStamp]  DEFAULT (getdate()) FOR [DateStamp]

	ALTER TABLE [dbo].[PicassoExecuterLog]  WITH CHECK ADD  CONSTRAINT [FK_PicassoExecuterLog_Personel] FOREIGN KEY([FK_UserIDNumber])
	REFERENCES [dbo].[Personel] ([UserIDNumber])

	ALTER TABLE [dbo].[PicassoExecuterLog] CHECK CONSTRAINT [FK_PicassoExecuterLog_Personel]
END
ELSE
BEGIN
  IF NOT EXISTS
  (
    SELECT SysColumns.Name 
    FROM SysObjects WITH (NOLOCK) 
      INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
      AND SysColumns.Name = 'ModuleName'
      WHERE SysObjects.Name = 'PicassoExecuterLog'
  )
  BEGIN
    ALTER TABLE PicassoExecuterLog ADD ModuleName VARCHAR(500) NULL 
  END
  IF NOT EXISTS
  (
    SELECT SysColumns.Name 
    FROM SysObjects WITH (NOLOCK) 
      INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
      AND SysColumns.Name = 'SessionId'
      WHERE SysObjects.Name = 'PicassoExecuterLog'
  )
  BEGIN
    ALTER TABLE PicassoExecuterLog ADD SessionId VARCHAR(100) NULL 
  END
END

