EXPERIMENTAL
Needs migrating to the newer meow/ora with esm support, typescript.
- Add your
GRAPHCMS_ENDPOINT
andGRAPHCMS_TOKEN
to.env
(or use flags--endpoint
and--token
) - Add migrations to a directory called
graphcms-migrations
, or a name you prefer - Run and pass the directory name
npx graphcms-migrate <directory-of-migrations>
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,
});
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 }}