Files
nabeh/backend/migrate_billing_tables.php
2026-05-23 03:23:22 +03:00

40 lines
1.5 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
if (php_sapi_name() !== 'cli') {
http_response_code(403);
exit('Access denied.');
}
require_once __DIR__ . '/app/bootstrap.php';
use App\Core\Database;
try {
echo "=== Migrating Billing Tables ===\n";
// 1. Alter company_subscriptions to support new fields and ENUM
Database::execute("
ALTER TABLE company_subscriptions
MODIFY COLUMN status ENUM('active', 'trialing', 'canceled', 'expired', 'past_due', 'pending_approval') DEFAULT 'active';
");
echo "✅ Updated 'status' ENUM in company_subscriptions.\n";
// Add payment_method if it doesn't exist
try {
Database::execute("ALTER TABLE company_subscriptions ADD COLUMN payment_method VARCHAR(50) NULL COMMENT 'paymob, cliq, binance' AFTER payment_gateway");
echo "✅ Added 'payment_method' column.\n";
} catch (\Exception $e) {
echo " Column 'payment_method' may already exist. Skipping.\n";
}
// Add receipt_reference if it doesn't exist
try {
Database::execute("ALTER TABLE company_subscriptions ADD COLUMN receipt_reference VARCHAR(255) NULL COMMENT 'External transaction ID or receipt URL' AFTER payment_method");
echo "✅ Added 'receipt_reference' column.\n";
} catch (\Exception $e) {
echo " Column 'receipt_reference' may already exist. Skipping.\n";
}
echo "=== Migration Completed Successfully! ===\n";
} catch (\Exception $e) {
echo "❌ Migration Failed: " . $e->getMessage() . "\n";
}