How to convert Laravel migrations to raw SQL scripts?

后端 未结 5 1542
孤独总比滥情好
孤独总比滥情好 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条回答
  •  萌比男神i
    2021-01-30 03:36

    user2479930's code is great, but I was getting:

    Class 'LocalItemsSchema.php' not found
    

    I debugged the issue and fixed it with the following:

    foreach($migrations as $migration) {
            $migration_name = $migration;
            $migration_name = str_replace('.php', '', $migration_name);
            $migration = $migrator->resolve($migration_name);
    
            $queries[] = [
                'name' => $migration_name,
                'queries' => array_column($db->pretend(function() use ($migration) { $migration->up(); }), 'query'),
            ];
        }
    

提交回复
热议问题