IF EXISTS (
	SELECT TOP 1 NAME
	FROM SYS.DEFAULT_CONSTRAINTS
	WHERE PARENT_OBJECT_ID = OBJECT_ID('FP_FUNC')
	AND PARENT_COLUMN_ID = (
		SELECT COLUMN_ID
		FROM SYS.COLUMNS
		WHERE NAME = 'FLAG_DESAB_AUTENTICACAO_2F'
		AND OBJECT_ID = OBJECT_ID('FP_FUNC')
	)
)
BEGIN
	DECLARE @COMANDO VARCHAR(500)
	SET @COMANDO = 
	'ALTER TABLE FP_FUNC DROP CONSTRAINT ' + (
		SELECT TOP 1 NAME
		FROM SYS.DEFAULT_CONSTRAINTS
		WHERE PARENT_OBJECT_ID = OBJECT_ID('FP_FUNC')
		AND PARENT_COLUMN_ID = (
			SELECT COLUMN_ID
			FROM SYS.COLUMNS
			WHERE NAME = 'FLAG_DESAB_AUTENTICACAO_2F'
			AND OBJECT_ID = OBJECT_ID('FP_FUNC')
		)
	)
	EXEC (@COMANDO)
END

IF EXISTS (SELECT 1 FROM SYS.COLUMNS WHERE NAME = 'FLAG_DESAB_AUTENTICACAO_2F' AND OBJECT_ID = OBJECT_ID('FP_FUNC'))
BEGIN
	ALTER TABLE FP_FUNC DROP COLUMN FLAG_DESAB_AUTENTICACAO_2F
END

IF NOT EXISTS (SELECT 1 FROM SYS.COLUMNS WHERE NAME = 'FLAG_HABILITA_USO_2FA' AND OBJECT_ID = OBJECT_ID('GLB_USU'))
BEGIN
	ALTER TABLE GLB_USU ADD FLAG_HABILITA_USO_2FA INT NOT NULL DEFAULT 0
END