UPDATE TBDD_BASECONFIG SET DB_VERSION = '1.9.7.1'
IF NOT EXISTS(SELECT 1 FROM sys.columns 
          WHERE Name = N'ACTIVE'
          AND Object_ID = Object_ID(N'dbo.TBDD_GUI_LANGUAGE'))
BEGIN
    -- Column Exists
	ALTER TABLE TBDD_GUI_LANGUAGE ADD ACTIVE BIT NOT NULL DEFAULT 1
END
ELSE
	PRINT 'COLUMN DOES EXIST'
GO
CREATE TABLE TBDD_USER_CHANGE_LOG(
	GUID			BIGINT		IDENTITY(1,1)	NOT NULL,
	USR_ID			INTEGER	NOT NULL,
	COMMENT			VARCHAR(3000),
CONSTRAINT 	   	[PK_TBDD_USER_CHANGE_LOG] 	PRIMARY KEY(GUID))
GO
USE [DD_ECM]
GO
/****** Object:  Trigger [dbo].[TBDD_USER_AFT_UPD]    Script Date: 30.03.2023 16:54:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [dbo].[TBDD_USER_AFT_UPD_LOG] ON [dbo].[TBDD_USER]
FOR UPDATE
AS
BEGIN 
	DECLARE @USRNAME VARCHAR(50),@LANGUAGE VARCHAR(5),@CHANGED_WHO VARCHAR(100),@USR_ID INTEGER, @COMMENT VARCHAR(1000)
	SELECT  @USRNAME = USERNAME,@LANGUAGE = LANGUAGE,@CHANGED_WHO = CHANGED_WHO,@USR_ID = GUID FROM inserted
	
	IF UPDATE (LANGUAGE) AND @CHANGED_WHO LIKE 'LANG_CHANGE_GUI%'
		BEGIN
			SET @COMMENT = 'USER CHANGED LANGUAGE TO [' + @LANGUAGE + ']'
			INSERT INTO [dbo].[TBDD_USER_CHANGE_LOG]
			   ([USR_ID],[COMMENT])
			VALUES
			   (@USR_ID,@COMMENT)
		END
END		
GO
IF NOT EXISTS(SELECT 1 FROM sys.columns 
          WHERE Name = N'APP_STARTUP_PATH'
          AND Object_ID = Object_ID(N'dbo.TBDD_USER_LOG_IN_ATTEMPT'))
BEGIN
    -- Column Exists
	ALTER TABLE TBDD_USER_LOG_IN_ATTEMPT ADD APP_STARTUP_PATH VARCHAR(1000)
END
