PowerShell function to create Redgate SQL Compare args from a SQL Server JDBC connection string

I’ve joined a dev team for “Down Tools” week at Redgate. (Think Google 20% time). It has generally been fantastic.

OK – I did a bad…

The first day went quite well:

The next day not so much:

Well that felt rubbish! Live and learn. The result was a bunch of code that will probably go to waste. However, I think one of the functions that I agonised over for a good while might be useful to someone else so here it is. Feel free to use it, share it, critique it, tear it shreds as appropriate. If it saves you some time then I can say I produced something useful with the time I spent learning the correct format for SQL Server JDBC connection strings and then working out how to parse, cut and stitch strings back together again in PowerShell.

What the function does

This function takes a SQL Server database JDBC connection string and an int (1 or 2, to represent whether this connection is source or target) and returns SQL Compare args to connect to the database.

I’ve assumed the format for the connection string defined here. This function works for all the given examples. It returns an array of arguments based on the SQL Compare command line syntax defined here.

Disclaimer/Caveat

Since I’m not actually going to use it I’ve not tested as fully as I would normally. Use this at your own risk.

The code:

I’ve shared the code on my GitHub. I accept pull requests. If you spot a bug and fix it please don’t be shy. 🙂 View the code on GitHub Gist.

So what am I building?

I’m building a Flyway plugin for Octopus Deploy with a built in drift-check for MySQL, Oracle or SQL Server. Some other people I’m working with are experimenting with combining Redgate MySQL Compare and Flyway to create something that works a bit like ReadyRoll with a UI a bit like Source Control for Oracle. Hopefully this will support the open source FlyWay project as well as improve the experience with our MySQL tooling. By stitching it all together we might have an interesting DLM story for MySQL. It’s really early days. Just an experiment so far. No promises that anything we do will ever be delivered. I’m sure I’ll write about it in more detail if it all works and when it’s ready!

That’s all folks!

Leave a Reply

Your email address will not be published.