Database upgrade failure

I am attempting to upgrade our Octopus Server instance from 3.14.15926 to 3.15.0 or newer, which results in the following database migration failure:

FATAL Failed upgrading database schema: SQL Error 536 - Invalid length parameter passed to the RIGHT function.
The statement has been terminated.
    System.Data.SqlClient.SqlException at
    System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at
    System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at
    System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at
    System.Data.SqlClient.SqlDataReader.get_MetaData() at
    System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption) at
    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at
    System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at
    DbUp.Support.SqlServer.SqlScriptExecutor.<>c__DisplayClass7.<Execute>b__4(Func`1 dbCommandFactory) at
    DbUp.Support.SqlServer.SqlScriptExecutor.Execute(SqlScript script, IDictionary`2 variables) at
    Logs: Fetching list of already executed scripts.
    Beginning database upgrade Fetching list of already executed scripts.
    Executing SQL Server script 'Octopus.Core.UpgradeScripts.Script0089 - ChangeOctopusServerNodeIdFormat.sql'
    Caution: Changing any part of an object name could break scripts and stored procedures.
    SQL exception has occured in script: 'Octopus.Core.UpgradeScripts.Script0089 - ChangeOctopusServerNodeIdFormat.sql'
    Script block number: 11; Block line 14;

This appears to also have created duplicate nodes in Octopus which resulted in our license limits being exceeded.

Hi Sean

Thanks for keeping in touch, i am sorry to hear that the upgrade did not work out nicely.

I suspect that it was due to an empty value in the RelatedDcoumentIds column in the Event table, would you be able to run the follow SQL script on the Octopus database to check?

SELECT [Id] ,[RelatedDocumentIds] ,[ProjectId] ,[EnvironmentId] ,[Category] ,[UserId] ,[Username] ,[Occurred] ,[Message] ,[JSON] ,[TenantId] ,[AutoId] FROM [dbo].[Event] where message like '%octopusservernode%' and RelatedDocumentIds = ''

If you do end up with records returning from this script, that could be the reason of the upgrade failure. You can remove those records and try to upgrade again.

For the duplicate nodes problem, this happens if you have Octopus Server running at the same time as this specific upgrade is happening. We changed the way Octopus Server nodes are recorded in the SQL Database.

You should delete the duplicated records in the OctopusServerNode table, and Octopus will fix the problem for you itself.

Hope that helps


Thank you Eddy, I will try again soon and let you know.

I was able to complete the upgrade after cleaning up the broken data and shutting down the Octopus Deploy service during the upgrade.

Thank you!

Hi Sean

Good to hear that, happy deployment