1. Home
  2. Docs
  3. Llamachant Framework Modules
  4. Additional Modules
  5. Update Scripts Module

Update Scripts 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.

Getting Started

  1. Install the LlamachantFramework.UpdateScripts.Module from nuget into your solution
  2. Include the LlamachantFrameworkUpdateScriptsModule in the RequiredModuleTypes collection of your .Module project
  3. In your projects, add a new class that implements the IUpdateScript interface
  4. Implement the IUpdateScriptProvider interface to your ModuleBase classes
				
					public sealed partial class TestApplicationModule : ModuleBase, IUpdateScriptProvider {
    public LlamaFrameworkTestModule() {
        InitializeComponent();
        this.RequiredModuleTypes
        .Add(typeof(LlamachantFramework.UpdateScripts.Module.LlamachantFrameworkUpdateScriptsModule));
    }
    
    public IList<IUpdateScript> GetPreUpdateScripts()
    {
        //This will automatically collect all IUpdateScripts in the current assembly
        return UpdateScriptManager.Instance
        .FindUpdateScriptsInAssembly(Assembly.GetExecutingAssembly(), IUpdateScriptType.PreUpdateScript);
    }
    
    public IList<IUpdateScript> GetPostUpdateScripts()
    {
        //This approach lets you determine which IUpdateScripts to release
        //return new List<IUpdateScript>() { new MyOneTimeUpdate() };
        
        //This will automatically collect all IUpdateScripts in the current assembly
        return UpdateScriptManager.Instance
        .FindUpdateScriptsInAssembly(Assembly.GetExecutingAssembly(), IUpdateScriptType.PostUpdateScript); 
    }
    
     public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB)
        {
            ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB);
           
            return new[] 
            { 
                updater, 
                new LlamachantFramework.UpdateScripts.Module.DatabaseUpdate.Updater(objectSpace, versionFromDB) 
            };
        }
}

//Now you can create as many of these types of classes as you need
public class MyOneTimeUpdate : IUpdateScript
{
    public string UpdateID => "6d7eb7fa-c283-489a-904b-13673899dda7"; //This must be unique
    public string Description => "Perform a one time update";
    public DateTime CreatedDate => DateTime.Parse("January 1, 2022");
    public IUpdateScriptType ScriptType => IUpdateScriptType.PostUpdateScript;
    public string Run(IObjectSpace space, Version databaseVersion)
    {
        try
        {
            //try to perform your update here using the IObjectSpace
            return "Success";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
}
				
			
Was this article helpful to you? Yes No

How can we help?