Programming

Simple SQL Schema Migration

I'm working on an application to manage my streaming media for my Roku player using sqlite3 and Python for everything. One thing I've learned over the years is that your SQL schema always changes. Once your code is in production you always have something you need to change about it, whether it's adding a new column, changing a type or tables to support new features. I wanted a way to automatically update the database schema when a new version of the code is installed. I don't want to jump into the complexity of using SQLAlchemy and migrate so I came up with this simple method. The database has a table named schema with a single row with the current schema version in it. This class checks the current version and executes any missing commands, bringing it up to the latest version.