Today I tried to find a good way to include the SQL schema in my code and thus in source control. Having bookmarked a couple of frameworks in the past I finally got the change to look closer at some. This seems to be the fairly well maintained, it has commits in the past month and lots of patches in the discussion group, which is good. A few typos in the documentation wiki that were pointed out months ago without being fixed is not so good. Also, the documentation assumed some features that were only present in the source tree, not in the release package. The API interface leaves me somewhat lacking 1: Database.AddTable("Event", 2: new Column("Id", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity), 3: new Column("Name", DbType.String, 4: ColumnProperty.Indexed | ColumnProperty.NotNull), 5: new Column("StartTime", DbType.DateTime, 6: ColumnProperty.Indexed | ColumnProperty.NotNull), 7: new Column("EndTime", DbType.DateTime, ColumnProperty.Null) 8: );
I would have wished for a more fluent interface, but it works.
Each migration is a class, inheriting from Migration and implementing the Up() and Down() methods. It uses class attributes to figure out the order of the migrations and if they have been run.
1: [Migration(20090211235701)] 2: public class AddEventTable : Migration { 3: public override void Up() { 4: 5: Database.AddTable("Event", 6: new Column("Id", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity), 7: new Column("Name", DbType.String, 8: ColumnProperty.Indexed | ColumnProperty.NotNull), 9: new Column("StartTime", DbType.DateTime, 10: ColumnProperty.Indexed | ColumnProperty.NotNull), 11: new Column("EndTime", DbType.DateTime, ColumnProperty.Null) 12: ); 13: 14: } 15: 16: public override void Down() { 17: Database.RemoveTable("Event"); 18: } 19: }
Information about which migration have been run against a database is stored in a SchemaInfo table.
The database must be created in advance since the migration tool connects to the database before running any migrations scripts.
Migrations.NET support several databases, including MS SQL, Oracle, MySQL and SQLite.
One problem I had was that ColumProperty.Indexed does not work and there is no way to add an index to a table without adding custom SQL, thus negating some of the db-independence.
In the end, I’ve come to the conclusion that it’s nice, but missing some features and that I don’t really like the API. Putting it aside for now.
Rikmigrations uses the same Up()/Down() pattern but with a slightly different API interface that I liked better. Here, the attributes are set on the assembly level instead of the class level. I liked the class attributes from Migrator.NET better, but this works too.
1: using RikMigrations; 2: [assembly: Migration(typeof(BlogMigration1), 1)] 3: [assembly: Migration(typeof(BlogMigration2), 2)] 4: namespace Blog.Migrations 5: { 6: public class BlogMigration1 : IMigration 7: { 8: public void Up(DbProvider db) 9: { 10: Table t = db.AddTable("Blog"); 11: t.AddColumn("ID", typeof(int)).PrimaryKey().AutoGenerate(); 12: t.AddColumn("Name", typeof(string), 64); 13: t.Save(); 14: } 15: public void Down(DbProvider db) 16: { 17: db.DropTable("Blog"); 18: } 19: 20: } 21: public class BlogMigration2 : IMigration 22: { 23: public void Up(DbProvider db) 24: { 25: Table t = db.AlterTable("Blog"); 26: t.AddColumn("Description", typeof(string), int.MaxValue); 27: t.Save(); 28: } 29: public void Down(DbProvider db) 30: { 31: Table t = db.AlterTable("Blog"); 32: t.DropColumn("Description"); 33: t.Save(); 34: } 35: } 36: }
It has some cool features like using generics to specify the data types:
1: Table t = db.AddTable("Blog"); 2: t.AddColumn<int>("ID"); 3: t.AddColumn<string>("Name", 64); 4: t.Save();
and inserting default data into a table:
1: db.InsertDataInto("Table1", new { ID = 1, Name = "Hello World" }, true);
It looks like it’s also missing the feature to add an index, but from what I’ve glanced at the code, it shouldn’t be that hard to implement (this might just come back to haunt me…)
The documentation isn’t much and what little there is seems to be pretty old, but the code doesn’t look that hard to just figure out so I don’t think it will be much of a problem.
I didn’t get a chance to try this today but tomorrow I’m going to take it for a spin. There’s a couple of others I’d like to try as well. Watch this space for more.
Vi kopierer suksessen de har hatt i Oslo og arrangerer GeekBeer i Stavanger. Onsdag 4. mars, kl 19:00 på Timbuktu Kommenter gjerne her hvis du har tenkt å bli med, ellers kan jeg kontaktes på glenn krøllalfa henriksen punktum no eller på Twitter som @henriksen. Det er ingen krav til deltakerene men det er en fordel at du er sånn passe interessert i utvikling. Om det er i .NET, Java, PHP, Ruby eller noe annet er det samme. Vi organiserer, du står for din egen drikke. GeekBeer er også på Facebook så du kan melde deg på der og!
If you’re attending one conference this year, you should be in Oslo on the 17th through 19th of June, at the NDC 2009. The line-up is fantastic and I’ll challenge anyone to show me a development conference with a better speaker line-up. Mary Poppendieck, Mike Cohn, Scott Hanselman, Michael Feathers, Robert C. Martin (uncle Bob), Ted Neward and many more. And there’s even more on the way. This is the A-Team of speakers! If you’re not a full time developer, but work more as a project manager, check out the last day, the Norwegian Agile Day, a whole day dedicated to sessions on agile software development, with, amongst others, Mary Poppendieck, an authority in lean development and Mike Cohn, the founder of both the Agile Alliance and the Scrum Alliance. It doesn’t matter where you’re from, this is the conference to attend! Don’t miss it!
Regjeringen har i disse dager sluppet en løsning for elektronisk reiseregning på nettet. De har at på til sluppet den som fri programvare, noe som egentlig bare skulle mangle med tanke på at det er skattepengene som har blitt brukt. Den er, ved første øyekast, ganske grei å bruke. Det er ikke alt jeg er like enig i, men med tanke på det grusomme programmet vi bruker på jobben er dette en kjempeforbedring. Men ved nærmere ettersyn er det en del ting som ikke er som de burde vært. De tekniske løsningene er ikke så bra som de burde vært. Mange har referert til disse og jeg skal ikke gjenta de her, men det er én ting som virkelig plager meg (utenom sikkerhetsproblemet). All forretningslogikk ligger i Adobe Flex klienten, den klienten som lastes ned og kjøres på klienten. De har noen web services som kjører men det ser ut til at de ikke gjør noe mer enn å lagre informasjon og å lage PDF-er. Hvorfor kunne ikke logikken vært lagt på webserveren, eksponert gjennom en web service? Da kunne de laget et standard XML Schema for å representere en reiseregning, tatt det i mot, gjort de nødvendige beregningene og returnert det ferdige resultatet. Logikken for å regne ut en reiseregning har ikke noe behov for å endre seg fra klient til klient. Ved å sentralisere dette gjør man det mulig å lage mange forskjellige klienter som tar i mot data fra ett eller annet sted, gir det til reiseregningen.no for å få det regnet ut etter de til enhver tid gjeldene regler og få tilbake et resultat for så å gjøre hva man vil med det. Det hadde gjort det mye, mye enklere å lage alternative UI-er eller å integrere en reiseregning i et annet produkt eller arbeidsflyt. Om ikke annet så hadde logikken vært implementert i C# og ikke i ActionScript, et språk med mye mindre utbredelse enn C#...
This is kinda cool: Typemock are offering their new product for unit testing SharePoint called Isolator For SharePoint, for a special introduction price. it is the only tool that allows you to unit test SharePoint without a SharePoint server. To learn more click here. The first 50 bloggers who blog this text in their blog and tell us about it, will get a Full Isolator license, Free. for rules and info click here. Sweet! :)
I was looking at the source of a Twitter plugin to Windows Live Writer and found this gem of a comment: TwitterApi.UpdateStatus(Username, Password, status);
// Updating Twitter often happens so quickly that
// it doesn't feel like enough time has passed for
// it to have worked. So sleep for 250 millis to
// make the user feel like something happened.
Thread.Sleep(250);
Fantastic!
Microsoft has released a beta of the Microsoft Web Application Installer, an installer that will present you some popular open source web applications like Grafitti, DotNetNuke, WordPress, OSCommerce and more (yes, PHP apps too!). It will check your machine for pre-requisites you’ll need, provide links for downloads, configure IIS, allow you to enter basic configuration items and install everything. Microsoft making it easier to install OpenSource? What’s the world coming too…? :) Scott Hanselman has more details too
Microsoft have announced that they will start shipping JQuery as part of Visual Studio and offer full support for it. They will be shipping the original, open-source, version under the original MIT license. They will not be forking it or changing it and will contribute patches and changes back to the JQuery project under regular patch review process. I think this is a fantastic idea! I’m glad people in MS sees that not everything has to be invented there and that they are able to a) include open-source stuff in their product and b) not take it over and make an incompatible version. I believe that this way of doing things is symptomatic to the change in attitude I’ve been seeing in the developer part of Microsoft for some time now, they are more open and communicating better with the community. Good things ahead.
A while ago I wanted to make a service that could take an RSS feed, apply some filters and give me a new feed. It’s a good thing I didn’t because Yahoo has done it so much better than I ever could have done! Yahoo Pipes is a beautiful example of interactive HTML (very Web 2.0) and a fantastic service. Specify your data sources (CSV files, feeds (it can even auto-discover feeds), pages, Flicker, etc), mix them, filter them, loop them, RegEx them, you name it, and output it all in a nice, neat feed. Drag boxes on to the page, drag to connect them and fill in the blanks. It’s really easy to use! A beautiful piece of software… There’s tons of other stuff you can do with it so check out their blog for hints and features.
|