Memoirs Of A Jr. Dev

As most of you who follow COF know, I have absolutely no shame when it comes to blogging about stuff I’ve never done before in programming AKA things that are new to me. When I learn from a mistake I inevitably will make, I am certain to document it here from start to finish.
Image result for start video game gif
I love a well written database. One where all the columns and rows line up and no one names said columns or rows something arbitrary like Fibonacci Seq(x1) Description:  <- I just made that up as possibly the worst thing you could name an attribute in your database. I could be wrong, just sayin’
Anyway moving right along, my task this week was to help a client out by fixing some accidentally deleted data from their site.
To avoid reverting an entire website back to before the weekend, I was asked to restore a copy of the previous db before the accidental deletions and put the db somewhere I can look at it to pull out the accidentally deleted ids, did I mention for an entire client website not just my little side project app.
Image result for i love lucy chocolate factory gif
…wait WHAT?
My knowledge base of working with OPD (Other People’s Data) prior to this:
Image result for game over video game gif
Yeah, this falls into “things they don’t teach you in dev bootcamp, because they really can’t”, and “things you don’t learn online”. Being realistic, in a bootcamp or when teaching yourself programming, whose database do you really need to copy to production? You are basically working with your own app, created by you, with all your own data that no one but you has touched.
Image result for stuart look what I can do gif funny
Hmmmm, what to do, what to do.
Well the first step is to ask your System Crew (I call mine Pilots of the Millennium Falcon) to make a copy of the production db. *note, they will need a date from you, for the data that you want copied. In my case I asked for 12 hours before the content was accidentally deleted.
So, now that I have a copy of the client’s data in a safe place on my computer, I can mess with that data all day long and not break anything. So here is what I did.
1.) I cd’d into that backup file
cd /web/projecto/backupp.TMP

2.) I opened up a rails console
RAILS_ENV=local rails c

3.) I recreated that deleted taxonomy_id by writing a lil code
restored_taxon = Taxonomy.create(tree_path: ":x:xx:", has_child: false, title: "My Awesome Taxonomy Title", description: "My Awesome Taxonomy Title and related topics", sorting_order: 00, active: true, selectable: true)

4.) I plugged in all the missing data for the first taxonomy (there were 6 deleted due to associations)
first_ids = [12345, 22345, 32345, 42345, ...]

4.) I recreated ids/taxonomies associations
first_ids.each do |first_id|
FirstTaxonomy.create(first_id: first_id, taxonomy_id:

After 6 rounds of this, all deleted content was restored and all the client needed to do was some magic on their end to see it all back to normal.
Image result for fixed it! funny gif
What was super strange to me wasn’t with creating the scripts to fix this issue, but the process of how to work with OPD (other people’s data) in a safe and secure spot so as not to dump an entire website’s data and take ‘er down.
Image result for oh god no gif funny
In all honesty, I think breaking things to the point of irreparable damage is one of the  biggest fears of a Jr Dev, and this is something I personally struggle with daily. It’s that fine line between just trying something and not trying something cos you might screw it ALL up. I’m getting there though.
Image result for running to the finish line gif funny
Let me know in the comments when you had your moment of “I’m just gonna hit this button here and not be scared that I’ll break anything” AND how to get better at collaborating processes like working with OPD.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.