Skip to content

vanslly/graphcms-migrate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npx graphcms-migrate

EXPERIMENTAL

Needs migrating to the newer meow/ora with esm support, typescript.

Usage

  1. Add your GRAPHCMS_ENDPOINT and GRAPHCMS_TOKEN to .env (or use flags --endpoint and --token)
  2. Add migrations to a directory called graphcms-migrations, or a name you prefer
  3. Run and pass the directory name npx graphcms-migrate <directory-of-migrations>

Migration template

You must create migration .js files inside your custom migrations directory formatted like this:

const { FieldType, newMigration } = require("@graphcms/management");

const migration = newMigration({
  endpoint: process.env.GRAPHCMS_ENDPOINT,
  authToken: process.env.GRAPHCMS_TOKEN,
});

const instructor = migration.createModel({
  apiId: "Instructor",
  apiIdPlural: "Instructors",
  displayName: "Instructor",
});

instructor.addSimpleField({
  apiId: "name",
  displayName: "Name",
  type: FieldType.String,
  isRequired: true,
  isTitle: true,
});

instructor.addRelationalField({
  apiId: "avatar",
  displayName: "Avatar",
  model: "Asset",
});

module.exports = migration;

In an upcoming version we will pass the endpoint/token to newMigration, so this would remove the need for:

const migration = newMigration({
  endpoint: process.env.GRAPHCMS_ENDPOINT,
  authToken: process.env.GRAPHCMS_TOKEN,
});

GitHub Workflow

name: GraphCMS Migrations
on:
  push:
    branches:
      - main
jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: "14"
          check-latest: true

      - name: Push schema
        run: npx graphcms-migrate graphcms-migrations
        env:
          GRAPHCMS_ENDPOINT: ${{ secrets.GRAPHCMS_ENDPOINT }}
          GRAPHCMS_TOKEN: ${{ secrets.GRAPHCMS_TOKEN }}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published