Today’s goal was simple. Create a database, pop in a few tables, find a way to populate them automagically. All in all, it all went pretty smoothly, but like anything in software, there are always a few unforeseen issues lurking in the shadows.

The unforeseen issues were all tied to my environment. You see, I have been traveling the world for the last fourteen months with my Macbook Air, a great laptop that has been getting the job done. Now that I am home, I have this older, but still great, Macbook Pro, and I kind of prefer to use this one. It has a lot more power, more accessibility (ahem, ports.. Apple), and also has a dope laser cut wooden cover and wooden keyboard keys. Oh, I can also use my barely used, massive 4k monitor with it (not something that bodes well for the Macbook Air). 

So, since this computer has been sitting at home for fourteen months, it’s a little behind the times as far as setup. So I went to work on the project and I decided to install Laravel. I love Laravel. It is definitely my PHP framework of choice, and even if I don’t use all the features it has for this application, it just gets me up and running so quickly and effortlessly, that I don’t even second guess it. Especially since this project is all about least path of resistance so I can get up and running as quick as possible. It felt like a no brainer.

I try to create a new Laravel project, and I found that a whole bunch of crap is out of date on this Mac. Homebrew, PHP, Laravel installer, mysql, you name it. So I spend about an hour just updating various software around my Mac to get it back to development ready. Thats when I run into mysql issues. I wanted to update mysql and I ran into a few walls. I guess I’m a bit hasty when it comes to updating things if they are on my local machine, because I just started hitting commands I assumed would do the trick like brew install this, brew upgrade that, etc. 

Things start chugging along and I see that the version jumped quite a bit. I was on mysql 5.6.x and then I see it download mysql 8.0.12. I try to restart mysql and begin the journey of having to figure out why the hell mysql wont start up. I try different things like restarting the service, starting mysqld manually, unlinking and relinking in brew, nothing. I just keep getting different errors and I can’t start this thing up. I then found some info on the internet that explained that if you upgrade from below 5.7, you’re in for a bad time. I ended up deleting all versions of mysql off my computer and going into the underbelly of my computer and deleting old mysql files and folders. I reinstalled it, and ……. crap. Still having issues. 

I fiddle around with the my.cnf file, nuke some log files, and a few other, what feels like random, remedies I found on the interwebs, until I finally get it working. At last. I go to test it out with Laravel and then I get separate errors from Laravel. Turns out, newer versions of Laravel have a few login issues with mysql 8. Finally find some solutions in the Github Issues of Laravel and FINALLY START ROLLING.

At this point, I’m like two hours in and all I’ve managed to do is get my machine to a place where I can actually write some real code. From there it was a piece of cake. I quickly setup a few tables. 

  • Users
  • Flight Deals
  • User Flight Deals

I then wrote a small abstraction class for dealing with the Skyscanner API. This class is just responsible for searching Skyscanner for prices from a given city to anywhere in the country. It spits out a whole bunch of results and I then filter those results for my criteria (under $200, direct flights).

Once I was finished with the Skyscanner abstraction class, I quickly wrote a command to hit Skyscanner, and populate my database with the flight deals. Once they are in there, it then attaches the flight deals to the users in the User Flight Deals pivot table. I decided to add a “notifed_at” field in this table, so I can keep track of if and when I notified a given user about a given deal. This way, I can attach a bunch of deals to a user, and then decide to notify him or her about a bunch of them at the same time at a later time, and update the table accordingly to track it all. 

Now my database has a few fake users living in different cities across the US, a bunch of real flight deals for this weekend (LAX to SFO for $103 roundtrip!), and I related the right deals to the right users. At this point it felt important to start structuring the notification, so I started to create another command to notify users of their deals. This command just grabs all the users with deals attached that they have not been notified about yet, and bundles all the deals into one notification for a given user. I started to work on a Mailchimp abstraction class, but decided to mock it for now. I decided to just log the message and structure it accordingly so I make sure I am capturing all the data I need from the Skyscanner API before I send out any notifications. 

This felt like a good stopping point. The next steps are to research the Mailchimp API and integrate my application with my mailing list so I can fire off emails directly from the application. This felt like a task I didn’t want to start today because I’m not sure if Mailchimp has an API request that is just, send this email template with this data to these users. I know transactional has that, but this isn’t exactly transactional email, so I will need to see what is the appropriate way to handle this. Let that be future Danny’s problem. For tonight, I grab some Peking Duck with my friends at Peking Duck House on 53rd street. 


Also published on Medium.