Managed Update Script Module

This module is used to manage updates via update classes instead of stuffing too much code into your Updater.cs class. Each update should only be executed once per database making deployment updates really easy.

Example: Your client has your software installed at their location. In your most recent update, you made a change to the database that requires a complex script to correct. Rather than run the script on the database manually, you want to have the Updater.cs do this for you. The problem is, you only want this script to run once per database. This is where the Managed Update Script Module comes into play.

 

Forewarning:

  • You should have a deployment strategy in place that takes a backup of the database before you deploy new versions
  • This module is provided “as-is” without any warranty

 

To use this module:

  1. Include the ManagedUpdateScript.Module project in your solution
  2. Add the module to your .Module project’s required module list
    • Open the Module.cs file in your project and drag/drop this module from the toolbox OR
    • Add the following line of code to your Module.cs constructor: this.RequiredModuleTypes.Add(typeof(ManagedUpdateScript.Module.ManagedUpdateScriptModule));
  3. In your project, add a new class that implements the IUpdateScript interface. This is where you will define and execute the update script. See the DoSomethingUpdate class in the sample project as an example.
  4. In whichever project you want to run update scripts from, add the IUpdateProvider interface to the ModuleBase
  5. Implement the IUpdateScriptProvider and simply return a list of all updates that should be run either before the database is updated or after: GetPreUpdateScripts() vs GetPostUpdateScripts()

 

The updates will run every time the database is updated. If you want to prevent this from happening while debugging for performance reasons, you can set the UpdateScriptManager.Instance.UpdateWhenDebugging property to false.

public sealed partial class ManagedUpdateScriptWindowsFormsModule : ModuleBase, IUpdateScriptProvider {
    public ManagedUpdateScriptWindowsFormsModule() {
        InitializeComponent();
    }
    
    public IList<IUpdateScript> GetPostUpdateScripts()
    {
        return new List<IUpdateScript>()
        {
            new DoSomethingUpdate()
        };
    }

    public IList<IUpdateScript> GetPreUpdateScripts()
    {
        return new List<IUpdateScript>();
    }
}

public class DoSomethingUpdate : IUpdateScript
{
    public Guid UpdateID => Guid.Parse("3584382a-7b88-4797-8941-bc03bde9d828");
    public string Description => "This update doesn't actually do anything";
    public DateTime CreatedDate => DateTime.Parse("January 1, 2021");

    public string Run(Session session)
    {
        //session.ExecuteNonQuery("SELECT Count(OID) FROM XPObjectType");
        return "Something was done";
    }
}

File Type : PDF

View / Download