Deploy: 2026-07-15 05:08:07
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
http_response_code(403);
|
||||
exit('Access denied.');
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/app/bootstrap.php';
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
try {
|
||||
$pdo = Database::getConnection();
|
||||
|
||||
echo "=== Running Database Migrations: WhatsApp Cloud API Integration ===\n";
|
||||
|
||||
// 1. Create meta_cloud_sessions table
|
||||
$createSessionsTableSql = "
|
||||
CREATE TABLE IF NOT EXISTS `meta_cloud_sessions` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`company_id` INT NOT NULL,
|
||||
`phone_number_id` VARCHAR(50) NOT NULL COMMENT 'Meta Phone Number ID',
|
||||
`waba_id` VARCHAR(50) NOT NULL COMMENT 'WhatsApp Business Account ID',
|
||||
`access_token` VARCHAR(1024) NOT NULL COMMENT 'Encrypted Meta Access Token',
|
||||
`display_phone` VARCHAR(20) DEFAULT NULL COMMENT 'Display phone number',
|
||||
`status` ENUM('active', 'inactive', 'pending') DEFAULT 'pending',
|
||||
`verify_token` VARCHAR(100) DEFAULT NULL COMMENT 'Webhook verification token',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
|
||||
INDEX `idx_meta_company` (`company_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
";
|
||||
Database::execute($createSessionsTableSql);
|
||||
echo "✅ Table 'meta_cloud_sessions' verified/created.\n";
|
||||
|
||||
// 2. Create message_templates table
|
||||
$createTemplatesTableSql = "
|
||||
CREATE TABLE IF NOT EXISTS `message_templates` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`company_id` INT NOT NULL,
|
||||
`meta_template_id` VARCHAR(100) DEFAULT NULL,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`language` VARCHAR(10) DEFAULT 'ar',
|
||||
`category` ENUM('marketing', 'utility', 'authentication') DEFAULT 'utility',
|
||||
`header_type` ENUM('none', 'text', 'image', 'video', 'document') DEFAULT 'none',
|
||||
`header_content` TEXT DEFAULT NULL,
|
||||
`body_text` TEXT NOT NULL,
|
||||
`footer_text` VARCHAR(60) DEFAULT NULL,
|
||||
`buttons` JSON DEFAULT NULL,
|
||||
`status` ENUM('draft', 'pending', 'approved', 'rejected') DEFAULT 'draft',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
|
||||
INDEX `idx_template_company` (`company_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
";
|
||||
Database::execute($createTemplatesTableSql);
|
||||
echo "✅ Table 'message_templates' verified/created.\n";
|
||||
|
||||
echo "Migration completed successfully!\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "❌ Migration error: " . $e->getMessage() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user