Database migrations made easy
EasyMigration - simple SQL Server migrations with PowerShell, I’ve had this script sitting in my toolbox for quite a while, and now it’s finally time to share it. Why didn’t I do it earlier? Probably because I didn’t have a good name for it.
In short, it executes database migration scripts in a defined order and keeps track of what has already been executed. For full documentation, check out the GitHub repository.
Let’s take a quick look.
If you already have SQL Server and SSMS installed and running, you can skip the first two steps.
- Download and install SSMS and Docker
- Create a new SQL Server 2025 container using this docker-compose.yml file:
1services:
2 mssql:
3 image: mcr.microsoft.com/mssql/server:2025-latest
4 container_name: mssql-dev
5
6 environment:
7 ACCEPT_EULA: "Y"
8 MSSQL_PID: "Developer"
9 SA_PASSWORD: "P1s-Unsee-Me"
10
11 ports:
12 - "1433:1433"
13
14 mem_limit: 2g
- If the SqlServer module is not installed, install it from an elevated PowerShell prompt:
1Install-Module SqlServer
- Clone the easy-migration repository from my GitHub
- Using SSMS, run the schema.sql script in the context of the tempdb database
- Take a quick look to see how scripts are organized by phase in the migration.json file
Examples
To run the examples, open a PowerShell prompt in the example directory
Dry Run mode
1. (Join-Path $PSScriptRoot ".." "functions.ps1")
2
3Invoke-EasyMigration `
4 -ConnStr "Data Source=(local);Initial Catalog=tempdb;Connection Timeout=5;Encrypt=False;
5 User Id=sa;Password=P1s-Unsee-Me;Application Name=easy-migration;" `
6 -BasePath $PSScriptRoot `
7 -Phase "phase01" `
8 -ForceScripts "job007\000-kill-all-user-processes.sql" `
9 -Verbose `
10 -WhatIf
Output
What if: Performing the operation "Invoke-EasyMigration" on target "DataSource: (local), InitialCatalog: tempdb, Phase: phase01".
VERBOSE: Dry run
VERBOSE: Running migration script: 000-fix-this.sql
VERBOSE: Migration completed
VERBOSE: Running migration script: 001-fix-that.sql
VERBOSE: Migration completed
VERBOSE: Forcing migration script: job007\000-kill-all-user-processes.sql
VERBOSE: Running migration script: job007\000-kill-all-user-processes.sql
VERBOSE: Migration completed
VERBOSE: Easy as that!
Execute mode
1. (Join-Path $PSScriptRoot ".." "functions.ps1")
2
3Invoke-EasyMigration `
4 -ConnStr "Data Source=(local);Initial Catalog=tempdb;Connection Timeout=5;Encrypt=False;
5 User Id=sa;Password=P1s-Unsee-Me;Application Name=easy-migration;" `
6 -BasePath $PSScriptRoot `
7 -Phase "phase01" `
8 -ForceScripts "job007\000-kill-all-user-processes.sql" `
9 -Verbose
Output
VERBOSE: Performing the operation "Invoke-EasyMigration" on target "DataSource: (local), InitialCatalog: tempdb, Phase: phase01".
VERBOSE: Running migration script: 000-fix-this.sql
VERBOSE: I'm
VERBOSE: Going
VERBOSE: To
VERBOSE: Fix
VERBOSE: This
VERBOSE: Migration completed
VERBOSE: Running migration script: 001-fix-that.sql
VERBOSE: I'm going to fix that
VERBOSE: Migration completed
VERBOSE: Forcing migration script: job007\000-kill-all-user-processes.sql
VERBOSE: Running migration script: job007\000-kill-all-user-processes.sql
VERBOSE: Just kidding
VERBOSE: Migration completed
VERBOSE: Easy as that!
Hopefully it was easy to read and will be easy to use.
See you later!