|
UsingDbVerse
Using DbVerseInstalling The Template
Creating A DbVerse Project
Configuring The DbVerse Database Project
AuthoringSample ApplicationThe Sample.Database project included with the source code is a good starting point to learn authoring. For a quick idea, look at this example. The "Methods" ClassAll of the database modifications that you author, including setup and teardown, will be in a class named "Methods." This class inherits from MethodsBase. All public methods in Methods can be executed from the console or Windows UI as described below. When you created the project from the DbVerse Database Project template, three C# code files were created. Each is a partial of the Methods class. These files are created for convenience only. They provide a quick start skeleton and a way to illustrate DbVerse usage. You may remove any or all of them and/or change the filenames. NOTE: If you prefer a different name for your class than "Methods" you can change it. DbVerse uses Castle Windsor to inject your class into DbVerse. See castle.config. Update MethodsAny public method in the Methods class can be designated as "Update" by decorating it with the Update attribute. Once version 1 of your database is deployed to QA or Production, you should author all subsequent changes as update methods only. This attribute lets DbVerse keep track of which updates have been applied in the different environments and in what order updates are executed. The Db ObjectMethodsBase contains a property Db, This object represents the target database. Almost all your code will use Db. ScriptsDbVerse allows you to run scripts. This feature comes in very handy for data conversion, to initialize a legacy database, or simply accommodate developers who prefer to write scripts. To run scripts in the context of DbVerse place each script in the "Scripts" folder and set "Compile To Ouptut Directory" to "Copy Always". To execute a script: Db.ExecuteScript("myScriptFileName"). Using SMOYou might run into edge cases where where the DbVerse interface cannot do what you want. In those cases you have two options. One way is to use scripts as described above. Another way is to use SMO directly. Almost all DbVerse objects expose the underlying SMO object. For example you can use Db.SmoDatabase to access the underlying SMO database object or Server.SmoServer to access the underlying SMO server object, and so on. SMO is a comprehensive interface to SQL Sever. There's almost nothing you cannot do. DataYou might want to generate data as part of initialization. DbVerse provides basic add/change/delete methods to alter data in the database. While this is fine for things like populating or altering lookup tables, it might not be adequate in for generating QA data. You might prefer to use your application's persistence and/or repositories to add entities to your database. In that case, simply add references to those projects to the DbVerse Database project, and write the code to create the QA data in the same fashion you would, for example, in integration tests. Running MethodsDbVerse provides both a console application and a Windows UI. After compilation you will find these executables in the target folder of your Database project. To use the console application, simply specify the names of methods as command line arguments in the order you want them to run. For example: Lunaverse.DbVerse.Console.exe DropDatabase CreateDatabase CreateSchema ApplyAllUpdates AddSeedData AddQaData or Lunaverse.DbVerse.Console.exe RecreateQaDatabase You can also specify the connection string in the command line following "c:" which will override the connection string value specified in the configuration. The Windows UI lists all available methods and allows you to execute them one at a time. Continuous IntegrationThe DbVerse console application support continuous integration scenarios. Using MS Build, NAnt (or whatever) simply create a task to run the DbVerse console application with desired methods as shown above. Make sure to run DbVerse after the solution build and before running integration tests. Applying Changes To "Live" DatabasesIn development and CI environments you typically wipe out and rebuild the database. However, you need to be able to apply changes to "live" databases (i.e., QA and Production) in a non-destructive way. DbVerse makes this simple. Just run the ApplyAllNewUpdates method (via console or WinUI) against the database. DbVerse remembers which updates have previously been applied to that database and applies only new ones. DbVerse "remembers" by creating and maintaining a table named "DatabaseUpdates." Therefore your database must not already have a table with that name. (NOTE: In the odd case that a method fails and DbVerse still adds a record indicating that that update was applied, you can just manually delete the DatabaseUpdates record for the update that did not successfully run.) |
Sign in to add a comment