Skip to content

Commit

Permalink
fix: forgot to add new tables
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTipo01 committed Oct 8, 2022
1 parent f0b539f commit c6b2417
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
)

const (
tblMessages = "CREATE TABLE IF NOT EXISTS `messages` ( `guildID` varchar(20) NOT NULL DEFAULT '0', `channelID` varchar(20) NOT NULL DEFAULT '0', `messageID` varchar(20) CHARACTER SET utf8mb4 NOT NULL, `authorID` varchar(20) DEFAULT NULL, `message` longtext CHARACTER SET utf8mb4 NOT NULL CHECK (json_valid(`message`)), `deleted` tinyint(1) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`messageID`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblUsers = "CREATE TABLE IF NOT EXISTS `users` ( `id` varchar(20) NOT NULL, `nickname` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblServers = "CREATE TABLE IF NOT EXISTS `servers` ( `id` varchar(20) NOT NULL, `name` varchar(100) NOT NULL, `model` longtext NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblChannels = "CREATE TABLE IF NOT EXISTS `channels` ( `id` varchar(20) NOT NULL, `name` text NOT NULL DEFAULT '', `serverId` varchar(20) NOT NULL, PRIMARY KEY (`id`), KEY `FK_channels_server` (`serverId`), CONSTRAINT `FK_channels_server` FOREIGN KEY (`serverId`) REFERENCES `servers` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblPings = "CREATE TABLE IF NOT EXISTS `pings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `menzionatoreId` varchar(20) NOT NULL, `menzionatoId` varchar(20) NOT NULL, `channelId` varchar(20) NOT NULL, `serverId` varchar(20) NOT NULL, `timestamp` datetime NOT NULL, `messageId` varchar(20) NOT NULL, PRIMARY KEY (`id`), KEY `FK_pings_channels` (`channelId`), KEY `FK_pings_server` (`serverId`), KEY `FK_pings_users` (`menzionatoreId`), KEY `FK_pings_users_2` (`menzionatoId`), KEY `messageId` (`messageId`), CONSTRAINT `FK_pings_channels` FOREIGN KEY (`channelId`) REFERENCES `channels` (`id`), CONSTRAINT `FK_pings_messages` FOREIGN KEY (`messageId`) REFERENCES `messages` (`messageID`), CONSTRAINT `FK_pings_server` FOREIGN KEY (`serverId`) REFERENCES `servers` (`id`), CONSTRAINT `FK_pings_users` FOREIGN KEY (`menzionatoreId`) REFERENCES `users` (`id`), CONSTRAINT `FK_pings_users_2` FOREIGN KEY (`menzionatoId`) REFERENCES `users` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8mb4;"
tblConfig = "CREATE TABLE IF NOT EXISTS `config` ( `id` int(11) NOT NULL AUTO_INCREMENT, `guildID` varchar(20) CHARACTER SET utf8mb4 NOT NULL DEFAULT '0', `channelID` varchar(20) CHARACTER SET utf8mb4 NOT NULL DEFAULT '0', `channelToID` varchar(20) CHARACTER SET utf8mb4 NOT NULL DEFAULT '0', `offset` int(11) DEFAULT 0, PRIMARY KEY (`id`), KEY `FK_config_server` (`guildID`), KEY `FK_config_channels` (`channelID`), KEY `FK_config_channels_2` (`channelToID`), CONSTRAINT `FK_config_channels` FOREIGN KEY (`channelID`) REFERENCES `channels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_config_channels_2` FOREIGN KEY (`channelToID`) REFERENCES `channels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_config_server` FOREIGN KEY (`guildID`) REFERENCES `servers` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;"
tblMessages = "CREATE TABLE IF NOT EXISTS `messages` ( `guildID` varchar(20) NOT NULL DEFAULT '0', `channelID` varchar(20) NOT NULL DEFAULT '0', `messageID` varchar(20) CHARACTER SET utf8mb4 NOT NULL, `authorID` varchar(20) DEFAULT NULL, `message` longtext CHARACTER SET utf8mb4 NOT NULL CHECK (json_valid(`message`)), `deleted` tinyint(1) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`messageID`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblUsers = "CREATE TABLE IF NOT EXISTS `users` ( `id` varchar(20) NOT NULL, `nickname` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblServers = "CREATE TABLE IF NOT EXISTS `servers` ( `id` varchar(20) NOT NULL, `name` varchar(100) NOT NULL, `model` longtext NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblChannels = "CREATE TABLE IF NOT EXISTS `channels` ( `id` varchar(20) NOT NULL, `name` text NOT NULL DEFAULT '', `serverId` varchar(20) NOT NULL, PRIMARY KEY (`id`), KEY `FK_channels_server` (`serverId`), CONSTRAINT `FK_channels_server` FOREIGN KEY (`serverId`) REFERENCES `servers` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblPings = "CREATE TABLE IF NOT EXISTS `pings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `menzionatoreId` varchar(20) NOT NULL, `menzionatoId` varchar(20) NOT NULL, `channelId` varchar(20) NOT NULL, `serverId` varchar(20) NOT NULL, `timestamp` datetime NOT NULL, `messageId` varchar(20) NOT NULL, PRIMARY KEY (`id`), KEY `FK_pings_channels` (`channelId`), KEY `FK_pings_server` (`serverId`), KEY `FK_pings_users` (`menzionatoreId`), KEY `FK_pings_users_2` (`menzionatoId`), KEY `messageId` (`messageId`), CONSTRAINT `FK_pings_channels` FOREIGN KEY (`channelId`) REFERENCES `channels` (`id`), CONSTRAINT `FK_pings_messages` FOREIGN KEY (`messageId`) REFERENCES `messages` (`messageID`), CONSTRAINT `FK_pings_server` FOREIGN KEY (`serverId`) REFERENCES `servers` (`id`), CONSTRAINT `FK_pings_users` FOREIGN KEY (`menzionatoreId`) REFERENCES `users` (`id`), CONSTRAINT `FK_pings_users_2` FOREIGN KEY (`menzionatoId`) REFERENCES `users` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8mb4;"
tblConfig = "CREATE TABLE IF NOT EXISTS `config` ( `id` int(11) NOT NULL AUTO_INCREMENT, `guildID` varchar(20) CHARACTER SET utf8mb4 NOT NULL DEFAULT '0', `channelID` varchar(20) CHARACTER SET utf8mb4 NOT NULL DEFAULT '0', `channelToID` varchar(20) CHARACTER SET utf8mb4 NOT NULL DEFAULT '0', `offset` int(11) DEFAULT 0, PRIMARY KEY (`id`), KEY `FK_config_server` (`guildID`), KEY `FK_config_channels` (`channelID`), KEY `FK_config_channels_2` (`channelToID`), CONSTRAINT `FK_config_channels` FOREIGN KEY (`channelID`) REFERENCES `channels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_config_channels_2` FOREIGN KEY (`channelToID`) REFERENCES `channels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_config_server` FOREIGN KEY (`guildID`) REFERENCES `servers` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;"
tblPollState = "CREATE TABLE IF NOT EXISTS `pollState` ( `messageID` varchar(20) NOT NULL, `userAnswered` text NOT NULL DEFAULT '', `question` text NOT NULL, `groupName` varchar(255) NOT NULL, `guildID` varchar(20) NOT NULL, `userAnsweredPositive` text NOT NULL DEFAULT '', PRIMARY KEY (`messageID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
tblPollsGroups = "CREATE TABLE IF NOT EXISTS `pollsGroup` ( `serverID` varchar(20) NOT NULL, `name` varchar(255) NOT NULL, `userIDs` text NOT NULL DEFAULT '', `createdBy` varchar(20) NOT NULL, PRIMARY KEY (`serverID`,`name`), CONSTRAINT `FK_groups_servers` FOREIGN KEY (`serverID`) REFERENCES `servers` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
)

// Executes a simple query given a DB
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func init() {
}

// Initialize tables
execQuery(tblMessages, tblUsers, tblServers, tblChannels, tblPings, tblConfig)
execQuery(tblMessages, tblUsers, tblServers, tblChannels, tblPings, tblConfig, tblPollState, tblPollsGroups)

// And add the everyone user to the table, as we use that for logging @everyone and @here
_, err = db.Exec("INSERT IGNORE INTO users (id, nickname) VALUES(?, ?)", "everyone", "everyone")
Expand Down

0 comments on commit c6b2417

Please sign in to comment.