Skip to content

Migrate command doesn't run sqaushed .sql schema in Laravel 11 #557

@rishabkapadia

Description

@rishabkapadia

What were you trying to do?

Converting existing project to nativephp.
Migrate database using php artisan native:migrate.

What happened?

Instead of loading and executing the ./database/schema/sqlite-schema.sql, it says: Nothing to migrate.
More about squashing migrations : https://laravel.com/docs/11.x/migrations#squashing-migrations

How to reproduce the bug

if you already did composer native:dev, then manually delete sqlite db file from /database directory.

  1. create a new laravel 11 project or If you are on laravel version 10 or lower, upgrade to laravel 11.
  2. at project root run touch ./database/demo.sqlite
  3. Update .env DB_DATABASE value to demo
  4. Run php artisan migrate:fresh --database=sqlite
  5. Use the squash command php artisan schema:dump --database=sqlite --prune to clear individual migration files and clean up the project or if you have unsupported column modifiers. (WARNING: existing table wise migrations files will be deleted)
  6. Run touch ./database/nativephp.sqlite
  7. Run php artisan native:migrate

Debug Output

{
"Environment": {
"PHP": {
"Version": "8.3.19",
"Path": "/opt/homebrew/Cellar/php@8.3/8.3.19/bin/php"
},
"Laravel": {
"Version": "11.44.2",
"ConfigCached": false,
"DebugEnabled": true
},
"Node": {
"Version": "v22.11.0",
"Path": "/Users/Rishab/.nvm/versions/node/v22.11.0/bin/node"
},
"NPM": {
"Version": "10.9.0",
"Path": "/Users/Rishab/.nvm/versions/node/v22.11.0/bin/npm"
},
"OperatingSystem": "Darwin"
},
"NativePHP": {
"Versions": {
"nativephp/electron": "1.0.0.0",
"nativephp/laravel": "1.0.0.0",
"nativephp/php-bin": "1.0.1.0"
},
"Configuration": {
"Provider": "App\Providers\NativeAppServiceProvider",
"BuildHooks": {
"Pre": [],
"Post": []
},
"NotarizationEnabled": false,
"CustomPHPBinary": false
}
}
}

Which operating systems have you seen this occur on?

macOS

Notes

Temporary fix:

  1. Run php artisan make:migration native_schema_loader
  2. update the up() method of the new migration:
    public function up(): void
    {
        if (app()->runningInConsole() && $this->isRunningNativeMigrate()) {
            if (!Schema::hasTable('users')) {
                $sql = File::get(database_path('schema/sqlite-schema.sql'));
                DB::unprepared($sql);
            }
        }
    }

    private function isRunningNativeMigrate(): bool
    {
        return isset($_SERVER['argv']) && in_array('native:migrate', $_SERVER['argv']);
    }
  1. Run php artisan native:migrate

But still php artisan native:migrate:fresh keeps showing 'Dropping all tables. Nothing to migrate' and hence have to drop tables manually via DB client for consequent runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions