How to convert Laravel migrations to raw SQL scripts?

后端 未结 5 1533
孤独总比滥情好
孤独总比滥情好 2021-01-30 03:33

Developers of my team are really used to the power of Laravel migrations, they are working great on local machines and our dev servers. But customer\'s database admin will not a

5条回答
  •  灰色年华
    2021-01-30 03:54

    I'm using Laravel 6.X. For me, @user2479930's answer didn't work. I needed to read through Migrator's source code and had to add: $migrator->requireFiles($migrations); for it to work.

    $migrator = app('migrator');
    $db = $migrator->resolveConnection(null);
    $migrations = $migrator->getMigrationFiles('database/migrations');
    $migrator->requireFiles($migrations);
    $queries = [];
    
    foreach ($migrations as $migration) {
        $migration_name = $migration;
        $migration = $migrator->resolve($migrator->getMigrationName($migration_name));
    
        $queries[] = [
            'name' => $migration_name,
            'queries' => array_column($db->pretend(function () use ($migration) {
                $migration->up();
            }), 'query'),
        ];
    }
    dd($queries);
    

提交回复
热议问题