Nabs.Launchpad.Core.MigrationsCli
10.0.221
Prefix Reserved
dotnet add package Nabs.Launchpad.Core.MigrationsCli --version 10.0.221
NuGet\Install-Package Nabs.Launchpad.Core.MigrationsCli -Version 10.0.221
<PackageReference Include="Nabs.Launchpad.Core.MigrationsCli" Version="10.0.221" />
<PackageVersion Include="Nabs.Launchpad.Core.MigrationsCli" Version="10.0.221" />
<PackageReference Include="Nabs.Launchpad.Core.MigrationsCli" />
paket add Nabs.Launchpad.Core.MigrationsCli --version 10.0.221
#r "nuget: Nabs.Launchpad.Core.MigrationsCli, 10.0.221"
#:package Nabs.Launchpad.Core.MigrationsCli@10.0.221
#addin nuget:?package=Nabs.Launchpad.Core.MigrationsCli&version=10.0.221
#tool nuget:?package=Nabs.Launchpad.Core.MigrationsCli&version=10.0.221
Nabs Launchpad Core Migrations CLI Library
⚠️ Warning: This package depends on prerelease packages and is intended for development and testing purposes. Use with caution in production environments.
A .NET 10 console application library for managing Entity Framework Core database migrations with an interactive terminal interface using Spectre.Console.
Overview
The Nabs.Launchpad.Core.MigrationsCli library provides a command-line interface for managing database migrations and schema changes. It offers both interactive menu-driven and command-line argument modes for flexibility in development and CI/CD workflows.
Key Features
- List Migrations: Display all DbContexts with their outstanding model changes, migration history, and seed data processors
- Add Migrations: Create new migrations for DbContexts with pending model changes
- Remove Migrations: Remove the last migration from a DbContext (in progress)
- Reset All Migrations: Delete all migrations and start over (in progress)
- Apply Migrations: Apply pending migrations to the local database
- Drop Database: Drop the design-time database with confirmation prompts
- Interactive Menu: User-friendly terminal menu using Spectre.Console
- Risk Analysis: Classify pending model changes by risk level (high, medium, low)
Getting Started
To use the Nabs Launchpad Core Migrations CLI library, follow these steps:
1. Create a Console Application
Create a new console application project in your .NET solution:
dotnet new console -n MyProject.MigrationsCli
2. Add Required References
Reference the Nabs.Launchpad.Core.MigrationsCli library in your console application project:
<ItemGroup>
<ProjectReference Include="..\Nabs.Launchpad.Core.MigrationsCli\Nabs.Launchpad.Core.MigrationsCli.csproj" />
<ProjectReference Include="..\MyProject.Migrations\MyProject.Migrations.csproj" />
</ItemGroup>
3. Configure Program.cs
Add the following code to your Program.cs file:
using Nabs.Launchpad.Core.MigrationsCli;
var migrationsConsole = new MigrationsConsole();
// Register your DbContext, SeedDataProcessor, and DesignTimeDbContextFactory
migrationsConsole.AddMigration<MyDbContext, MySeedDataProcessor, MyDesignTimeDbContextFactory>("myDatabaseConnection");
// Add additional DbContexts as needed
migrationsConsole.AddMigration<AnotherDbContext, AnotherSeedDataProcessor, AnotherDesignTimeDbContextFactory>("anotherDatabaseConnection");
await migrationsConsole.RunAsync(args);
4. Create Supporting Classes
Ensure you have a migrations project with:
- DbContext: Your Entity Framework Core database context
- IDesignTimeDbContextFactory: For design-time DbContext creation (required)
- ISeedDataProcessor: For seeding initial or test data
Commands
List Migrations (list-migrations)
Display the current state of migrations for all registered DbContexts:
dotnet run -- list-migrations
This command shows:
- Outstanding Model Changes: Pending changes with risk level indicators
- 🚩 High risk (destructive operations like dropping tables/columns)
- ⚠️ Medium risk (altering columns, adding/dropping foreign keys)
- ✅ Low risk (adding columns/tables)
- Migration History: Applied and pending migrations with timestamps
- Seed Data Processors: Registered seed data processors for each DbContext
Add Migrations (add-migrations)
Create a new migration for DbContexts with pending model changes:
dotnet run -- add-migrations
dotnet run -- add-migrations --context PrimaryDbContext --migrationName AddCustomerTable
In interactive mode, you will be prompted to enter a migration name. In non-interactive mode, the --migrationName parameter is required.
Apply Migrations (apply-migrations)
Apply pending migrations to the database:
dotnet run -- apply-migrations
dotnet run -- apply-migrations --context PrimaryDbContext
dotnet run -- apply-migrations --context PrimaryDbContext --migrationName InitialCreate
Note: If there are pending model changes that haven't been added as migrations, the command will warn you and skip that DbContext.
Remove Migrations (remove-migrations)
Remove the last migration from a DbContext:
dotnet run -- remove-migrations
dotnet run -- remove-migrations --context PrimaryDbContext
Reset Migrations (reset-migrations)
Delete all migrations and start fresh:
dotnet run -- reset-migrations
dotnet run -- reset-migrations --project MyProject.DataMigrations
Drop Database (drop-db)
Drop the design-time database (requires confirmation):
dotnet run -- drop-db
dotnet run -- drop-db --context PrimaryDbContext
This command will:
- Check if the database exists before attempting to drop
- Prompt for confirmation before dropping each database
- Display success or skip messages for each operation
Interactive Mode
Running the application without arguments launches an interactive menu:
dotnet run
This displays a menu with options:
- List Migrations
- Add Migrations
- Apply Migrations
- Remove Migrations
- Reset Migrations
- Drop Database (only works for IDesignTimeDbContextFactory)
- Exit
Dependencies
- .NET 10: Target framework
- Microsoft.EntityFrameworkCore: Core EF abstractions
- Microsoft.EntityFrameworkCore.SqlServer: SQL Server provider
- Microsoft.Extensions.Hosting: Hosting abstractions
- Spectre.Console: Rich console output and interactive menus
- Spectre.Console.Cli: Command-line argument parsing
- Nabs.Launchpad.Core.Migrations: Core migration interfaces
Risk Classification
The CLI analyzes pending model changes and classifies them by risk level:
| Operation | Risk Level | Icon |
|---|---|---|
| Drop Table | High | 🚩 |
| Drop Column | High | 🚩 |
| Rename Table | High | 🚩 |
| Add Foreign Key (with CASCADE delete) | High | 🚩 |
| Alter Column | Medium | ⚠️ |
| Add Column (non-nullable without default) | Medium | ⚠️ |
| Add Foreign Key | Medium | ⚠️ |
| Drop Foreign Key | Medium | ⚠️ |
| Create Table | Low | ✅ |
| Add Column (nullable or with default) | Low | ✅ |
| Create Index | Low | ✅ |
| Ensure Schema | Low | ✅ |
Work In Progress
The following features are currently under development:
- Remove Migrations Command: Implementation for removing last migration
- Reset Migrations Command: Implementation for resetting all migrations
- Context Filtering: Filter commands by specific DbContext name
- Migration Name Filtering: Apply specific migrations by name
Integration with Launchpad
This library is part of the Nabs Launchpad framework and works with:
- Core.Migrations: Provides
ISeedDataProcessorandIMigrationsProcessorinterfaces - Core.Persistence: Works with Entity Framework DbContext configurations
Best Practices
- Use Design-Time Factories: Implement
IDesignTimeDbContextFactory<TDbContext>for reliable DbContext creation (required for registration) - Review Risk Analysis: Always review the risk classification before applying migrations
- Backup Before Destructive Operations: High-risk operations may result in data loss
- Test Migrations Locally: Apply migrations to a local database before production
- Use Interactive Mode for Development: The menu-driven interface is ideal for development workflows
- Check for Pending Model Changes: The apply-migrations command will warn you if there are uncommitted model changes
License
Copyright © Net Advantage Business Solutions
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.2)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.2)
- Microsoft.Extensions.Hosting (>= 10.0.2)
- Nabs.Launchpad.Core.Migrations (>= 10.0.221)
- Spectre.Console (>= 0.54.1-alpha.0.31)
- Spectre.Console.Cli (>= 1.0.0-alpha.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.