Flaminco.Migration.SqlServer
1.0.0
dotnet add package Flaminco.Migration.SqlServer --version 1.0.0
NuGet\Install-Package Flaminco.Migration.SqlServer -Version 1.0.0
<PackageReference Include="Flaminco.Migration.SqlServer" Version="1.0.0" />
paket add Flaminco.Migration.SqlServer --version 1.0.0
#r "nuget: Flaminco.Migration.SqlServer, 1.0.0"
// Install Flaminco.Migration.SqlServer as a Cake Addin #addin nuget:?package=Flaminco.Migration.SqlServer&version=1.0.0 // Install Flaminco.Migration.SqlServer as a Cake Tool #tool nuget:?package=Flaminco.Migration.SqlServer&version=1.0.0
Flaminco.Migration.SqlServer
Flaminco.Migration.SqlServer
is designed to simplify the process of executing database migration scripts embedded within your
.NET assemblies built using (DbUP). By leveraging this library, you can ensure that your database schema is up-to-date
with the latest changes whenever your application starts. This library supports the use of directories to organize and
prioritize the execution order of your scripts.
Features
- Execute database migration scripts embedded in assemblies.
- Supports organizing scripts into directories with prioritized execution order.
- Integrated with IHostedService to ensure migrations are run before the application starts accepting requests.
- Leverage
appsettings.json
for configuration. - Supports for always executing migration scripts.
Installation
dotnet add package Flaminco.Migration.SqlServer
Getting Started
Installation
Step 1: Add Migration to Your Services
To get started with Flaminco.Migration.SqlServer
, you need to configure the Migration services in your ASP.NET Core application.
You can do this by adding the following line:
Using Direct Configuration
builder.Services.AddMigration<Program>(options =>
{
options.ConnectionString = "Server=localhost;****";
options.Directories = ["WebApplication1.Scripts.Tables","WebApplication1.Scripts.StoredProcedures"];
options.AlwaysExexuteDirectories = ["WebApplication1.Scripts.StoredProcedures"]; // means run the scripts inside these directories each time the upgrader run.
});
Using Configuration from appsettings.json
{
"Migration": {
"ConnectionString": "Server=localhost;****",
"Directories": [
"WebApplication1.Scripts.Tables",
"WebApplication1.Scripts.StoredProcedures"
],
"AlwaysExecuteDirectories": [
"WebApplication1.Scripts.StoredProcedures"
]
}
}
Modify your Program.cs or Startup.cs to use the configuration:
builder.Services.AddMigration<Program>(builder.Configuration);
Step 2: Embed Your SQL Scripts
Ensure your SQL scripts are embedded as resources in your project. Modify your .csproj file to include the scripts:
<ItemGroup>
<EmbeddedResource Include="Scripts\Tables\**\*.sql" />
<EmbeddedResource Include="Scripts\StoredProcedures\**\*.sql" />
</ItemGroup>
Step 3: Ensure the Correct Execution Order
The order of directories specified in the Directories array will determine the execution order of the scripts. In the above example, scripts in the Tables directory will be executed before those in the StoredProcedures directory. If no directories are specified, all scripts in the assembly will be loaded and executed by the default DbUp ordering mechanism.
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- dbup-sqlserver (>= 6.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 92 | 11/9/2024 |