Skip to content

Migratio is a PowerShell module to handle PostgreSQL database migrations

License

Notifications You must be signed in to change notification settings

joachimdalen/Migratio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

header-image

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.
⚠️ Migratio is far from complete and tested, so some things might not work as expected. Please take care if you decide to use this before a release.

🗄️ Supported databases

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.



🖥️ Cmdlets

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

💲 Variables

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}}';

⚙️ Configuration File

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

About

Migratio is a PowerShell module to handle PostgreSQL database migrations

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published