Iterative development of custom modules

Topics: Customizing Orchard, Troubleshooting, Writing modules
Apr 10, 2014 at 2:37 AM
I've following the samples of text editor module, i've tried to make some customizations and i get throw with this exception:

'NHibernate.Exceptions.GenericADOException' occurred in NHibernate.SqlAzure.dll

I've updated the model after installing, and i realise orchard isn't picking up my updates on migrations.cs.

i am trying to change the migrations from:
public int UpdateFrom2() {
  ContentDefinitionManager.AlterTypeDefinition("Product", cfg => cfg
    .WithPart("CommonPart")
    .WithPart("RoutePart")
    .WithPart("BodyPart")
    .WithPart("ProductPart")
    .WithPart("CommentsPart")
    .WithPart("TagsPart")
    .WithPart("LocalizationPart")
    .Creatable()
    .Indexed());
  return 3;
}
to something like:
public int UpdateFrom2() {
  ContentDefinitionManager.AlterTypeDefinition("Product", cfg => cfg   
    .WithPart("ProductPart")
    .Creatable()
    .Indexed());
  return 3;
}
because i want to have a simple GUI for users to enter some information, but after disabling & re-enabling the module/feature, the create product forms wasn't updating. After checking sql (azure), i realise some of the fields are also obsolete, so i proceed to drop the tables and try to re-enable the modules thinking that it will repopulate the tables. Apparently it doesn't. I do not wish to be spoonfed, but i'm curious how do module authors create modules when this workflow wasn't documented? I also tried to uninstall via command-line and to my horror, it deleted the entire module project, luckily it was just a "hello world" kind of stuff..

And lastly, the documented way to use Local IIS is to go to 'properties' -> 'web' -> select Local IIS and give proper permissions to a couple of folders, it was a 2-3 liner in the documentation, but that didn't go well for me too. I got stuck with using IIS Express and JIT is killing me, every debug session took like 30seconds before anything can be seen and every newly loaded page took equally long for me.

Sorry for wall of text.
Apr 10, 2014 at 10:51 AM
Upgrades using migrations are incremental. If you want to change some type definition, you need to create a new method named UpdateFromX, where X is the last return value of the latest UpdateFrom method. In your case, Since the last one was returning 3, you needed a UpdateFrom3 method and return someting greater than 3, normally 4. The new method will be picked and executed with the next request. and the database references will be updated to mark that the module data migrations is now version 4, and with the next upgrade it won't execute UpdateFrom3 or previous ones.

I don't know if a RemovePart method exists to be used with AlterTypeDefinition, you need to check.

As for debugging, don't start the project with debugging. Start without debugging and later attach to the IIS/IIS Express process. I'm not sure if it suits with debugging migrations, but for most cases it saves you some time.