CREATE TABLE IF NOT EXISTS `plugin_auth_login_attempts` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `email` varchar(255) DEFAULT NULL,
  `ip` varchar(255) DEFAULT NULL,
  `created` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `email` (`email`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `plugin_auth_permissions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `parent_id` int(10) unsigned DEFAULT NULL,
  `key` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `plugin_auth_roles` (
  `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  `role` varchar(255) DEFAULT NULL,
  `status` enum('T','F') NOT NULL DEFAULT 'T',
  PRIMARY KEY (`id`),
  KEY `status` (`status`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `plugin_auth_roles_permissions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `role_id` int(10) unsigned NOT NULL,
  `permission_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `role_id` (`role_id`,`permission_id`),
  KEY `permission_id` (`permission_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `plugin_auth_users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `role_id` int(10) unsigned NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `password` blob,
  `name` varchar(255) DEFAULT NULL,
  `phone` varchar(255) DEFAULT NULL,
  `created` datetime NOT NULL,
  `last_login` datetime DEFAULT NULL,
  `pswd_modified` datetime DEFAULT NULL,
  `status` enum('T','F') NOT NULL DEFAULT 'T',
  `is_active` enum('T','F') NOT NULL DEFAULT 'F',
  `locked` enum('T','F') NOT NULL DEFAULT 'F',
  `login_token` varchar(255) DEFAULT NULL,
  `ip` varchar(15) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`),
  KEY `role_id` (`role_id`),
  KEY `status` (`status`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `plugin_auth_users_permissions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(10) unsigned NOT NULL,
  `permission_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_id` (`user_id`,`permission_id`),
  KEY `permission_id` (`permission_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

INSERT INTO `plugin_auth_roles` (`id`, `role`, `status`) VALUES
(1, 'Administrator', 'T'),
(2, 'Regular User', 'T');

INSERT INTO `plugin_base_fields` VALUES (NULL, 'plugin_auth_pwd_error_ARRAY_100', 'arrays', 'plugin_auth_pwd_error_ARRAY_100', 'plugin', '2017-11-30 10:27:11');
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `plugin_base_multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Password minimum length should be %u.', 'plugin');

INSERT INTO `plugin_base_fields` VALUES (NULL, 'plugin_auth_pwd_error_ARRAY_101', 'arrays', 'plugin_auth_pwd_error_ARRAY_101', 'plugin', '2017-11-30 10:28:43');
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `plugin_base_multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Password must contain letters only.', 'plugin');

INSERT INTO `plugin_base_fields` VALUES (NULL, 'plugin_auth_pwd_error_ARRAY_105', 'arrays', 'plugin_auth_pwd_error_ARRAY_105', 'plugin', '2017-11-30 10:29:23');
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `plugin_base_multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Password must contain at least one capital letter.', 'plugin');

INSERT INTO `plugin_base_fields` VALUES (NULL, 'plugin_auth_pwd_error_ARRAY_102', 'arrays', 'plugin_auth_pwd_error_ARRAY_102', 'plugin', '2017-11-30 10:29:39');
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `plugin_base_multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Password must contain digits only.', 'plugin');

INSERT INTO `plugin_base_fields` VALUES (NULL, 'plugin_auth_pwd_error_ARRAY_103', 'arrays', 'plugin_auth_pwd_error_ARRAY_103', 'plugin', '2017-11-30 10:30:05');
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `plugin_base_multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Password must contain at least one letter and one digit.', 'plugin');

INSERT INTO `plugin_base_fields` VALUES (NULL, 'plugin_auth_pwd_error_ARRAY_104', 'arrays', 'plugin_auth_pwd_error_ARRAY_104', 'plugin', '2017-11-30 10:30:39');
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `plugin_base_multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Password must contain at least one special character.', 'plugin');