Skip to content

Commit

Permalink
Updated migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Znote committed Nov 15, 2020
1 parent 216ff40 commit 2dc848f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
21 changes: 20 additions & 1 deletion data/migrations/27.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
function onUpdateDatabase()
return false
print("> Updating database to version 27 (guildhalls, guild banks #2213)")
db.query("ALTER TABLE `houses` ADD `type` ENUM('HOUSE', 'GUILDHALL') NOT NULL DEFAULT 'HOUSE' AFTER `id`")
db.query("ALTER TABLE `guilds` ADD `balance` bigint(20) UNSIGNED NOT NULL DEFAULT '0'")
db.query([[
CREATE TABLE IF NOT EXISTS `guild_transactions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`guild_id` int(11) NOT NULL,
`guild_associated` int(11) DEFAULT NULL,
`player_associated` int(11) DEFAULT NULL,
`type` ENUM('DEPOSIT', 'WITHDRAW') NOT NULL,
`category` ENUM ('OTHER', 'RENT', 'MATERIAL', 'SERVICES', 'REVENUE', 'CONTRIBUTION') NOT NULL DEFAULT 'OTHER',
`balance` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`time` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`guild_associated`) REFERENCES `guilds`(`id`) ON DELETE SET NULL,
FOREIGN KEY (`player_associated`) REFERENCES `players`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB;
]])
return true
end
3 changes: 3 additions & 0 deletions data/migrations/28.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false
end
19 changes: 18 additions & 1 deletion schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,29 @@ CREATE TABLE IF NOT EXISTS `guilds` (
`name` varchar(255) NOT NULL,
`ownerid` int(11) NOT NULL,
`creationdata` int(11) NOT NULL,
`balance` bigint(20) unsigned NOT NULL DEFAULT '0',
`motd` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY (`name`),
UNIQUE KEY (`ownerid`),
FOREIGN KEY (`ownerid`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

CREATE TABLE IF NOT EXISTS `guild_transactions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`guild_id` int(11) NOT NULL,
`guild_associated` int(11) DEFAULT NULL,
`player_associated` int(11) DEFAULT NULL,
`type` ENUM('DEPOSIT', 'WITHDRAW') NOT NULL,
`category` ENUM ('OTHER', 'RENT', 'MATERIAL', 'SERVICES', 'REVENUE', 'CONTRIBUTION') NOT NULL DEFAULT 'OTHER',
`balance` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`time` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`guild_associated`) REFERENCES `guilds`(`id`) ON DELETE SET NULL,
FOREIGN KEY (`player_associated`) REFERENCES `players`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `guild_invites` (
`player_id` int(11) NOT NULL DEFAULT '0',
`guild_id` int(11) NOT NULL DEFAULT '0',
Expand Down Expand Up @@ -207,6 +223,7 @@ CREATE TABLE IF NOT EXISTS `houses` (
`highest_bidder` int(11) NOT NULL DEFAULT '0',
`size` int(11) NOT NULL DEFAULT '0',
`beds` int(11) NOT NULL DEFAULT '0',
`type` ENUM('HOUSE', 'GUILDHALL') NOT NULL DEFAULT 'HOUSE',
PRIMARY KEY (`id`),
KEY `owner` (`owner`),
KEY `town_id` (`town_id`)
Expand Down Expand Up @@ -349,7 +366,7 @@ CREATE TABLE IF NOT EXISTS `towns` (
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '26'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');
INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '27'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');

DROP TRIGGER IF EXISTS `ondelete_players`;
DROP TRIGGER IF EXISTS `oncreate_guilds`;
Expand Down

0 comments on commit 2dc848f

Please sign in to comment.