Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,46 @@
}
}

private async Task SetDbInSimpleMode(CancellationToken cancellationToken)
{
var dbName = this.Database.GetDbConnection().Database;

var connection = this.Database.GetDbConnection();
if (connection.State != System.Data.ConnectionState.Open)

Check notice on line 230 in TransactionProcessor.Database/Contexts/EstateManagementGenericContext.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessor.Database/Contexts/EstateManagementGenericContext.cs#L230

Add curly braces around the nested statement(s) in this 'if' block.
await connection.OpenAsync(cancellationToken);

// 1. Check current recovery model
await using var checkCommand = connection.CreateCommand();
checkCommand.CommandText = @"
SELECT recovery_model_desc
FROM sys.databases
WHERE name = @dbName;
";
var param = checkCommand.CreateParameter();
param.ParameterName = "@dbName";
param.Value = dbName;
checkCommand.Parameters.Add(param);

var result = await checkCommand.ExecuteScalarAsync(cancellationToken);
var currentRecoveryModel = result?.ToString();

if (currentRecoveryModel != "SIMPLE")
{
// 2. Alter database outside transaction
await using var alterCommand = connection.CreateCommand();
alterCommand.CommandText = $@"
ALTER DATABASE [{dbName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE [{dbName}] SET RECOVERY SIMPLE;
ALTER DATABASE [{dbName}] SET MULTI_USER;
";
// Execute outside EF transaction
await alterCommand.ExecuteNonQueryAsync(cancellationToken);
}
}




public static Boolean IsDuplicateInsertsIgnored(String tableName) =>
EstateManagementContext.TablesToIgnoreDuplicates.Contains(tableName.Trim(), StringComparer.InvariantCultureIgnoreCase);

Expand All @@ -234,6 +274,8 @@
await this.CreateViews(cancellationToken);
await this.SeedStandingData(cancellationToken);
await this.CreateStoredProcedures(cancellationToken);
await this.SetDbInSimpleMode(cancellationToken);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.14")
.HasAnnotation("ProductVersion", "9.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
Expand Down Expand Up @@ -65,7 +65,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Date");

b.ToTable("calendar");
b.ToTable("calendar", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Contract", b =>
Expand All @@ -91,7 +91,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("EstateId", "OperatorId", "ContractId");

b.ToTable("contract");
b.ToTable("contract", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.ContractProduct", b =>
Expand Down Expand Up @@ -127,7 +127,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("ContractProductId", "ContractId")
.IsUnique();

b.ToTable("contractproduct");
b.ToTable("contractproduct", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.ContractProductTransactionFee", b =>
Expand Down Expand Up @@ -165,7 +165,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("ContractProductTransactionFeeId", "ContractProductId")
.IsUnique();

b.ToTable("contractproducttransactionfee");
b.ToTable("contractproducttransactionfee", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Estate", b =>
Expand Down Expand Up @@ -194,7 +194,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("EstateId")
.IsUnique();

b.ToTable("estate");
b.ToTable("estate", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.EstateSecurityUser", b =>
Expand All @@ -214,7 +214,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("SecurityUserId", "EstateId");

b.ToTable("estatesecurityuser");
b.ToTable("estatesecurityuser", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.File", b =>
Expand Down Expand Up @@ -261,7 +261,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("FileId")
.IsUnique();

b.ToTable("file");
b.ToTable("file", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.FileImportLog", b =>
Expand Down Expand Up @@ -289,7 +289,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("EstateId", "FileImportLogId")
.IsUnique();

b.ToTable("fileimportlog");
b.ToTable("fileimportlog", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.FileImportLogFile", b =>
Expand Down Expand Up @@ -325,7 +325,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("FileImportLogId", "FileId");

b.ToTable("fileimportlogfile");
b.ToTable("fileimportlogfile", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.FileLine", b =>
Expand All @@ -351,7 +351,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("FileId", "LineNumber"));

b.ToTable("fileline");
b.ToTable("fileline", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Float", b =>
Expand Down Expand Up @@ -383,7 +383,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("CreatedDate"));

b.ToTable("Floats");
b.ToTable("Floats", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.FloatActivity", b =>
Expand Down Expand Up @@ -419,7 +419,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("ActivityDate"));

b.ToTable("FloatActivity");
b.ToTable("FloatActivity", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Merchant", b =>
Expand Down Expand Up @@ -463,7 +463,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("EstateId", "MerchantId")
.IsUnique();

b.ToTable("merchant");
b.ToTable("merchant", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.MerchantAddress", b =>
Expand Down Expand Up @@ -504,7 +504,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("MerchantId", "AddressId");

b.ToTable("merchantaddress");
b.ToTable("merchantaddress", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.MerchantContact", b =>
Expand All @@ -530,7 +530,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("MerchantId", "ContactId");

b.ToTable("merchantcontact");
b.ToTable("merchantcontact", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.MerchantContract", b =>
Expand All @@ -546,7 +546,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("MerchantId", "ContractId");

b.ToTable("MerchantContracts");
b.ToTable("MerchantContracts", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.MerchantDevice", b =>
Expand All @@ -566,7 +566,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("MerchantId", "DeviceId");

b.ToTable("merchantdevice");
b.ToTable("merchantdevice", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.MerchantOperator", b =>
Expand All @@ -592,7 +592,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("MerchantId", "OperatorId");

b.ToTable("merchantoperator");
b.ToTable("merchantoperator", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.MerchantSecurityUser", b =>
Expand All @@ -612,7 +612,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("MerchantId", "SecurityUserId");

b.ToTable("merchantsecurityuser");
b.ToTable("merchantsecurityuser", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.MerchantSettlementFee", b =>
Expand Down Expand Up @@ -643,7 +643,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("SettlementId", "TransactionId", "ContractProductTransactionFeeId");

b.ToTable("merchantsettlementfee");
b.ToTable("merchantsettlementfee", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Operator", b =>
Expand Down Expand Up @@ -675,7 +675,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("OperatorId")
.IsUnique();

b.ToTable("operator");
b.ToTable("operator", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Reconciliation", b =>
Expand Down Expand Up @@ -735,7 +735,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("TransactionId", "MerchantId"), false);

b.ToTable("reconciliation");
b.ToTable("reconciliation", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.ResponseCodes", b =>
Expand All @@ -752,7 +752,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("ResponseCode");

b.ToTable("responsecodes");
b.ToTable("responsecodes", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Settlement", b =>
Expand Down Expand Up @@ -797,7 +797,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("EstateId", "SettlementId"), false);

b.ToTable("settlement");
b.ToTable("settlement", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.StatementHeader", b =>
Expand Down Expand Up @@ -834,7 +834,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("StatementGeneratedDate"));

b.ToTable("statementheader");
b.ToTable("statementheader", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.StatementLine", b =>
Expand Down Expand Up @@ -865,7 +865,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("StatementId", "TransactionId", "ActivityDateTime", "ActivityType");

b.ToTable("statementline");
b.ToTable("statementline", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Summary.SettlementSummary", b =>
Expand Down Expand Up @@ -907,7 +907,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("SettlementDate", "MerchantReportingId", "OperatorReportingId", "ContractProductReportingId", "IsCompleted", "IsSettled")
.IsUnique();

b.ToTable("SettlementSummary");
b.ToTable("SettlementSummary", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Summary.TodayTransaction", b =>
Expand Down Expand Up @@ -989,7 +989,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("TransactionId")
.IsUnique();

b.ToTable("TodayTransactions");
b.ToTable("TodayTransactions", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Summary.TransactionHistory", b =>
Expand Down Expand Up @@ -1071,7 +1071,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("TransactionId")
.IsUnique();

b.ToTable("TransactionHistory");
b.ToTable("TransactionHistory", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.Transaction", b =>
Expand Down Expand Up @@ -1152,7 +1152,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("TransactionId"), false);

b.ToTable("transaction");
b.ToTable("transaction", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.TransactionAdditionalRequestData", b =>
Expand All @@ -1168,7 +1168,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("TransactionId");

b.ToTable("transactionadditionalrequestdata");
b.ToTable("transactionadditionalrequestdata", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.TransactionAdditionalResponseData", b =>
Expand All @@ -1181,7 +1181,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("TransactionId");

b.ToTable("transactionadditionalresponsedata");
b.ToTable("transactionadditionalresponsedata", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.TransactionTimings", b =>
Expand Down Expand Up @@ -1215,7 +1215,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("TransactionId"), false);

b.ToTable("transactiontimings");
b.ToTable("transactiontimings", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.Entities.VoucherProjectionState", b =>
Expand Down Expand Up @@ -1295,7 +1295,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("VoucherCode");

b.ToTable("voucherprojectionstate");
b.ToTable("voucherprojectionstate", (string)null);
});

modelBuilder.Entity("TransactionProcessor.Database.ViewEntities.SettlementView", b =>
Expand Down Expand Up @@ -1376,7 +1376,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("EventId", "Type"));

b.ToTable("Events");
b.ToTable("Events", (string)null);
});

modelBuilder.Entity("TransactionProcessor.ProjectionEngine.Database.Database.Entities.MerchantBalanceChangedEntry", b =>
Expand Down Expand Up @@ -1412,7 +1412,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("AggregateId", "OriginalEventId");

b.ToTable("MerchantBalanceChangedEntry");
b.ToTable("MerchantBalanceChangedEntry", (string)null);
});

modelBuilder.Entity("TransactionProcessor.ProjectionEngine.Database.Database.Entities.MerchantBalanceProjectionState", b =>
Expand Down Expand Up @@ -1486,7 +1486,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("EstateId", "MerchantId");

b.ToTable("MerchantBalanceProjectionState");
b.ToTable("MerchantBalanceProjectionState", (string)null);
});

modelBuilder.Entity("TransactionProcessor.ProjectionEngine.Database.Database.ViewEntities.MerchantBalanceHistoryViewEntry", b =>
Expand Down
Loading