Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commands to import from existing database or bacpac #337

Open
egil opened this issue Dec 18, 2024 · 0 comments
Open

Add commands to import from existing database or bacpac #337

egil opened this issue Dec 18, 2024 · 0 comments
Labels
integration A new .NET Aspire integration

Comments

@egil
Copy link

egil commented Dec 18, 2024

Related to an existing integration?

Yes

Existing integration

Hosting.SqlDatabaseProjects

Overview

Add commands "Import database" and "Import BacPac" to a SQL Server Database resource. While not related to DacPacs, it is very similar, and users are likely to need both features. The DacServices library is also used for this.

I have a "works on my machine" implementation shared here that could be a starting point for this feature: https://gist.github.com/egil/f3a9d42f58862913d95dbc0b6bba494e

Usage example

var builder = DistributedApplication.CreateBuilder(args);

var sqlPassword = builder.AddParameter("sql-password", secret: true);
var sqlserver = builder
    .AddSqlServer("sqlserver", password: sqlPassword)
    .WithDataVolume()
    .WithLifetime(ContainerLifetime.Persistent);

var importSourceConnectionString = "Server=[REPLACE].database.windows.net;Authentication=Active Directory Interactive;Database=[REPLACE];Encrypt=True;"
var db = sqlserver
    .AddDatabase("[REPLACE]")
    .WithDatabaseImportCommand(importSourceConnectionString);

var conStrResource = builder.AddConnectionString("my-source-database");
var db2 = sqlserver
    .AddDatabase("[REPLACE]")
    .WithDatabaseImportCommand(conStrResource);

var bacPacFilename = @"c:\backups\my-database.bac";
var db3 = sqlserver
    .AddDatabase("[REPLACE]")
    .WithBacPacImportCommand(bacPacFilename);

This is how one of the commands looks in the Aspire UI based on the sample in my GIST:

Image

Breaking change?

No

Alternatives

It could be released as a standalone package instead of including it in SqlDatabaseProjects.

Additional context

I published my GIST and got positive feedback on bsky: https://bsky.app/profile/did:plc:ng6rx44bjxrvoowr4ny6jpl3/post/3ldk2zrundc2g

Help us help you

Yes, but only if others can assist

@aaronpowell aaronpowell added the integration A new .NET Aspire integration label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration A new .NET Aspire integration
Projects
None yet
Development

No branches or pull requests

2 participants