Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard committed Sep 30, 2022
1 parent 522b618 commit 5aae60b
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions Respawn/Checkpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

namespace Respawn
{
public class Checkpoint
{
private IList<TemporalTable> _temporalTables = new List<TemporalTable>();

public Table[] TablesToIgnore { get; init; } = Array.Empty<Table>();
public Table[] TablesToInclude { get; init; } = Array.Empty<Table>();
public string[] SchemasToInclude { get; init; } = Array.Empty<string>();
public string[] SchemasToExclude { get; init; } = Array.Empty<string>();
public class Checkpoint
{
private IList<TemporalTable> _temporalTables = new List<TemporalTable>();

public Table[] TablesToIgnore { get; init; } = Array.Empty<Table>();
public Table[] TablesToInclude { get; init; } = Array.Empty<Table>();
public string[] SchemasToInclude { get; init; } = Array.Empty<string>();
public string[] SchemasToExclude { get; init; } = Array.Empty<string>();
public string? DeleteSql { get; private set; }
public string? ReseedSql { get; private set; }
public bool CheckTemporalTables { get; init; }
public bool WithReseed { get; init; }
public IDbAdapter DbAdapter { get; init; } = Respawn.DbAdapter.SqlServer;
public string? ReseedSql { get; private set; }
public bool CheckTemporalTables { get; init; }
public bool WithReseed { get; init; }
public IDbAdapter DbAdapter { get; init; } = Respawn.DbAdapter.SqlServer;

public int? CommandTimeout { get; init; }
public int? CommandTimeout { get; init; }

public virtual async Task Reset(string nameOrConnectionString)
public virtual async Task Reset(string nameOrConnectionString)
{
await using var connection = new SqlConnection(nameOrConnectionString);

Expand All @@ -33,18 +33,18 @@ public virtual async Task Reset(string nameOrConnectionString)
await Reset(connection);
}

public virtual async Task Reset(DbConnection connection)
{
if (string.IsNullOrWhiteSpace(DeleteSql))
{
await BuildDeleteTables(connection);
}
public virtual async Task Reset(DbConnection connection)
{
if (string.IsNullOrWhiteSpace(DeleteSql))
{
await BuildDeleteTables(connection);
}

if (_temporalTables.Any())
{
var turnOffVersioningCommandText = DbAdapter.BuildTurnOffSystemVersioningCommandText(_temporalTables);
await ExecuteAlterSystemVersioningAsync(connection, turnOffVersioningCommandText);
}
if (_temporalTables.Any())
{
var turnOffVersioningCommandText = DbAdapter.BuildTurnOffSystemVersioningCommandText(_temporalTables);
await ExecuteAlterSystemVersioningAsync(connection, turnOffVersioningCommandText);
}

try
{
Expand All @@ -60,7 +60,7 @@ public virtual async Task Reset(DbConnection connection)
}
}

private async Task ExecuteAlterSystemVersioningAsync(DbConnection connection, string commandText)
private async Task ExecuteAlterSystemVersioningAsync(DbConnection connection, string commandText)
{
await using var tx = await connection.BeginTransactionAsync();
await using var cmd = connection.CreateCommand();
Expand All @@ -74,7 +74,7 @@ private async Task ExecuteAlterSystemVersioningAsync(DbConnection connection, st
await tx.CommitAsync();
}

private async Task ExecuteDeleteSqlAsync(DbConnection connection)
private async Task ExecuteDeleteSqlAsync(DbConnection connection)
{
await using var tx = await connection.BeginTransactionAsync();
await using var cmd = connection.CreateCommand();
Expand All @@ -94,30 +94,30 @@ private async Task ExecuteDeleteSqlAsync(DbConnection connection)
await tx.CommitAsync();
}

private async Task BuildDeleteTables(DbConnection connection)
{
var allTables = await GetAllTables(connection);
private async Task BuildDeleteTables(DbConnection connection)
{
var allTables = await GetAllTables(connection);

if (CheckTemporalTables && await DbAdapter.CheckSupportsTemporalTables(connection))
{
_temporalTables = await GetAllTemporalTables(connection);
}
if (CheckTemporalTables && await DbAdapter.CheckSupportsTemporalTables(connection))
{
_temporalTables = await GetAllTemporalTables(connection);
}

var allRelationships = await GetRelationships(connection);
var allRelationships = await GetRelationships(connection);

var graphBuilder = new GraphBuilder(allTables, allRelationships);
var graphBuilder = new GraphBuilder(allTables, allRelationships);

DeleteSql = DbAdapter.BuildDeleteCommandText(graphBuilder);
ReseedSql = WithReseed ? DbAdapter.BuildReseedSql(graphBuilder.ToDelete) : null;
}
DeleteSql = DbAdapter.BuildDeleteCommandText(graphBuilder);
ReseedSql = WithReseed ? DbAdapter.BuildReseedSql(graphBuilder.ToDelete) : null;
}

private async Task<HashSet<Relationship>> GetRelationships(DbConnection connection)
{
var relationships = new HashSet<Relationship>();
var commandText = DbAdapter.BuildRelationshipCommandText(this);
private async Task<HashSet<Relationship>> GetRelationships(DbConnection connection)
{
var relationships = new HashSet<Relationship>();
var commandText = DbAdapter.BuildRelationshipCommandText(this);

await using var cmd = connection.CreateCommand();

cmd.CommandText = commandText;

await using var reader = await cmd.ExecuteReaderAsync();
Expand All @@ -131,13 +131,13 @@ private async Task<HashSet<Relationship>> GetRelationships(DbConnection connecti
}

return relationships;
}
}

private async Task<HashSet<Table>> GetAllTables(DbConnection connection)
{
var tables = new HashSet<Table>();
private async Task<HashSet<Table>> GetAllTables(DbConnection connection)
{
var tables = new HashSet<Table>();

var commandText = DbAdapter.BuildTableCommandText(this);
var commandText = DbAdapter.BuildTableCommandText(this);

await using var cmd = connection.CreateCommand();

Expand All @@ -151,13 +151,13 @@ private async Task<HashSet<Table>> GetAllTables(DbConnection connection)
}

return tables;
}
}

private async Task<IList<TemporalTable>> GetAllTemporalTables(DbConnection connection)
{
var tables = new List<TemporalTable>();
private async Task<IList<TemporalTable>> GetAllTemporalTables(DbConnection connection)
{
var tables = new List<TemporalTable>();

var commandText = DbAdapter.BuildTemporalTableCommandText(this);
var commandText = DbAdapter.BuildTemporalTableCommandText(this);

await using var cmd = connection.CreateCommand();

Expand All @@ -171,6 +171,6 @@ private async Task<IList<TemporalTable>> GetAllTemporalTables(DbConnection conne
}

return tables;
}
}
}
}
}

0 comments on commit 5aae60b

Please sign in to comment.