-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented exposing DependencyTraversalStrategy configurability
- Loading branch information
Showing
14 changed files
with
166 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
DataDude/Instructions/Insert/AutomaticForeignKeys/AutoFKConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
namespace DataDude.Instructions.Insert.AutomaticForeignKeys | ||
using DataDude.Schema; | ||
|
||
namespace DataDude.Instructions.Insert.AutomaticForeignKeys | ||
{ | ||
public class AutoFKConfiguration | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether "missing" foreign key dependencies will automatically be added as insert instructions. | ||
/// </summary> | ||
public bool AddMissingForeignKeys { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a traversal strategy for dependencies. Default value is to follow all foreign keys. | ||
/// </summary> | ||
public IDependencyTraversalStrategy DependencyTraversalStrategy { get; set; } = Schema.DependencyTraversalStrategy.FollowAllForeignKeys; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
|
||
namespace DataDude.Schema | ||
{ | ||
public class DependencyTraversalFailedException : Exception | ||
{ | ||
public DependencyTraversalFailedException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
public DependencyTraversalFailedException(TableInformation sourceTable) | ||
: this($"Failed building a dependency chain for table {sourceTable.FullName}") | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Linq; | ||
|
||
namespace DataDude.Schema | ||
{ | ||
public static class DependencyTraversalStrategy | ||
{ | ||
/// <summary> | ||
/// Gets a strategy that does not follow nullable dependencies. | ||
/// </summary> | ||
public static IDependencyTraversalStrategy SkipNullableForeignKeys => new SkipNullableFKTraversalStrategy(); | ||
|
||
/// <summary> | ||
/// Gets a strategy that does not follow recursivce dependencies. | ||
/// </summary> | ||
public static IDependencyTraversalStrategy SkipRecursiveForeignKeys => new SkipRecursiveFKTraversalStrategy(); | ||
|
||
/// <summary> | ||
/// Gets a strategy that follows all dependencies. | ||
/// </summary> | ||
public static IDependencyTraversalStrategy FollowAllForeignKeys => new FollowAllForeignKeysTraversalStrategy(); | ||
|
||
private class SkipNullableFKTraversalStrategy : IDependencyTraversalStrategy | ||
{ | ||
public bool Process(ForeignKeyInformation foreignKey) | ||
{ | ||
return foreignKey.Columns.All(c => c.Column.IsNullable == false); | ||
} | ||
} | ||
|
||
private class SkipRecursiveFKTraversalStrategy : IDependencyTraversalStrategy | ||
{ | ||
public bool Process(ForeignKeyInformation foreignKey) | ||
{ | ||
return foreignKey.Table != foreignKey.ReferencedTable; | ||
} | ||
} | ||
|
||
private class FollowAllForeignKeysTraversalStrategy : IDependencyTraversalStrategy | ||
{ | ||
public bool Process(ForeignKeyInformation foreignKey) => true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace DataDude.Schema | ||
{ | ||
public interface IDependencyTraversalStrategy | ||
{ | ||
bool Process(ForeignKeyInformation foreignKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters