<?php

require __DIR__ . '/vendor/autoload.php';

$app = require_once __DIR__ . '/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

// Check and add service_id to sales_dashboard
if (!Schema::hasColumn('sales_dashboard', 'service_id')) {
    DB::statement('ALTER TABLE sales_dashboard ADD FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE SET NULL');
    echo "Added service_id to sales_dashboard\n";
} else {
    echo "service_id already exists in sales_dashboard\n";
}

// Check and add service_id to invoice_items
if (!Schema::hasColumn('invoice_items', 'service_id')) {
    DB::statement('ALTER TABLE invoice_items ADD FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE SET NULL');
echo "Migration completed successfully!\n";
}
