-- DB update 2022_03_01_00 -> 2022_04_19_00
DROP PROCEDURE IF EXISTS `updateDb`;
DELIMITER //
CREATE PROCEDURE updateDb ()
proc:BEGIN DECLARE OK VARCHAR(100) DEFAULT 'FALSE';
SELECT COUNT(*) INTO @COLEXISTS
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'version_db_characters' AND COLUMN_NAME = '2022_03_01_00';
IF @COLEXISTS = 0 THEN LEAVE proc; END IF;
START TRANSACTION;
ALTER TABLE version_db_characters CHANGE COLUMN 2022_03_01_00 2022_04_19_00 bit;
SELECT sql_rev INTO OK FROM version_db_characters WHERE sql_rev = '1644531230030579700'; IF OK <> 'FALSE' THEN LEAVE proc; END IF;
--
-- START UPDATING QUERIES
--

INSERT INTO `version_db_characters` (`sql_rev`) VALUES ('1644531230030579700');

DROP TABLE IF EXISTS `mail_server_character`;
CREATE TABLE IF NOT EXISTS `mail_server_character` (
  `guid` INT UNSIGNED NOT NULL,
  `mailId` INT UNSIGNED NOT NULL,
  PRIMARY KEY (`guid`, `mailId`)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4;

DROP TABLE IF EXISTS `mail_server_template`;
CREATE TABLE IF NOT EXISTS `mail_server_template` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `reqLevel` TINYINT UNSIGNED NOT NULL DEFAULT '0',
  `reqPlayTime` INT UNSIGNED NOT NULL DEFAULT '0',
  `moneyA` INT UNSIGNED NOT NULL DEFAULT '0',
  `moneyH` INT UNSIGNED NOT NULL DEFAULT '0',
  `itemA` INT UNSIGNED NOT NULL DEFAULT '0',
  `itemCountA` INT UNSIGNED NOT NULL DEFAULT '0',
  `itemH` INT UNSIGNED NOT NULL DEFAULT '0',
  `itemCountH` INT UNSIGNED NOT NULL DEFAULT '0',
  `subject` TEXT NOT NULL,
  `body` TEXT NOT NULL,
  `active` TINYINT UNSIGNED NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4;

--
-- END UPDATING QUERIES
--
UPDATE version_db_characters SET date = '2022_04_19_00' WHERE sql_rev = '1644531230030579700';
COMMIT;
END //
DELIMITER ;
CALL updateDb();
DROP PROCEDURE IF EXISTS `updateDb`;
