/* Create MySql tables at installation
 USE AS
  mysql < createscript
*/
create database if not exists opengatem;
use opengatem;
create table if not exists macaddrs(
	macAddress CHAR(18),
	status CHAR(1),
	device TINYTEXT,
	userId TINYTEXT,
	extraId TINYTEXT,
	mailAddress TINYTEXT,
	entryDate DATETIME,
	renewDate DATETIME,
	limitDate DATETIME);

create table if not exists sessionmd(
	macAddress CHAR(18),
	gatewayName TINYTEXT,
	openTime DATETIME,
	closeTime DATETIME);

create table if not exists macippair(
	macAddress CHAR(18),
	ipAddress TINYTEXT,
	findTime DATETIME);

create table if not exists macmodify(
	userId TINYTEXT,
	extraId TINYTEXT,
	macAddress CHAR(18),
	modifyType CHAR(1),
	modifyDate DATETIME);

create table if not exists nicvendors(
	oui CHAR(8),
	org TINYTEXT);

create table if not exists watchlist(
	macAddress CHAR(18),
	reporting CHAR(1),
	memo TINYTEXT);

create or replace view sessionview as select
	userId,
	extraId,
	macaddrs.macAddress,
	device,
	openTime,
	closeTime,
	gatewayName 
	from macaddrs,sessionmd 
	where macaddrs.macAddress=sessionmd.macAddress 
	and entryDate<openTime and openTime<limitDate;

