microsoft / microsoft/aspire

Add WithDatabaseBackup to SQL Server integration

Open
#15,839 2 comments 0 reactions 0 assignees View on GitHub
area-integrations enhancement
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

In development you might not always want to start from an empty database, but you might have a backup that is used by all developers.
This is adding extra steps for the developers during the onboarding and it requires a manual restore when the developer needs to have a clean database.

### Describe the solution you'd like

Add a new extension to the SQL Server database integration
```csharp
var sql = builder.AddSqlServer("sql")
.WithLifetime(ContainerLifetime.Persistent);

var db = sql.AddDatabase(databaseName)
.WithDatabaseRestore(string backupFilepath)
```
The method should check if the database exits, if it does exist it does nothing. If the database does not exist it will create the database using the backup file.

The feature should also add a restore command to the sql resource in the dashboard. The command should force the restore of the backup on the existing database.

This helps the dev experience when the database exists, but the developer wants to start with a "clean" database.

### Additional context

I have looked into adding the feature to the SQL Server Community integration, but this is a cleaner way. When using the community integration first the database needs to be created and only then the backup can be restored.

I already have a large part of the code ready as we are using it in our projects, so I am happy to contribute.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.