Skip to content

Commit

Permalink
Added sqlite data browser
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Nov 14, 2024
1 parent 09ea52d commit 485e7d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
internal static class TodoApiEfMigrationsExtensions
internal static class Extensions
{
public static IResourceBuilder<ExecutableResource>? AddTodoDbMigration(this IDistributedApplicationBuilder builder)
{
Expand Down Expand Up @@ -28,4 +28,7 @@ public static IResourceBuilder<ExecutableResource> AddEfMigration<TProject>(this
// TODO: Support passing a connection string
return builder.AddExecutable(name, "dotnet", projectDirectory, "ef", "database", "update", "--no-build");
}

public static string GetProjectDirectory(this IResourceBuilder<ProjectResource> project) =>
Path.GetDirectoryName(project.Resource.GetProjectMetadata().ProjectPath)!;
}
18 changes: 15 additions & 3 deletions TodoApi.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@

var todoapi = builder.AddProject<Projects.TodoApi>("todoapi");

builder.AddProject<Projects.Todo_Web_Server>("todo-web-server")
.WithReference(todoapi);

var dbDirectory = Path.Combine(todoapi.GetProjectDirectory(), ".db");

// Add sqlite-web to view the Todos.db database
var sqliteWeb = builder.AddContainer("sqliteweb", "tomdesinto/sqliteweb")
.WithHttpEndpoint(targetPort: 8080)
.WithBindMount(dbDirectory, "/db")
.WithArgs("Todos.db")
.ExcludeFromManifest();

if (migrateOperation is not null)
{
// Wait for the migration to complete before running the api
// Wait for the migration to complete before running the api and ui
todoapi.WaitForCompletion(migrateOperation);

sqliteWeb.WaitForCompletion(migrateOperation);
}

builder.AddProject<Projects.Todo_Web_Server>("todo-web-server")
.WithReference(todoapi);

builder.Build().Run();

0 comments on commit 485e7d4

Please sign in to comment.