Database Migrations Converting DbScriptomate to Ruby
I am working with a buddy of mine on a database migration tool. It is like Active Record Migrations but customized to our specific needs. The project is called DbScriptomate and if you are developing code in the Microsoft world using SQL Server then check it out now! I will wait while you go check it, seriously I am patient.
DbScriptomate works by accepting command line arguments. It can setup your database server for first-time use, create your migration script or run the migration scripts to get your database in sync with everyone on your team. We are looking to simplify the way we parse the command line arguments. We could cleanup our code somewhat and take a bunch of complexity out at the same time if we do this correctly. In the .NET world there is no built-in way to do the parsing of the arguments, you need to do all the argument parsing by hand. There are some good tools to get this job done though and by just googling “command line parse .net c#” you will get a few libraries.
So whilst going through the DbScriptomate today I had a brilliant idea. In my attempt to learn Ruby, I tend to take C# code and convert that to Ruby. Thus far I have done small things like csv parsing, email and base64 encoding. I thought what a great idea if I could take DbScriptomate and convert it to Ruby, I know the code-base and the requirements so this should be a fun ride.
So here is my plan to do this conversion:
- Command line parsing
- Support to run scripts against a database
- Initial setup of Journaling table
- Generate a migration script whether it is DDL or DML
- Ensure scripts are only run once
- Run the scripts against the database
I am sure I will be adding some more steps here because I am sure Jacques will remind me of something I missed. I am going to start in the order above and work my way through. This could take me a couple weeks depending on workload, but I am looking forward to this series of posts. All the code will be available on GitHub in this repository for everyone to follow along with.
Just before anyone jumps up and says “hey you already have this in x, y and z library” let me say this is just for me to learn. I have no intention of making this a gem and I will not be using this in production. Active Record Migrations is great for this sort of thing so stick with that.
Hope you are as excited as I am! Also checkout Jacques’ blog he has some good posts on continuous delivery and other useful tidbits that will make you a better developer.