/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DBCONFIG]') AND type in (N'U'))
	CREATE TABLE [dbo].[DBCONFIG](
		[DBNAME][varchar](50) NOT NULL,
		[HOSTNAME] [varchar](50) NOT NULL,
		[PORT] [int] NOT NULL, 
		[ACTIVE] [varchar](1) NOT NULL,
		CONSTRAINT [PK_DBCONFIG] PRIMARY KEY CLUSTERED
		(
			[DBNAME] ASC
		)
	) ON [PRIMARY]
	
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SERVICE]') AND type in (N'U'))
 	CREATE TABLE [dbo].[SERVICE](
		[SERVICENAME] [varchar](50)NOT NULL,
		[URL] [varchar](500) NOT NULL,
		[SEC] [bit] NULL,
		CONSTRAINT [PK_SERVICE] PRIMARY KEY CLUSTERED
		(
			[SERVICENAME] ASC
		)
	) ON [PRIMARY]
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[dbo].[SERVICE]') AND name in (N'SEC'))
	ALTER TABLE [dbo].[SERVICE] ADD [SEC] [bit] NULL
	
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CLIENTTOBS]') AND type in (N'U'))
	CREATE TABLE [dbo].[CLIENTTOBS](
		[CLIENT] [varchar](50) NOT NULL,
		[BS] [varchar](50) NOT NULL,
		CONSTRAINT [PK_CLIENTTOBS] PRIMARY KEY CLUSTERED 
		(
			[CLIENT] ASC
		)
	) ON [PRIMARY]
	
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BSTOOPS]') AND type in (N'U'))
	CREATE TABLE [dbo].[BSTOOPS](
		[BS] [varchar](50) NOT NULL,
		[OPS] [varchar](50) NOT NULL,
		CONSTRAINT [PK_BSTOOPS] PRIMARY KEY CLUSTERED 
		(
			[BS] ASC
		)
	) ON [PRIMARY]
SET ANSI_NULLS OFF
