Adds another check to old migrations to ensure some required FKs are dropped when needed
This commit is contained in:
@@ -29,5 +29,11 @@ namespace Umbraco.Core.Persistence.Migrations
|
||||
{
|
||||
return this.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This might be useful in the future if we add it to the interface, but for now it's used to hack the DeleteAppTables & DeleteForeignKeyExpression
|
||||
/// to ensure they are not executed twice.
|
||||
/// </summary>
|
||||
internal string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,9 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero
|
||||
|
||||
if (constraints.Any(x => x.Item1.InvariantEquals("umbracoUser2app") && x.Item3.InvariantEquals("FK_umbracoUser2app_umbracoApp")))
|
||||
{
|
||||
Delete.ForeignKey("FK_umbracoUser2app_umbracoApp").OnTable("umbracoUser2app");
|
||||
Delete.ForeignKey("FK_umbracoUser2app_umbracoApp").OnTable("umbracoUser2app");
|
||||
//name this migration, this is a hack for DeleteAppTables to ensure it's not executed twice
|
||||
((MigrationExpressionBase) Context.Expressions.Last()).Name = "FK_umbracoUser2app_umbracoApp";
|
||||
}
|
||||
if (constraints.Any(x => x.Item1.InvariantEquals("umbracoUser2app") && x.Item3.InvariantEquals("FK_umbracoUser2app_umbracoUser")))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Umbraco.Core.Configuration;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
|
||||
{
|
||||
@@ -10,6 +12,31 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
|
||||
{
|
||||
Delete.Table("umbracoAppTree");
|
||||
|
||||
//NOTE: this is a hack since old umbraco versions might not have had their db's upgraded correctly so they are all quite inconsistent.
|
||||
// This is actually done in migration: RemoveUmbracoAppConstraints to target 4.9.0 but we've found with some db's that are currently at 4.9.1,
|
||||
// these upgrades did not run. So, now we not only have to check if these constraints exist, but we also have to check if the RemoveUmbracoAppConstraints
|
||||
// has executed since we cannot drop the same foreign key twice or we'll get errors.
|
||||
|
||||
//Here we'll do a dirty check to see if RemoveUmbracoAppConstraints has executed
|
||||
if (Context.Expressions.Any(x =>
|
||||
{
|
||||
var b = x as MigrationExpressionBase;
|
||||
if (b == null) return false;
|
||||
return b.Name == "FK_umbracoUser2app_umbracoApp";
|
||||
}) == false)
|
||||
{
|
||||
//These are the old aliases, before removing them, check they exist
|
||||
var constraints = SqlSyntaxContext.SqlSyntaxProvider.GetConstraintsPerColumn(Context.Database).Distinct().ToArray();
|
||||
if (constraints.Any(x => x.Item1.InvariantEquals("umbracoUser2app") && x.Item3.InvariantEquals("FK_umbracoUser2app_umbracoApp")))
|
||||
{
|
||||
Delete.ForeignKey("FK_umbracoUser2app_umbracoApp").OnTable("umbracoUser2app");
|
||||
}
|
||||
if (constraints.Any(x => x.Item1.InvariantEquals("umbracoUser2app") && x.Item3.InvariantEquals("FK_umbracoUser2app_umbracoUser")))
|
||||
{
|
||||
Delete.ForeignKey("FK_umbracoUser2app_umbracoUser").OnTable("umbracoUser2app");
|
||||
}
|
||||
}
|
||||
|
||||
Delete.Table("umbracoApp");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user