![]() / into the correct operational sequence. Configxxx so that the configurators can be sorted / The convention must use a consistent name / and is stored in Sqlite using a PRAGMA. / The 3 digit number is the database version number / which ends in 3 numeric digits starting / must use a consistent naming convention / To use automatic configuration the configurator classes / Configurators are the components which actually make database changes. The properties it provides are not essential but are useful for debugging or logging database change activity. The method InitialiseDatabase is called each time the application starts and should perform all updates necessary to bring the database to the current version. This interface provides the main functionality for maintaining the database schema. / the number of IDatabaseConfigurators which were executed / After completion this should show the final version of the database / After completion this should show the initial version of the database Void InitialiseDatabase(IDatabaseConfigurator configurators, bool dispose = false) / each IDatabaseConfigurator to be disposed after use / IDatabaseConfigurators which will be execute in order / The correct sequence of the IDatabaseConfigurators is the / The IDbInitialiser will resolve how to locate and sort the / This should move the database from it's current Public interface IDbInitialiser : IDisposable / You would normally call this once at application startup / IDbInitialiser is used to manage database initialisation and upgrades. It comprises 2 interfaces: IDbInitialiser /// The resulting initialiser is by no means perfect and I am sure that readers will find many ways to improve it however it does the job, it's flexible, automatic and simple to implement. Of course, the initialiser must also have an effective versioning mechanism so that it knows when and where to start applying changes. Thus, any initialiser must be able to handle more complex scenarios beyond simply executing a script. For example, ALTER TABLE cannot be use to drop a column and unlike CREATE TABLE IF NOT EXISTS, there is no similar ALTER TABLE ADD COLUMN IF NOT EXISTS. However, one small limitation is that in some cases, SQLite supports only a subset of standard SQL commands. IMHO SQLite is a great product even supporting full text searching. However, this solution did not offer any way of automatically keeping the database updated with schema changes and so I created a simple initialization framework which is what this article is about. SQLite was my choice for an in-process database. I had previously used PetaPoco as a lightweight ORM when working with Umbraco and subsequently found NPoco which had added some nice features including async versions of many methods. This article came about when I was creating a small blog styled web application where EF and SQL Server was just too much overhead, I needed a smaller, lighter, in-process database which I could use with the Microsoft AspNet Identity framework.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |