Getting raw SQL performed by laravel 4 routing

I work in an environment where, instead of deploying the changes directly to client servers, I need to create a tarball with a list of changes from the SVN revision and send it to my web command.

The problem is that I am not allowed to fantasize anything, just changes in the site’s resources and raw requests, this means that I can’t ask the client to start larvel migration when I need them to change their order and (and I don’t trust migrations sufficient for life anyway.) I will also not have access to a direct database.

So, what I want to do is to capture the raw SQL when performing the migration, from there I see what exactly is changing, and I can tell the client "here is the SQL file of what you need to change, view it, run it when you apply the update."

+8
laravel laravel-4
source share
2 answers

If you add this to the top of your Routes.php file, it flushes all the SQL that Laravel runs:

 Event::listen('illuminate.query', function($sql) { var_dump($sql); }); 

So do this, then run php artisan migrate - and all SQL is dumped.

Then you can just write SQL to a file or something instead of executing var_dump - the possibilities are endless ...

+8
source share

As an alternative solution that does not require the installation of event listeners, you can use the --pretend option when running the command:

 php artisan migrate --pretend 

This will unload the SQL queries that will be executed during the migration, but without actually performing the migration. It will print on each line the name of the migration class and query executed from this migration, so for the migration that creates the users table with a unique email column, you will get something like this:

 CreateUsersTable: create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null, `password` varchar(60) not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci CreateUsersTable: alter table `users` add unique users_email_unique(`email`) 

This option is present since Laravel 4 up to the latest version of Laravel (which at the time when I send this answer is 5.1).

+11
source share

All Articles