Migratio is a PowerShell module to handle database migrations and seeding. It supports rollout, rollback and seeding data. |
---|
Have the need to use variables or secrets in your script? Migratio supports that as well. |
So far Migratio only supports PostgreSQL, but MSSQL is alo planned. Submit a feature request in the issues if you wish support for a different database.
See detailed documentation here
Name | Description |
---|---|
New-MgMigration | Create a new rollout and rollback migration |
New-MgMigrationTable | Create a new migration table in the database |
New-MgSeeder | Create a new seeder migration |
Get-MgUsedVariables | Get a list over used variables for a migration file. See Variables for more info |
Get-MgLatestIteration | Get the latest iteration of migrations applied |
Get-MgProcessedMigrations | Get all the applied migrations |
Get-MgScriptsForLatestIteration | Get all the applied migrations for the latest iteration |
Get-MgProcessedSeeders | Get all the applied seeders |
Invoke-MgRollout | Run a rollout of migrations that is not applied yet |
Invoke-MgRollback | Run a rollback of the latest iteration of migrations |
Invoke-MgSeeding | Run all unapplied seeders |
Want to use environment variables in your migration scripts? Well, Migratio supports that. Simply insert ${{YOUR_VARIABLE}}
and Migratio will replace the value during migration, seeding or rollback when the ReplaceVariables
option is set.
CREATE USER applicationUser WITH ENCRYPTED PASSWORD '${{APP_USER_PASSWORD}}';
directories:
base: /dev/migrations # Path to base directory containing subfolders
rollout: /dev/migrations/rollout # Path to rollout scripts
rollback: /dev/migrations/rollback # Path to rollback scripts
seeders: /dev/migrations/seeders # Path to seeder scripts
envMapping: # Mapping/Translation of variables and env variables
MG_DB_PASSWORD: DB_USERNAME
envFile: "./backend.env" # Path to env file
auth: # DB auth options
postgres:
host: "localhost"
port: 1234
database: "TestDB"
username: "postgres"
password: "${{MG_DB_PASSWORD}}" # Will use DB_USERNAME under lookup (ref: envMapping)
replaceVariables: true # Replace variables in rollout scripts
Multiple environments are also supported
environments:
[envName]:
...config
environments:
development:
directories:
base: /dev/migrations
rollout: /dev/migrations/rollout
rollback: /dev/migrations/rollback
seeders: /dev/migrations/seeders
envMapping:
MG_DB_PASSWORD: DB_USERNAME
envFile: "./backend.env"
auth:
postgres:
host: "localhost"
port: 1234
database: "TestDB"
username: "postgres"
password: "${{MG_DB_PASSWORD}}"
replaceVariables: true
production:
directories:
base: /prod/migrations
rollout: /prod/migrations/rollout
rollback: /prod/migrations/rollback
seeders: /prod/migrations/seeders
envMapping:
MG_DB_PASSWORD: DB_PROD_USERNAME
envFile: "./backend.prod.env"
auth:
postgres:
host: "localhost"
port: 1234
database: "ProdDB"
username: "produser"
password: "${{MG_DB_PASSWORD}}"
replaceVariables: true