migraphile

1.1.0-beta.7 • Public • Published

migraphile

A migration tool that combines Migra and Graphile Migrate

Installation

yarn add migraphile

How It Works

Migraphile is a wrapper around Migra and allows users to enable drift detection with Graphile Migrate. With both of the features below, a developer can enable a smooth experience in generating and applying migrations to their database based on changes to a schema (orm) database.

Drift Detection

To do this, you will need to add the following to your .gmrc file that graphile-migrate produces.

{
  // Previously managed via BASELINE_FILE
  "afterReset": "schema/supabase.sql",
  
  // Simulate what v1.0.* would have done
  "beforeCurrent": [
    {
      "_": "command",
      "command": "yarn migraphile fix_drift"
    }
  ],
  "afterAllMigrations": [
    {
      "_": "command",
      "command": "yarn migraphile fix_drift"
    }
  ]
}

The fix_drift command is smart enough to run the necessary migrations to fix the drift. This is done by comparing the shadow database to the local database. The fixes are then applied to the local database. This command is intended to be called within the graphile-migrate process.

Migraphile will also pull some additional parameters from your environment. Create an .env file with the following parameters:

# graphile migrate
DATABASE_URL=postgres://user:pass@localhost:54322/postgres
ROOT_DATABASE_URL=postgres://user:pass@localhost:54322/template1
SHADOW_DATABASE_URL=postgres://user:pass@localhost:54322/shadow

# migraphile
APP_DATABASE_URL=postgres://user:pass@localhost:54322/postgres
ORM_DATABASE_URL=postgres://user:pass@localhost:54322/knex
ORM_NAME=Knex
OUTPUT_FILE_PATH=current/1-current.sql
SCHEMAS=public

One note is that the DATABASE_URL is the same as the APP_DATABASE_URL because graphile-migrate likes to override the variable Migraphile needs to be able to grab the original value.

Generate Migrations

You will need to run yarn migraphile to enable migration generation. This will listen for commands and generate a migration file to the given OUTPUT_FILE_PATH. For graphile-migrate this is usually migrations/current/1-current.sql.

Requirements

  • Docker: Migraphile uses Docker to run Migra in a container as it is a python application.

Readme

Keywords

none

Package Sidebar

Install

npm i migraphile

Weekly Downloads

188

Version

1.1.0-beta.7

License

MIT

Unpacked Size

53.5 kB

Total Files

13

Last publish

Collaborators

  • fireline-science-dev