AlterTableCommand's methods should return this?

Topics: Administration, Writing modules
Oct 5, 2011 at 8:55 AM
Edited Oct 5, 2011 at 8:57 AM

Currently (Orchard 1.2) it is not possible to chain AlterTable statements on the same table. This is just annoying.

 

      SchemaBuilder.AlterTable("HarvesterProgressRecord", table =>  table
        .AlterColumn("CurrentItem", column => column.ColumnName = "ItemsHarvested")
        .AddColumn("ItemsImported", DbType.Int32));

 

You need to do it like this:

 

      SchemaBuilder
        .AlterTable("HarvesterProgressRecord", table => table.AlterColumn("CurrentItem", column => column.ColumnName = "ItemsHarvested"))
        .AlterTable("HarvesterProgressRecord", table => table.AddColumn("ItemsImported", DbType.Int32));

 

This is annoying, because you have to state the same Table name over and over again if you have lot's of mutations in your table.

 

This could be changed by letting the methods from AlterTableCommand insert a new sql statement instead of making it perfectly compositional.

Or maybe make a .WithTable method that accepts 1 param as tablename so that you specify it once in your migration method. 

 

 

 

 

Oct 5, 2011 at 9:39 AM

Or like this:

       SchemaBuilder
        .AlterTable("HarvesterProgressRecord", table => { 
             table.AlterColumn("CurrentItem", column => column.ColumnName = "ItemsHarvested");
             table.AddColumn("ItemsImported", DbType.Int32);
          });

Which make a lot of sense :)

Discussion closed!

Oct 5, 2011 at 9:40 AM

BTW, renaming a column is currently not possible in orchard migrations (correct me if I'm wrong), my code doesn't work..

Coordinator
Oct 5, 2011 at 4:59 PM

By design ! The  AlterTable call be be converted to a Statement. It was design like this to define SQL boundaries explicitly. Some commands can't be executed together. This way it's sure it won't fail.