A collection of handy scripts for .NET Entity Framework Core migrations and database management.
dotnet-ef global tool installed:
dotnet tool install --global dotnet-ef
Bash shell environment (macOS, Linux, or WSL / Git Bash on Windows)
Copy and run these in your own folder path.
[!NOTE] Before running a script for the first time, open your terminal and make it executable by running:
chmod +x <folder-path>/<script-name>.sh
Description:
Adds a new Entity Framework Core migration and immediately applies it to the target database.
Usage:
./<folder-path>/add-migration.sh <migration-name> [project-path]
Parameters:
<migration-name> (Required): The name of the new migration (e.g., AddUserTable).[project-path] (Optional): Path to the .NET project containing the DbContext/migrations. Defaults to ./src/Migrations.Example:
./scripts/add-migration.sh AddUserTable ./src/MyProject
Description:
Safely removes a migration from both the database and the codebase. It verifies the target migration exists in the migration history, rolls back the database to the preceding migration state (or state 0 if removing the initial migration), and removes the migration from code.
Usage:
./<folder-path>/remove-migration.sh <migration-name-to-remove> [project-path]
Parameters:
<migration-name-to-remove> (Required): The name of the migration to remove.[project-path] (Optional): Path to the .NET project containing the DbContext/migrations. Defaults to ./src/Migrations.Example:
./scripts/remove-migration.sh AddUserTable ./src/MyProject
1 commits
Shell
100.0%
A collection of handy scripts for .NET Entity Framework Core migrations and database management.
dotnet-ef global tool installed:
dotnet tool install --global dotnet-ef
Bash shell environment (macOS, Linux, or WSL / Git Bash on Windows)
Copy and run these in your own folder path.
[!NOTE] Before running a script for the first time, open your terminal and make it executable by running:
chmod +x <folder-path>/<script-name>.sh
Description:
Adds a new Entity Framework Core migration and immediately applies it to the target database.
Usage:
./<folder-path>/add-migration.sh <migration-name> [project-path]
Parameters:
<migration-name> (Required): The name of the new migration (e.g., AddUserTable).[project-path] (Optional): Path to the .NET project containing the DbContext/migrations. Defaults to ./src/Migrations.Example:
./scripts/add-migration.sh AddUserTable ./src/MyProject
Description:
Safely removes a migration from both the database and the codebase. It verifies the target migration exists in the migration history, rolls back the database to the preceding migration state (or state 0 if removing the initial migration), and removes the migration from code.
Usage:
./<folder-path>/remove-migration.sh <migration-name-to-remove> [project-path]
Parameters:
<migration-name-to-remove> (Required): The name of the migration to remove.[project-path] (Optional): Path to the .NET project containing the DbContext/migrations. Defaults to ./src/Migrations.Example:
./scripts/remove-migration.sh AddUserTable ./src/MyProject
1 commits
Shell
100.0%