What have I done this week?

Mostly backpack.tf stuff. A gradual move from MongoDB to Postgres has begun.

We’re using the Doctrine PHP library, as it is database-agnostic and offers a lot of abstraction over a typical relational data store. It also has native support for JSON types, which I’m taking advantage of as we sometimes have to store unexpected bits of data. It also gives us the freedom to use document-based data structures if we need to, so we retain the advantages of MongoDB.

To get my feet wet, I’m starting by migrating only the tables we can easily rebuild. This includes transient data we fetch from the Steam web APIs, and other facets such as currency conversion rates. Once we are confident that the conventions used will make migrating everything else easier, we will continue by migrating the permanent data stores, one by one.

So far, I’ve happily deleted a lot of now-unnecessary code, and almost all item data is now stored and retrieved in their own Postgres tables. I wrote a lot of boilerplate to handle request-scoped caching for MongoDB, and that can now be removed as such functionality is available in Doctrine (and done far better). It has made our new repositories far thinner than the old ones, and code is far easier to reuse than before.

These changes are not yet pushed live, but I’m looking forward to seeing the differences in server resource usage when these changes are deployed, as these collections are queried the most often.

What should I try to improve?

Not sure. Relational DB design?

I’ve been so far stranded from having to do it because of having to use MongoDB so much. I actually feel a bit of guilt as it is something I really should know better. I seldom write SQL, as I feel writing raw queries is a little silly outside of server administration. Doctrine supplies its own domain-level language, the Doctrine Query Language, which is how SQL-like statements can be written without breaking database-agnosticism.

What am I going to do next?

Continue working on the Postgres migration! I find cleaning up bad mistakes to be therapeutic, and it gives me a great reason to explore Postgres and relational DB design.