UPDATE TBDD_BASECONFIG SET DB_VERSION = '1.9.8.7';
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDMI_ITEM_FILES](
	[GUID] [bigint] IDENTITY(1,1) NOT NULL,
	[REFERENCE_GUID] [varchar](250) NOT NULL,
	[ITEM_VALUE] [varbinary](max) NOT NULL,
	[ORG_FILENAME] [varchar](256) NOT NULL,
	[MIME_TYPE] [varchar](256) NOT NULL,
	[GROUP_INDEX] [int] NOT NULL,
	[CREATED_WHEN] [datetime] NOT NULL,
	[CREATED_WHO] [varchar](100) NULL,
	[CHANGED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [varchar](100) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[TBEDMI_ITEM_FILES] ADD  CONSTRAINT [DF_TBEDMI_ITEM_FILES_GROUP_INDEX]  DEFAULT ((0)) FOR [GROUP_INDEX]
GO
ALTER TABLE [dbo].[TBEDMI_ITEM_FILES] ADD  CONSTRAINT [DF_TBEDMI_ITEM_FILES_CREATED_WHEN]  DEFAULT (getdate()) FOR [CREATED_WHEN]
GO
CREATE TRIGGER [dbo].[TBEDMI_ITEM_FILES_AFT_UPD] ON [dbo].[TBEDMI_ITEM_FILES]
FOR UPDATE
AS
BEGIN 
	UPDATE TBEDMI_ITEM_FILES SET CHANGED_WHEN = GETDATE() FROM INSERTED WHERE TBEDMI_ITEM_FILES.GUID = INSERTED.GUID
END		
GO
ALTER TABLE [dbo].[TBEDMI_ITEM_FILES] ENABLE TRIGGER [TBEDMI_ITEM_FILES_AFT_UPD]
GO
--################################# ZUGFERD #######################################################
CREATE TABLE [dbo].[TBDD_ZUGFERD_XML_ITEMS](
	[GUID] [int]		IDENTITY(1,1) NOT NULL,
	[SPECIFICATION]		NVARCHAR(50) NOT NULL,
	ITEM_TYPE			int NOT NULL,
	[XML_PATH]			NVARCHAR(500) NOT NULL,
	[DESCRIPTION]		NVARCHAR(500) NOT NULL,
	[TABLE_NAME]		NVARCHAR(100) NOT NULL,
	[TABLE_COLUMN]		NVARCHAR(100) NOT NULL,
	[COMMENT]			NVARCHAR(500),
	[ACTIVE]			BIT,
	[IS_REQUIRED]		BIT		NOT NULL DEFAULT 0,
	[IS_GROUPED]		BIT		NOT NULL DEFAULT 0,
	[GROUP_SCOPE]		NVARCHAR(50) NULL,
	[ADDED_WHEN]		DATETIME	NOT NULL,
	[ADDED_WHO]			NVARCHAR(50),
	[CHANGED_WHEN]		DATETIME,
	[CHANGED_WHO]		NVARCHAR(50),
 CONSTRAINT [PK_TBDD_ZUGFERD_XML_ITEMS] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TBDD_ZUGFERD_XML_ITEMS] ADD  CONSTRAINT [DF_TBDD_ZUGFERD_XML_ITEMS_SPECIFICATION]  DEFAULT (N'DEFAULT') FOR [SPECIFICATION]
GO
ALTER TABLE [dbo].[TBDD_ZUGFERD_XML_ITEMS] ADD  CONSTRAINT [DF_TBDD_ZUGFERD_XML_ITEMS_ACTIVE]  DEFAULT ((1)) FOR [ACTIVE]
GO
ALTER TABLE [dbo].[TBDD_ZUGFERD_XML_ITEMS] ADD  CONSTRAINT [DF_TBDD_ZUGFERD_XML_ITEMS_GROUP_SCOPE]  DEFAULT (N'DEFAULT') FOR [GROUP_SCOPE]
GO
ALTER TABLE [dbo].[TBDD_ZUGFERD_XML_ITEMS] ADD  CONSTRAINT [DF_TBDD_ZUGFERD_XML_ITEMS_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBDD_ZUGFERD_XML_ITEMS] ADD  CONSTRAINT [DF_TBDD_ZUGFERD_XML_ITEMS_ADDED_WHO]  DEFAULT (N'EDM-Admin') FOR [ADDED_WHO]
GO
ALTER TABLE [dbo].[TBDD_ZUGFERD_XML_ITEMS] ADD	CONSTRAINT DF_TBDD_ZUGFERD_XML_ITEMS_ITEM_TYP DEFAULT 0 FOR ITEM_TYPE
GO


ALTER TABLE dbo.TBDD_ZUGFERD_XML_ITEMS ADD
	EN16931_ID nvarchar(50) NULL
GO