A little project for creation new databases in MS SQL Server from SQL Project files under .NET Core and Docker environment.
Unfortunately we cannot use Microsoft SSDT under Linux environment to create/migrate database version. But sometimes we want to run our tests from Docker and automatic database creation is really important detail for this. This library allows you to create and remove database easily.
dotnet add package SqlDeploy
- The lib can create database only. It cannot migrate or update exists databases.
- Creation script doesn't sort your DB objects by relations nad creates objects one by one as they are defined in *.sqlproj file. So you have to sort you objects manually to prevent errors bad relations order.
// Create a deployer
var deployer = new SqlProjectDeployer("path/to/your.sqlproj");
// Create a new db
var database = await deployer.RecreateToAsync(
new SqlConnection("<connection string to MS SQL>"),
databaseName: "NewDBName");
// You can work with the new DB here
// Delete the database after tests
await database.DeleteAsync();