USE [Arm-Init]
GO
/****** Object:  Table [dbo].[BusinessSystems] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[BusinessSystems](
	[Thumbprint] [nvarchar](300) NOT NULL,
	[TimeStamp] [datetime2](7)DEFAULT CURRENT_TIMESTAMP,
	[InternetAddress] [nvarchar](300) NOT NULL,
	[SysName] [nvarchar](300) NOT NULL,
	[TlsServer] [nvarchar](300) NOT NULL,
	[ClientType] [int] NOT NULL,
 CONSTRAINT [PK_BUSINESSSYSTEMS] PRIMARY KEY CLUSTERED 
(
	[Thumbprint] 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
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[BusinessSystems2Token] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BusinessSystems2Token](
	[TokenId] [int] NOT NULL,
	[BusinessSystemId] [nvarchar](300) NOT NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Certificates] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Certificates](
	[Id] [int] IDENTITY(1,1),
	[Thumbprint] [nvarchar](1000) NOT NULL,
	[TimeStamp] [datetime2](7) DEFAULT CURRENT_TIMESTAMP,
	[RawData] [nvarchar](max) NOT NULL,
	[Serial] [nvarchar](300) NOT NULL,
	[StartDate] [datetime2](7) NOT NULL,
	[EndDate] [datetime2](7) NOT NULL,
	[CommonName] [nvarchar](1000) NOT NULL,
	[Issuer] [nvarchar](1000) NOT NULL,
	[PublicKey] [nvarchar](500) NOT NULL,
	[Archived] [bit] NOT NULL,
	[Type] [int] NOT NULL,
 CONSTRAINT [PK_CERTIFICATES] 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]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Certificates2Token] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Certificates2Token](
	[TokenId] [int] NOT NULL,
	[CertId] [int] NOT NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[FirmwaresUpdate] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[FirmwaresUpdate](
	[Id] [int] IDENTITY(1,1),
	[TokenId] [int] NOT NULL,
	[ArmVersion] [nvarchar](100) NOT NULL,
	[TimeStamp] [datetime2](7) DEFAULT CURRENT_TIMESTAMP,
 CONSTRAINT [PK_FIRMWARESUPDATE] 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]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[GenerateAdminCertRequests] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[GenerateAdminCertRequests](
	[Id] [int] IDENTITY(1,1),
	[TokenSerial] [nvarchar](300) NOT NULL,
	[RawRequestData] [nvarchar](max) NOT NULL,
	[PublicKey] [nvarchar](500) NOT NULL,
	[TimeStamp] [datetime2](7) DEFAULT CURRENT_TIMESTAMP,
	[ArmVersion] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_GENERATEADMINCERTREQUESTS] 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]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ImportAdminCertificates] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ImportAdminCertificates](
	[Id] [int] IDENTITY(1,1),
	[TokenSerial] [nvarchar](300) NOT NULL,
	[AdminCertId] [int] NOT NULL,
	[TimeStamp] [datetime2](7) DEFAULT CURRENT_TIMESTAMP,
	[ArmVersion] [nvarchar](100) NOT NULL,
	[RequestId] [int] NOT NULL,
 CONSTRAINT [PK_IMPORTADMINCERTIFICATES] 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]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Initializations] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Initializations](
	[Id] [int] IDENTITY(1,1),
	[TokenId] [int] NOT NULL,
	[AdminTokenSerial] [nvarchar](300) NULL,
	[AdminCertId] [int] NULL,
	[ArmVersion] [nvarchar](100) NOT NULL,
	[TimeStamp] [datetime2](7) DEFAULT CURRENT_TIMESTAMP,
 CONSTRAINT [PK_INITIALIZATIONS] 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]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Tokens] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Tokens](
	[Id] [int] IDENTITY(1,1),
	[Serial] [nvarchar](300) NOT NULL,
	[Firmware1] [nvarchar](1000) NULL,
	[Firmware2] [nvarchar](1000) NULL,
	[Firmware3] [nvarchar](1000) NULL,
	[Firmware4] [nvarchar](1000) NULL,
	[ProfilesCount] [int] NOT NULL,
 CONSTRAINT [PK_TOKENS] 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]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[BusinessSystems2Token]  WITH CHECK ADD  CONSTRAINT [BusinessSystems2Token_fk0] FOREIGN KEY([TokenId])
REFERENCES [dbo].[Tokens] ([Id])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[BusinessSystems2Token] CHECK CONSTRAINT [BusinessSystems2Token_fk0]
GO
ALTER TABLE [dbo].[BusinessSystems2Token]  WITH CHECK ADD  CONSTRAINT [BusinessSystems2Token_fk1] FOREIGN KEY([BusinessSystemId])
REFERENCES [dbo].[BusinessSystems] ([Thumbprint])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[BusinessSystems2Token] CHECK CONSTRAINT [BusinessSystems2Token_fk1]
GO
ALTER TABLE [dbo].[Certificates2Token]  WITH CHECK ADD  CONSTRAINT [Certificates2Token_fk0] FOREIGN KEY([TokenId])
REFERENCES [dbo].[Tokens] ([Id])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[Certificates2Token] CHECK CONSTRAINT [Certificates2Token_fk0]
GO
ALTER TABLE [dbo].[Certificates2Token]  WITH CHECK ADD  CONSTRAINT [Certificates2Token_fk1] FOREIGN KEY([CertId])
REFERENCES [dbo].[Certificates] ([Id])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[Certificates2Token] CHECK CONSTRAINT [Certificates2Token_fk1]
GO
ALTER TABLE [dbo].[FirmwaresUpdate]  WITH CHECK ADD  CONSTRAINT [FirmwaresUpdate_fk0] FOREIGN KEY([TokenId])
REFERENCES [dbo].[Tokens] ([Id])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[ImportAdminCertificates]  WITH CHECK ADD  CONSTRAINT [ImportAdminCertificates_fk0] FOREIGN KEY([AdminCertId])
REFERENCES [dbo].[Certificates] ([Id])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[ImportAdminCertificates] CHECK CONSTRAINT [ImportAdminCertificates_fk0]
GO
ALTER TABLE [dbo].[ImportAdminCertificates]  WITH CHECK ADD  CONSTRAINT [ImportAdminCertificates_fk1] FOREIGN KEY([RequestId])
REFERENCES [dbo].[GenerateAdminCertRequests] ([Id])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[ImportAdminCertificates] CHECK CONSTRAINT [ImportAdminCertificates_fk1]
GO
ALTER TABLE [dbo].[Initializations]  WITH CHECK ADD  CONSTRAINT [Initializations_fk0] FOREIGN KEY([TokenId])
REFERENCES [dbo].[Tokens] ([Id])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[Initializations] CHECK CONSTRAINT [Initializations_fk0]
GO
ALTER TABLE [dbo].[Initializations]  WITH CHECK ADD  CONSTRAINT [Initializations_fk1] FOREIGN KEY([AdminCertId])
REFERENCES [dbo].[Certificates] ([Id])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[Initializations] CHECK CONSTRAINT [Initializations_fk1]
GO
