CREATE TABLE asset (
  asset_id int(10) NOT NULL AUTO_INCREMENT,
  asset_name varchar(100) NOT NULL,
  asset_hostname varchar(100) DEFAULT NULL,
  assetclass_id int(10) NOT NULL,
  asset_info text DEFAULT NULL,
  PRIMARY KEY (asset_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO asset (asset_name, assetclass_id) VALUES
('My Computer', 1),
('My Server', 2);


CREATE TABLE assetclass (
  assetclass_id int(10) NOT NULL AUTO_INCREMENT,
  assetclassgroup_id int(10) NOT NULL,
  assetclass_name varchar(100) NOT NULL,
  PRIMARY KEY (assetclass_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO assetclass (assetclassgroup_id, assetclass_name) VALUES
(1, 'PC'),
(2, 'Server');


CREATE TABLE assetclassgroup (
  assetclassgroup_id int(10) NOT NULL AUTO_INCREMENT,
  assetclassgroup_name varchar(100) NOT NULL,
  assetclassgroup_color varchar(6) NOT NULL DEFAULT '000000',
  PRIMARY KEY (assetclassgroup_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO assetclassgroup (assetclassgroup_name, assetclassgroup_color) VALUES
('Workstations', '000000'),
('Servers', '0000CC');


CREATE TABLE location (
  location_id int(10) NOT NULL AUTO_INCREMENT,
  location_name varchar(100) NOT NULL,
  location_parent int(10) NOT NULL DEFAULT 0,
  location_info text DEFAULT NULL,
  location_sort int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (location_id),
  KEY location_sort (location_sort)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO location (location_name, location_parent) VALUES
('Main Office', 0);


CREATE TABLE nat (
  nat_id int(10) NOT NULL AUTO_INCREMENT,
  nat_type int(1) NOT NULL,
  nat_ext int(10) NOT NULL,
  nat_int int(10) NOT NULL,
  PRIMARY KEY (nat_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE node (
  node_id int(10) NOT NULL AUTO_INCREMENT,
  node_ip varchar(45) NOT NULL,
  node_mac varchar(12) NOT NULL,
  node_dns1 varchar(100) DEFAULT NULL,
  node_dns2 varchar(100) DEFAULT NULL,
  subnet_id int(10) NOT NULL,
  asset_id int(10) NOT NULL,
  zone_id int(10) DEFAULT NULL,
  node_info text DEFAULT NULL,
  node_type enum('v4','v6') NOT NULL DEFAULT 'v4',
  PRIMARY KEY (node_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO node (node_ip, node_mac, subnet_id, asset_id) VALUES
('192.168.1.2', '001122334455', 1, 1),
('192.168.1.1', 'aabbccddeeff', 1, 2);


CREATE TABLE subnet (
  subnet_id int(10) NOT NULL AUTO_INCREMENT,
  subnet_address varchar(45) NOT NULL,
  subnet_mask int(2) NOT NULL,
  subnet_dhcp_start varchar(15) DEFAULT NULL,
  subnet_dhcp_end varchar(15) DEFAULT NULL,
  subnet_info text DEFAULT NULL,
  protocol_version tinyint(1) NOT NULL DEFAULT 4,
  ntp_server varchar(45) DEFAULT NULL,
  PRIMARY KEY (subnet_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO subnet (subnet_address, subnet_mask) VALUES
('192.168.0.0', 24);


CREATE TABLE subnetlocation (
  subnetlocation_id int(10) NOT NULL AUTO_INCREMENT,
  subnet_id int(10) NOT NULL,
  location_id int(10) NOT NULL,
  PRIMARY KEY (subnetlocation_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


CREATE TABLE subnetvlan (
  subnetvlan_id int(10) NOT NULL AUTO_INCREMENT,
  subnet_id int(10) NOT NULL,
  vlan_id int(10) NOT NULL,
  PRIMARY KEY (subnetvlan_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO subnetvlan (subnet_id, vlan_id) VALUES
(1, 1);


CREATE TABLE user (
  user_id int(10) NOT NULL AUTO_INCREMENT,
  user_name varchar(100) NOT NULL,
  user_pass varchar(32) NOT NULL,
  user_displayname varchar(100) NOT NULL,
  user_language char(2) NOT NULL DEFAULT 'en',
  user_imagesize int(3) NOT NULL DEFAULT 6,
  user_imagecount int(3) NOT NULL DEFAULT 64,
  user_mac varchar(25) NOT NULL DEFAULT 'xx:xx:xx:xx:xx:xx',
  user_dateformat varchar(10) NOT NULL DEFAULT 'd M Y H:i',
  user_dns1suffix varchar(100) DEFAULT NULL,
  user_dns2suffix varchar(100) DEFAULT NULL,
  user_menu_assets varchar(2) NOT NULL DEFAULT 'on',
  user_menu_assetclasses varchar(2) NOT NULL DEFAULT 'on',
  user_menu_assetclassgroups varchar(2) NOT NULL DEFAULT 'on',
  user_menu_locations varchar(2) NOT NULL DEFAULT 'on',
  user_menu_nodes varchar(2) NOT NULL DEFAULT 'on',
  user_menu_subnets varchar(2) NOT NULL DEFAULT 'on',
  user_menu_users varchar(2) NOT NULL DEFAULT 'on',
  user_menu_vlans varchar(2) NOT NULL DEFAULT 'on',
  user_menu_zones varchar(2) NOT NULL DEFAULT 'on',
  user_tooltips varchar(2) NOT NULL DEFAULT 'on',
  PRIMARY KEY (user_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO user (user_name, user_pass, user_displayname, user_imagesize, user_imagecount, user_mac, user_dateformat, user_menu_assets, user_menu_assetclasses, user_menu_assetclassgroups, user_menu_locations, user_menu_nodes, user_menu_subnets, user_menu_users, user_menu_vlans) VALUES
('admin', '21232f297a57a5a743894a0e4a801fc3', 'administrator', 6, 64, 'xxxxxxxxxxxx', 'd M Y H:i', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on');


CREATE TABLE vlan (
  vlan_id int(10) NOT NULL AUTO_INCREMENT,
  vlan_number int(3) NOT NULL,
  vlan_name varchar(100) NOT NULL,
  vlan_info text DEFAULT NULL,
  PRIMARY KEY (vlan_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO vlan (vlan_number, vlan_name) VALUES
(1, 'DEFAULT_VLAN');


CREATE TABLE zone (
  zone_id int(10) NOT NULL AUTO_INCREMENT,
  zone_soa varchar(40) CHARACTER SET utf8 NOT NULL,
  zone_hostmaster varchar(40) CHARACTER SET utf8 NOT NULL,
  zone_origin varchar(40) CHARACTER SET utf8 NOT NULL,
  zone_ttl_default varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '3D',
  zone_refresh varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '8H',
  zone_retry varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '2H',
  zone_expire varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '4W',
  zone_ttl varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '1D',
  zone_serial int(10) unsigned NOT NULL,
  zone_ns1 varchar(20) CHARACTER SET utf8 NOT NULL,
  zone_ns2 varchar(20) CHARACTER SET utf8 DEFAULT NULL,
  zone_ns3 varchar(20) CHARACTER SET utf8 DEFAULT NULL,
  zone_mx1 varchar(20) CHARACTER SET utf8 DEFAULT NULL,
  zone_mx2 varchar(20) CHARACTER SET utf8 DEFAULT NULL,
  zone_info text CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (zone_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO zone (zone_soa, zone_origin, zone_hostmaster, zone_serial, zone_ns1) VALUES
('ns1.example.com.', 'example.com.', 'hostmaster@example.com', '2023021301', 'ns1.example.com');
