Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
AMagistroni committed Dec 21, 2023
1 parent e9494e2 commit 5d6fba8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions SqlSchemaCompare.Core/Common/ErrorWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public string GetErrors(IEnumerable<ErrorParser> errorsOrigin, IEnumerable<Error
return errorSchemaStringBuild.ToString();
}

private StringBuilder GetErrors(IEnumerable<ErrorParser> errors, bool origin)
private static StringBuilder GetErrors(IEnumerable<ErrorParser> errors, bool origin)
{
StringBuilder errorSchemaStringBuild = new();
if (errors.Count() > 0)
if (errors.Any())
{
if (origin)
errorSchemaStringBuild.AppendLine("**************** ORIGIN **************** ");
Expand Down
2 changes: 1 addition & 1 deletion SqlSchemaCompare.Core/DbStructures/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class View: DbObject
{
public override DbObjectType DbObjectType => DbObjectType.View;
public string Body { get; init; }
public IList<Index> Indexes { get; } = new List<Index>();
public IList<Index> Indexes { get; } = new List<Index>();
public void AddIndex(Index index) => Indexes.Add(index);
}
}
46 changes: 23 additions & 23 deletions SqlSchemaCompare.Core/UpdateSchemaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public UpdateSchemaManager(ISchemaBuilder schemaBuilder)
_schemaBuilder = schemaBuilder;
}

private List<(DbObjectType DbObjectType, Operation Operation)> OrderItemSchema => new()
private static List<(DbObjectType DbObjectType, Operation Operation)> OrderItemSchema => new()
{
(DbObjectType.User, Operation.Create),
(DbObjectType.User, Operation.Drop),
Expand Down Expand Up @@ -118,7 +118,7 @@ public string UpdateSchema(IEnumerable<DbObject> sourceObjects, IEnumerable<DbOb
return updateSchemaStringBuild.ToString();
}

private void ProcessView(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
private static void ProcessView(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
{
ProcessGenericDbObject<View>(sourceObjects, destinationObjects, resultProcessDbObject);
var originDb = sourceObjects.OfType<View>();
Expand All @@ -133,7 +133,7 @@ private void ProcessView(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObje
}
}

private void ProcessSingleIndex(IEnumerable<Index> originIndexes, IEnumerable<Index> destinationIndexes, ResultProcessDbObject resultProcessDbObject)
private static void ProcessSingleIndex(IEnumerable<Index> originIndexes, IEnumerable<Index> destinationIndexes, ResultProcessDbObject resultProcessDbObject)
{
var indexToCreate = CreateDbObjectByName(originIndexes, destinationIndexes, resultProcessDbObject);
var indexToDrop = DropDbObjectByName(originIndexes, destinationIndexes)
Expand All @@ -151,7 +151,7 @@ private void ProcessSingleIndex(IEnumerable<Index> originIndexes, IEnumerable<In
resultProcessDbObject.AddOperation(indexToAlter, Operation.Create);
}

private void ProcessMember(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
private static void ProcessMember(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
{
var originDb = sourceObjects.OfType<Member>();
var destinationDb = destinationObjects.OfType<Member>();
Expand All @@ -166,7 +166,7 @@ private void ProcessMember(IEnumerable<DbObject> sourceObjects, IEnumerable<DbOb
DropDbObjectByName(originDb, destinationDb, resultProcessDbObject);
}

private void ProcessTrigger(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
private static void ProcessTrigger(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
{
(var toCreate, var toAlter, _) = ProcessGenericDbObject<Trigger>(sourceObjects, destinationObjects, resultProcessDbObject);

Expand All @@ -179,7 +179,7 @@ private void ProcessTrigger(IEnumerable<DbObject> sourceObjects, IEnumerable<DbO
}
}

private void ProcessUser(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
private static void ProcessUser(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
{
var originDb = sourceObjects.OfType<User>();
var destinationDb = destinationObjects.OfType<User>();
Expand All @@ -194,7 +194,7 @@ private void ProcessUser(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObje
resultProcessDbObject.AddOperation(toAlter, Operation.Alter);
}

private void ProcessRole(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
private static void ProcessRole(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
{
var originDb = sourceObjects.OfType<Role>();
var destinationDb = destinationObjects.OfType<Role>();
Expand All @@ -203,7 +203,7 @@ private void ProcessRole(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObje
DropDbObject(originDb, destinationDb, resultProcessDbObject);
}

private void ProcessSchema(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
private static void ProcessSchema(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
{
var originDb = sourceObjects.OfType<Schema>();
var destinationDb = destinationObjects.OfType<Schema>();
Expand All @@ -212,7 +212,7 @@ private void ProcessSchema(IEnumerable<DbObject> sourceObjects, IEnumerable<DbOb
DropDbObject(originDb, destinationDb, resultProcessDbObject);
}

private void ProcessTable(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
private static void ProcessTable(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
{
var originDb = sourceObjects.OfType<Table>();
var destinationDb = destinationObjects.OfType<Table>();
Expand Down Expand Up @@ -271,7 +271,7 @@ private void ProcessTable(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObj
}
DropDbObject(originDb, destinationDb, resultProcessDbObject);
}
private void ProcessTableColumn(Table table, Table destinationTable, ResultProcessDbObject resultProcessDbObject)
private static void ProcessTableColumn(Table table, Table destinationTable, ResultProcessDbObject resultProcessDbObject)
{
IList<Column> columnsToAdd;
IList<Column> columnsToDrop;
Expand Down Expand Up @@ -333,13 +333,13 @@ private void ProcessTableColumn(Table table, Table destinationTable, ResultProce
resultProcessDbObject.AddOperation(indexToDropAndCreate, Operation.Create);
}

private void ProcessDbObjectWithoutAlter<T>(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
private static void ProcessDbObjectWithoutAlter<T>(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
{
var originDb = sourceObjects.OfType<T>();
var destinationDb = destinationObjects.OfType<T>();

var toCreate = CreateDbObjectByName<T>(originDb, destinationDb, resultProcessDbObject);
DropDbObjectByName<T>(originDb, destinationDb, resultProcessDbObject);
var toCreate = CreateDbObjectByName(originDb, destinationDb, resultProcessDbObject);
DropDbObjectByName(originDb, destinationDb, resultProcessDbObject);

var toAlter = originDb
.Except(toCreate)
Expand All @@ -349,14 +349,14 @@ private void ProcessDbObjectWithoutAlter<T>(IEnumerable<DbObject> sourceObjects,
resultProcessDbObject.AddOperation<T>(toAlter, Operation.Create);
}

private (List<T> toCreate, List<T> toAlter, List<T> toDrop) ProcessGenericDbObject<T>(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
private static (List<T> toCreate, List<T> toAlter, List<T> toDrop) ProcessGenericDbObject<T>(IEnumerable<DbObject> sourceObjects, IEnumerable<DbObject> destinationObjects, ResultProcessDbObject resultProcessDbObject)
where T : DbObject
{
var originDb = sourceObjects.OfType<T>();
var destinationDb = destinationObjects.OfType<T>();

var toCreate = CreateDbObject<T>(originDb, destinationDb, resultProcessDbObject);
var toDrop = DropDbObject<T>(originDb, destinationDb, resultProcessDbObject);
var toCreate = CreateDbObject(originDb, destinationDb, resultProcessDbObject);
var toDrop = DropDbObject(originDb, destinationDb, resultProcessDbObject);

var toAlter = originDb
.Except(toCreate)
Expand All @@ -366,7 +366,7 @@ private void ProcessDbObjectWithoutAlter<T>(IEnumerable<DbObject> sourceObjects,

return (toCreate, toAlter, toDrop);
}
private List<T> CreateDbObject<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
private static List<T> CreateDbObject<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
{
var toCreate = sourceObjects
.Where(dbObject => sourceObjects
Expand All @@ -376,7 +376,7 @@ private List<T> CreateDbObject<T>(IEnumerable<T> sourceObjects, IEnumerable<T> d
resultProcessDbObject.AddOperation<T>(toCreate, Operation.Create);
return toCreate;
}
private List<T> CreateDbObjectByName<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
private static List<T> CreateDbObjectByName<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
{
var toCreate = sourceObjects
.Where(dbObject => sourceObjects
Expand All @@ -386,13 +386,13 @@ private List<T> CreateDbObjectByName<T>(IEnumerable<T> sourceObjects, IEnumerabl
resultProcessDbObject.AddOperation<T>(toCreate, Operation.Create);
return toCreate;
}
private List<T> DropDbObject<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
private static List<T> DropDbObject<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
{
var toDrop = DropDbObject<T>(sourceObjects, destinationObjects);
var toDrop = DropDbObject(sourceObjects, destinationObjects);
resultProcessDbObject.AddOperation<T>(toDrop, Operation.Drop);
return toDrop;
}
private List<T> DropDbObject<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects) where T : DbObject
private static List<T> DropDbObject<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects) where T : DbObject
{
return destinationObjects
.Where(dbObject => destinationObjects
Expand All @@ -402,13 +402,13 @@ private List<T> DropDbObject<T>(IEnumerable<T> sourceObjects, IEnumerable<T> des
.ToList();
}

private List<T> DropDbObjectByName<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
private static List<T> DropDbObjectByName<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject
{
var toDrop = DropDbObjectByName(sourceObjects, destinationObjects);
resultProcessDbObject.AddOperation<T>(toDrop, Operation.Drop);
return toDrop;
}
private List<T> DropDbObjectByName<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects) where T : DbObject
private static List<T> DropDbObjectByName<T>(IEnumerable<T> sourceObjects, IEnumerable<T> destinationObjects) where T : DbObject
{
return destinationObjects
.Where(dbObject => destinationObjects
Expand Down
4 changes: 2 additions & 2 deletions SqlSchemaCompare.Test/TSql/CompareTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public void DiscardObjects()
[Fact]
public void DiscardSchema_table()
{
string sql1 =
$@"CREATE TABLE [schema].[TableName](
const string sql1 =
@"CREATE TABLE [schema].[TableName](
[Id] [int] IDENTITY(1,1) NOT NULL,
[col1] [char](8) NULL
) ON [db1]
Expand Down

0 comments on commit 5d6fba8

Please sign in to comment.