Skip to content

Commit

Permalink
Move reporting DB migrations into Worker start up (#1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Jul 5, 2024
1 parent 0ac5831 commit 551adf6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.PowerPlatform.Dataverse.Client;
using TeachingRecordSystem.Core.Dqt;
Expand All @@ -26,6 +27,15 @@ public static IHostApplicationBuilder AddDqtReporting(this IHostApplicationBuild
sp => new ServiceClient(sp.GetRequiredService<IOptions<DqtReportingOptions>>().Value.CrmConnectionString));

builder.Services.AddCrmEntityChangesService(name: DqtReportingService.CrmClientName);

builder.Services.AddStartupTask(sp =>
{
var migrator = new Migrator(
connectionString: sp.GetRequiredService<IOptions<DqtReportingOptions>>().Value.ReportingDbConnectionString,
logger: sp.GetRequiredService<ILoggerFactory>().CreateLogger<Migrator>());
migrator.MigrateDb();
return Task.CompletedTask;
});
}

return builder;
Expand Down
2 changes: 1 addition & 1 deletion terraform/aks/app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ module "worker_application_configuration" {

module "worker_application" {
source = "git::https://github.com/DFE-Digital/terraform-modules.git//aks/application?ref=testing"
depends_on = [kubernetes_job.migrations, kubernetes_job.reporting_migrations]
depends_on = [kubernetes_job.migrations]

name = "worker"
is_web = false
Expand Down
32 changes: 0 additions & 32 deletions terraform/aks/dqt-reporting.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,3 @@ resource "azurerm_mssql_database" "reporting_db" {
]
}
}

resource "kubernetes_job" "reporting_migrations" {
metadata {
name = "${var.service_name}-${var.environment_name}-reporting-migrations"
namespace = var.namespace
}

spec {
template {
metadata {}
spec {
container {
name = "cli"
image = var.docker_image
command = ["trscli"]
args = ["migrate-reporting-db", "--connection-string", "$(CONNECTION_STRING)"]

env {
name = "CONNECTION_STRING"
value = local.reporting_db_connection_string
}
}

restart_policy = "Never"
}
}

backoff_limit = 1
}

wait_for_completion = true
}

0 comments on commit 551adf6

Please sign in to comment.