/*
 * 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.
 */

CREATE TABLE IF NOT EXISTS account(
			creationdate datetime NULL,
			openbalance decimal(12, 2) NULL,
			logoutcount integer NOT NULL,
			balance decimal(12, 2) NULL,
			accountid integer AUTO_INCREMENT NOT NULL,
			lastlogin datetime NULL,
			logincount integer NOT NULL,
			profile_userid varchar(250) NULL,
			PRIMARY KEY (accountid));

CREATE TABLE IF NOT EXISTS accountprofile(
			address varchar(250) NULL,
			password varchar(250) NULL,
			userid varchar(250) NOT NULL,
			email varchar(250) NULL,
			creditcard varchar(250) NULL,
			fullname varchar(250) NULL,
			PRIMARY KEY (userid));

/* quote is a reserved word in MySQL. A word following a period in a qualified
 * name is treated as an identifier.
 *
 * http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
 */
CREATE TABLE IF NOT EXISTS stocktraderdb.quote(
			low decimal(12, 2) NULL,
			open1 decimal(12, 2) NULL,
			volume float NOT NULL,
			price decimal(12, 2) NULL,
			high decimal(12, 2) NULL,
			companyname varchar(250) NULL,
			symbol varchar(250) NOT NULL,
			change1 float NOT NULL,
			PRIMARY KEY (symbol));

CREATE TABLE IF NOT EXISTS holding(
			purchaseprice decimal(12, 2) NULL,
			holdingid integer AUTO_INCREMENT NOT NULL,
			quantity float NOT NULL,
			purchasedate datetime NULL,
			account_accountid int NULL,
			quote_symbol varchar(250) NULL,
			PRIMARY KEY (holdingid));

CREATE TABLE IF NOT EXISTS orders(
			orderfee decimal(12, 2) NULL,
			completiondate datetime NULL,
			ordertype varchar(250) NULL,
			orderstatus varchar(250) NULL,
			price decimal(12, 2) NULL,
			quantity float NOT NULL,
			opendate datetime NULL,
			orderid integer AUTO_INCREMENT NOT NULL,
			account_accountid integer NULL,
			quote_symbol varchar(250) NULL,
			holding_holdingid integer NULL,
			PRIMARY KEY (orderid));

CREATE TABLE IF NOT EXISTS dbconfig(
			dbname varchar(50) NOT NULL,
			hostname varchar(50) NOT NULL,
			port integer NOT NULL,
			active varchar(1) NOT NULL,
			PRIMARY KEY (dbname));

CREATE TABLE IF NOT EXISTS service(
			servicename varchar(50) NOT NULL,
			url varchar(500) NOT NULL,
			PRIMARY KEY (servicename));

CREATE TABLE IF NOT EXISTS clienttobs(
			client varchar(50) NOT NULL,
			bs varchar(50) NOT NULL,
			PRIMARY KEY (client));

CREATE TABLE IF NOT EXISTS bstoops(
			bs varchar(50) NOT NULL,
			ops varchar(50) NOT NULL,
			PRIMARY KEY (bs));

