V10: fix content version cleanup dto migration (#13788)
* Add DoesPrimaryKeyExist method * Add primary key name to dto * Add extension method PrimaryKeyExists * Dont use sql_master table * Implement DoesPrimaryKeyExists * Rename without plural s * Refactor to get proper primary key name and not column name * Use primary key name and not column name * Dont filter tables in memory * Remove .Where * Don't select all, select only sql * throw NotImplementedException by default * USe virtual instead of abstract to avoid breaking change * Reinstert primary key attribute --------- Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -272,6 +272,13 @@ where tbl.[name]=@0 and col.[name]=@1;",
|
||||
return !constraintName.IsNullOrWhiteSpace();
|
||||
}
|
||||
|
||||
public override bool DoesPrimaryKeyExist(IDatabase db, string tableName, string primaryKeyName)
|
||||
{
|
||||
IEnumerable<SqlPrimaryKey>? keys = db.Fetch<SqlPrimaryKey>($"select * from sysobjects where xtype='pk' and parent_obj in (select id from sysobjects where name='{tableName}')")
|
||||
.Where(x => x.Name == primaryKeyName);
|
||||
return keys.FirstOrDefault() is not null;
|
||||
}
|
||||
|
||||
public override bool DoesTableExist(IDatabase db, string tableName)
|
||||
{
|
||||
var result =
|
||||
@@ -453,4 +460,9 @@ _sqlInspector ??= new SqlInspectionUtilities();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private class SqlPrimaryKey
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user