PHP code example of wishborn / upgrades

1. Go to this page and download the library: Download wishborn/upgrades library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wishborn / upgrades example snippets




namespace Wishborn\Upgrades;

use Wishborn\Upgrades\Support\Upgrade;
use App\Models\User;

class AddDefaultSettingsToUsers extends Upgrade
{
    protected function up(): void
    {
        $this->info('Adding default settings to users...');
        
        // If any part of this fails, all changes will be rolled back automatically
        User::whereNull('settings')
            ->chunk(100, function ($users) {
                foreach ($users as $user) {
                    $this->line("Processing user: {$user->email}");
                    
                    if ($this->confirm("Update user {$user->email}?")) {
                        $user->settings = ['theme' => 'light'];
                        $user->save();
                    }
                }
            });

        $this->info('Default settings added successfully!');
    }
}

if ($this->confirm('Continue?')) {
    // User confirmed
}

use Tests\TestCase;
use Wishborn\Upgrades\Models\Upgrade;

class TestUpgradeTest extends TestCase
{
    /** @test */
    public function it_can_run_the_upgrade()
    {
        $this->artisan('make:wish', ['name' => 'TestUpgrade']);
        
        $this->artisan('upgrade:run')
            ->expectsOutput('Running upgrades...')
            ->assertExitCode(0);

        // Assert your upgrade changes here
        $this->assertTrue(true);
    }
}

use Wishborn\Upgrades\Models\Upgrade;

test('upgrade can be run successfully', function () {
    $this->artisan('make:wish', ['name' => 'TestUpgrade']);
    
    $this->artisan('upgrade:run')
        ->expectsOutput('Running upgrades...')
        ->assertExitCode(0);

    // Assert your upgrade changes here
    expect(true)->toBeTrue();
});
bash
php artisan migrate
bash
# Publish the migrations
php artisan vendor:publish --tag=wishborn-upgrades-migrations

# Run migrations
php artisan migrate
bash
php artisan wish:run-upgrade
bash
php artisan wish:upgrade-status
bash
# Using PHPUnit
php artisan test

# Using Pest
./vendor/bin/pest