-
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.
Sync changes from TRS DB into DQT reporting database (#1451)
- Loading branch information
Showing
17 changed files
with
2,957 additions
and
39 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
42 changes: 42 additions & 0 deletions
42
...hingRecordSystem/src/TeachingRecordSystem.Cli/Commands.DropDqtReportingReplicationSlot.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Npgsql; | ||
using TeachingRecordSystem.Core.DataStore.Postgres; | ||
using TeachingRecordSystem.Core.Services.DqtReporting; | ||
|
||
namespace TeachingRecordSystem.Cli; | ||
|
||
public partial class Commands | ||
{ | ||
public static Command CreateDropDqtReportingReplicationSlotCommand(IConfiguration configuration) | ||
{ | ||
var connectionStringOption = new Option<string>("--connection-string") { IsRequired = true }; | ||
|
||
var configuredConnectionString = configuration.GetConnectionString("DefaultConnection"); | ||
if (configuredConnectionString is not null) | ||
{ | ||
connectionStringOption.SetDefaultValue(configuredConnectionString); | ||
} | ||
|
||
var command = new Command("drop-dqt-reporting-replication-slot", "Drops the logical replication slot for the DQT Reporting Service.") | ||
{ | ||
connectionStringOption | ||
}; | ||
|
||
command.SetHandler( | ||
async (string connectionString) => | ||
{ | ||
using var dbContext = TrsDbContext.Create(connectionString, commandTimeout: (int)TimeSpan.FromMinutes(10).TotalSeconds); | ||
|
||
// Ensure the user has the replication permission | ||
var user = new NpgsqlConnectionStringBuilder(connectionString).Username; | ||
#pragma warning disable EF1002 // Risk of vulnerability to SQL injection. | ||
await dbContext.Database.ExecuteSqlRawAsync($"alter user {user} with replication"); | ||
#pragma warning restore EF1002 // Risk of vulnerability to SQL injection. | ||
|
||
await dbContext.Database.ExecuteSqlRawAsync( | ||
$"select pg_drop_replication_slot('{DqtReportingOptions.DefaultTrsDbReplicationSlotName}');"); | ||
}, | ||
connectionStringOption); | ||
|
||
return command; | ||
} | ||
} |
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
Oops, something went wrong.