commit a238d7a308a13003581f53f074b4a82b7c6e8380 Author: git Date: Fri Jun 6 16:32:57 2025 +0100 Add init_sql.sql diff --git a/init_sql.sql b/init_sql.sql new file mode 100644 index 0000000..3c78f37 --- /dev/null +++ b/init_sql.sql @@ -0,0 +1,45 @@ +CREATE TABLE `TelegramBots` ( + `Name` varchar(255) NOT NULL, + `Token` varchar(255) DEFAULT NULL, + PRIMARY KEY (`Name`)); + +CREATE TABLE `TelegramRecipients` ( + `Name` varchar(255) NOT NULL, + `BotName` varchar(255) DEFAULT NULL, + `Type` enum('Person','Group') DEFAULT 'Person', + `ChatId` double NOT NULL, + UNIQUE KEY `Name` (`Name`,`BotName`), + KEY `BotName` (`BotName`), + CONSTRAINT `TelegramRecipients_ibfk_1` FOREIGN KEY (`BotName`) REFERENCES `TelegramBots` (`Name`) ON DELETE CASCADE ON UPDATE CASCADE +); + CREATE TABLE `TelegramInbox` ( + `Id` int(11) NOT NULL AUTO_INCREMENT, + `RecipientBotName` varchar(255) DEFAULT NULL, + `Sender` varchar(255) DEFAULT NULL, + `Message` varchar(4096) DEFAULT NULL, + `Status` enum('Unread','Read') DEFAULT 'Unread', + `LastUpdated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`Id`), + KEY `RecipientBotName` (`RecipientBotName`), + KEY `Sender` (`Sender`), + CONSTRAINT `TelegramInbox_ibfk_1` FOREIGN KEY (`RecipientBotName`) REFERENCES `TelegramBots` (`Name`), + CONSTRAINT `TelegramInbox_ibfk_2` FOREIGN KEY (`Sender`) REFERENCES `TelegramRecipients` (`Name`) +); + + CREATE TABLE `TelegramOutbox` ( + `Id` int(11) NOT NULL AUTO_INCREMENT, + `SenderBotName` varchar(255) NOT NULL, + `RecipientName` varchar(255) NOT NULL, + `Message` varchar(1024) DEFAULT NULL, + `Format` enum('Text','Markdown') DEFAULT 'Markdown', + `Status` enum('Unsent','Sent','Error') DEFAULT 'Unsent', + `ErrorMsg` varchar(255) DEFAULT NULL, + `LastUpdated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`Id`), + KEY `SenderBotName` (`SenderBotName`), + KEY `RecipientName` (`RecipientName`), + CONSTRAINT `TelegramOutbox_ibfk_1` FOREIGN KEY (`SenderBotName`) REFERENCES `TelegramBots` (`Name`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `TelegramOutbox_ibfk_2` FOREIGN KEY (`RecipientName`) REFERENCES `TelegramRecipients` (`Name`) ON DELETE CASCADE ON UPDATE CASCADE +); + + \ No newline at end of file