I need to run a program that updates a database from a file that is uploaded to the server periodically. I'm using laravel scheduler to do this. I have already done the shell script that runs ftp to upload the file. Works wonderfully, much easier than fiddling with crontab.
My question is with regards to the program that updates the database, before Laravel i would have create a php that created a new db instance and a series of sql commands to process the data. I'm guessing i could the same, but i was wondering if it was a more elegant solution to run a database updater in the scheduler?
Well you can simply call a command that is running database queries right?
Anyway, my suggestion would be to use migrations instead of files with queries. There is also a --path option in the php artisan migrate command which makes this possible for you. This way you can keep track in the database what's going on and you have some kind of history of performed queries ;)
Thanks for the replays. I know how to do the work on the database, in the past i would have created a stand alone php file to do it and put it on the crontab. It feels to me that it is much more elegant to do it using the scheduler.
Playing around and googeling i have created a command and I'm testing putting the code to update the database in the handle method of the command that i created.
Intriguing the migration suggestion, are you suggesting having the logic for the update in a migration file and call this migration periodically?
I case any one is following, i solve the problem in this way:
I created a command, in my case UpdateDatabase, in the handle of this command I test if a file exist, if it does ti fires a method on the inventory model that updates the database, and then deletes the file that was checked at the beginning.
The command is fire from the scheduler every 30 minutes.