fix(host): wire DB migration init + Plotly CDN + attribute fix on hand-written migration
Three fixes surfaced when launching the WPF host for the first time: 1. App.xaml.cs — call MarathonDbContextInitializer.InitializeAsync() between Host.Build() and Host.Start() so EF migrations + WAL pragma are applied BEFORE BackgroundServices race to query the DB. Without this, all pollers crashed on 'no such table: Events'. 2. wwwroot/index.html — added <script src='https://cdn.plot.ly/plotly-2.35.2.min.js'> before blazor.webview.js. Phase 6 reviewer flagged this for Phase 9, but charts are unrenderable without it; better to ship now. 3. Migrations/20260505000000_InitialCreate.cs — added [DbContext] and [Migration('20260505000000_InitialCreate')] attributes. Phase 2's hand-written migration was missing both, so EF saw 'no migrations to apply' even on a fresh DB. With the attributes, the migration runs on first launch and creates all tables (Events, Snapshots, Bets, EventResults, Anomalies, Sports, Leagues). Verified: clean DB → migration applied → all 7 tables created → pollers run with empty results (no data yet — UpcomingEventsPoller fires every 6h by default; first scrape will populate the DB).
This commit is contained in:
@@ -83,6 +83,17 @@ public partial class App : System.Windows.Application
|
||||
builder.Services.AddSingleton<MainWindow>();
|
||||
|
||||
Host = builder.Build();
|
||||
|
||||
// Apply EF migrations + WAL pragma BEFORE Host.Start() so the BackgroundServices
|
||||
// (LiveOddsPoller, AnomalyDetectionPoller, etc.) don't race the DB schema creation.
|
||||
// Resolved in a scope because MarathonDbContextInitializer is Scoped (DbContext lifetime).
|
||||
using (var initScope = Host.Services.CreateScope())
|
||||
{
|
||||
var initializer = initScope.ServiceProvider
|
||||
.GetRequiredService<Marathon.Infrastructure.Persistence.MarathonDbContextInitializer>();
|
||||
initializer.InitializeAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
Host.Start();
|
||||
|
||||
// Apply default culture from configuration before any UI renders.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Marathon.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
@@ -5,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
namespace Marathon.Infrastructure.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
[DbContext(typeof(MarathonDbContext))]
|
||||
[Migration("20260505000000_InitialCreate")]
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
<a class="dismiss" style="float: right; cursor: pointer; padding: 0 8px;">×</a>
|
||||
</div>
|
||||
|
||||
<!-- Plotly.js for OddsTimeline charts (Phase 6). Pinned major version 2.x. -->
|
||||
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js" charset="utf-8"></script>
|
||||
|
||||
<script src="_framework/blazor.webview.js" autostart="false"></script>
|
||||
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user