SQLite for RikMigrations

by Richard Mason 27. November 2007 05:55

I've just added support for SQLite to RikMigrations. This was done mainly because I use SQLite to store data in RikPVR and I needed to expand the schema. I tossed up whether to go with the embedded sql scripts like I have been doing or put in the time to add support to RikMigrations so I could use it. Eventually I decided it would be worth the work of adding to RikMigrations, if only to test how well it would support alternate database providers.

As expected, I had to refactor the code to support the change - alternate database providers wasn't in the original RikMigrations design, though I had already started refactoring towards a provider pattern. However, the changes were actually fairly minimal. I encourage others to sign up and start adding support for other engines.

Unfortunately, SQLite is a bit limited in some areas so not all features are supported. The biggest one is probably the inability to drop columns. There are workarounds for this in SQLite which I may look in to, but for the moment it will just throw an exception. Other ones I've run into is that you don't seem to be able to add columns with PRIMARY KEY or UNIQUE constraints on them once the table is created, but they work fine if they're added during the initial table construction.

In other news I've added a couple of extra pages to the RikMigrations doco. I'll keep adding to that bit by bit but if you have any specific questions drop me a comment or an email.

Finally, here's a quick bit of code in the meantime to show how to use SQLite instead of SQL Server. (This is only for programmatic access, I haven't added the command line interface yet)

DbProvider.DefaultConnectionString = @"Data Source=D:/TestDB.db";
MigrationManager.UpgradeMax(typeof(Joe1).Assembly, typeof(SqliteProvider));

The actual migrations stay exactly the same, except you may run into the limitations I mentioned earlier. I'll try to document them somewhere.

kick it on DotNetKicks.com

 

Comments are closed

About Us

RikWare is a software development company based in Brisbane, Australia. Led by director, Richard Mason, RikWare focusses on solving challenging business problems promptly and effectively.

RikWare is also the owner of Aussie Bushwalking, a free, wiki-like collaboration site for bushwalkers and the creator of RikMigrations, a migration framework for .NET.

Aussie Bushwalking

Want to discover some new bushwalking ideas? Share a few of your own? Aussie Bushwalking is like Wikipedia... but for bushwalkers. Head on over. Anybody can see the walks and it's free to sign up and share your own.

 

RikMigrations

RikMigrations is a database migration library for .NET based on the migrations facility provided by Ruby on Rails. It allows simple upgrading and downgrading of databases using .NET code (such as VB or C#) either from the command line or built into your application. Unlike many other migration frameworks, RikMigrations is a stand-alone library which does not rely on a large surrounding framework.