-- Dumping database structure for url_shortener
CREATE DATABASE IF NOT EXISTS `url_shortener` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
USE `url_shortener`;

-- Dumping structure for table url_shortener.tbl_access
CREATE TABLE IF NOT EXISTS `tbl_access` (
  `idAccess` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fiShortcode` varchar(18) NOT NULL DEFAULT '0',
  `dtIpHash` varchar(32) NOT NULL DEFAULT '0',
  `dtTimestamp` varchar(20) NOT NULL DEFAULT '0',
  PRIMARY KEY (`idAccess`),
  KEY `FK_tbl_access_tbl_urls` (`fiShortcode`),
  CONSTRAINT `FK_tbl_access_tbl_urls` FOREIGN KEY (`fiShortcode`) REFERENCES `tbl_urls` (`idShortcode`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=313 DEFAULT CHARSET=utf8mb4;

-- Data exporting was unselected.

-- Dumping structure for table url_shortener.tbl_bans
CREATE TABLE IF NOT EXISTS `tbl_bans` (
  `idBan` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `dtIpHash` varchar(32) NOT NULL,
  `dtTimestamp` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`idBan`),
  UNIQUE KEY `dtIpHash` (`dtIpHash`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;

-- Data exporting was unselected.

-- Dumping structure for table url_shortener.tbl_roles
CREATE TABLE IF NOT EXISTS `tbl_roles` (
  `idRole` int(10) unsigned NOT NULL,
  `dtPermissions` varchar(2048) DEFAULT NULL,
  PRIMARY KEY (`idRole`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Data exporting was unselected.

-- Dumping structure for table url_shortener.tbl_urls
CREATE TABLE IF NOT EXISTS `tbl_urls` (
  `idShortcode` varchar(18) NOT NULL,
  `dtOriginal` varchar(2048) DEFAULT NULL,
  `dtTimestamp` varchar(20) DEFAULT NULL,
  `fiUser` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`idShortcode`),
  KEY `FK_tbl_urls_tbl_users` (`fiUser`),
  CONSTRAINT `FK_tbl_urls_tbl_users` FOREIGN KEY (`fiUser`) REFERENCES `tbl_users` (`idUser`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Data exporting was unselected.

-- Dumping structure for table url_shortener.tbl_users
CREATE TABLE IF NOT EXISTS `tbl_users` (
  `idUser` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `dtApiKey` varchar(100) DEFAULT NULL,
  `dtUsername` varchar(32) NOT NULL DEFAULT '0',
  `dtPassword` varchar(512) DEFAULT NULL,
  `fiRole` int(11) unsigned DEFAULT NULL,
  `dtTimestamp` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`idUser`),
  UNIQUE KEY `dtUsername` (`dtUsername`),
  KEY `FK_tbl_users_tbl_roles` (`fiRole`),
  KEY `dtApiKey` (`dtApiKey`),
  CONSTRAINT `FK_tbl_users_tbl_roles` FOREIGN KEY (`fiRole`) REFERENCES `tbl_roles` (`idRole`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
