How The Episerver 'Installation' And 'Update' Powershell Functions Work Under Da Hood

Recently I've been working with a client to improve their continuous integration process, using TeamCity and Octopus.  As part of this process, I started looking at how we could copy our SQL changes.  If you've read, How To Create A New Episerver Database? then you'll know there are a few useful Nuget commands you can run in the package console to create a new EPiserver database and upgrade it to the correct version, but how does this work? In today's guide, I'm going to explain the inner workings.  

It's All Nuget Princess

Episerver is entirely installed via Nuget, so it makes sense that these database scripts are all pulled in via Nuget. When you install Episerver you'll need EPiServer.CMS.Core and EPiServer.Framework.  If you look in your packages directory within the EPiServer.Framework, you'll see a folder called 'tools' and a Powershell script called 'Upgrade.psm1':

If you open this up you can see the two install/upgrade functions, 'Update-EPiDatabase'

and 'Initialize-EPiDatabase'

'Initialize-EPiDatabase' for example will call the 'EPiServer.Cms.Core.sql' script within the 'EPiServer.CMS.Core' packages tools folder.

When you run the 'Initialize-EPiDatabase' PowerShell function it should give you a fully functioning database patched up to the version of Episerver you have installed.  This is really useful for building a brand new website, say in your test/QA environment.

If you simply want to upgrade your Episerver database (as you've upgraded Episerver) then you will need to know about the 'Update-EPiDatabase' function.

Update-EPiDatabase

The 'Update-EPiDatabase' is a little bit more complex, as it iterates through a number of SQL scripts within the 'epiupdates' folder.  If you look in the folder you'll see quite a lot of update scripts in there, as seen below:

If like me, when I stumbled across this, I thought what happens if I batch these scripts up into a giant superscript and run them directly within SQL, it fails.  If you want to create an automatic Epi build step in your continuous deployment process from your build server, then you'll need to have a look at a different function within 'Upgrade.psm1' called 'Export-EPiUpdates'. If you want to learn more about how to use these SQL scripts outside of your Nuget package console, then I suggest you read, How To Export Episerver Database Update Patches To Use Within Your Build Process.

Why Should I Care About This?!?!?

In your everyday development life, I admit this information probably isn't that useful.  As a developer working locally with Episerver, all you really need to know is that if you want to create a clean version of an EPiserver database, you can use two functions via the Nuget package console to do this.

If you are trying to set up some cool, funky continuous deployment process and you're fiddling with build server steps, then understanding how these scripts works will make your life a lot easier.  I've created build scripts that have cleared down the Epi database, called the update scripts, and then used a page import script to populate the content.  This can be really useful when you're initially building and testing a new website   Being able to fully automate your build process this way, should ensure that the code and content that you want to get deployed, does so, your Selenium tests won't get corrupted, as testers move content around etc.. and if you're working with DXC you can get on with work quicker, without having to raise support tickets with the service desk to get your data refreshed again.  

submit to reddit

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top