Files
Siro/backend/bot/social_media_bot/schema.sql
T

44 lines
1.9 KiB
SQL

-- Social Media Bot Schema
CREATE TABLE IF NOT EXISTS `social_accounts` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`platform` ENUM('facebook', 'instagram') NOT NULL,
`username` VARCHAR(100) NOT NULL,
`status` ENUM('active', 'restricted', 'banned') DEFAULT 'active',
`total_posts` INT DEFAULT 0,
`total_comments` INT DEFAULT 0,
`last_active` DATETIME NULL,
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS `social_tasks` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`account_id` INT NULL, -- NULL if any available account can take it
`platform` ENUM('facebook', 'instagram') NOT NULL,
`type` ENUM('join_group', 'read_posts', 'post_comment', 'share_link') NOT NULL,
`target_url` VARCHAR(500) NULL, -- URL of the group or post
`prompt_context` TEXT NULL, -- Context for Gemini to generate the comment
`generated_comment` TEXT NULL, -- The comment generated by Gemini
`status` ENUM('pending', 'in_progress', 'completed', 'failed') DEFAULT 'pending',
`error_message` TEXT NULL,
`scheduled_at` DATETIME NULL,
`completed_at` DATETIME NULL,
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`account_id`) REFERENCES `social_accounts`(`id`) ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS `social_logs` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`task_id` INT NULL,
`account_id` INT NULL,
`log_level` ENUM('info', 'warning', 'error') DEFAULT 'info',
`message` TEXT NOT NULL,
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`task_id`) REFERENCES `social_tasks`(`id`) ON DELETE SET NULL,
FOREIGN KEY (`account_id`) REFERENCES `social_accounts`(`id`) ON DELETE SET NULL
);
-- Insert dummy account for testing
INSERT IGNORE INTO `social_accounts` (`platform`, `username`, `status`) VALUES ('facebook', 'test_bot_1', 'active');