GraphQL Migrations
Graphback uses graphql-migrations to automatically create and update tables from a GraphQL schema. The library compares your database schema to your GraphQL schema and executes the required changes to keep the database structure synchronised with the GraphQL schema. The package is built on top of Knex.js, a flexible SQL query builder.
#
Compatibility- PostgreSQL (create and update database)
- SQLite (create database only)
#
InstallationYou can install graphql-migrations
on your existing project using the following commmands:
With npm:
or with yarn:
#
UsageGraphQL Migrations operates on business models defined in your schema: These are GraphQL types decorated with a @model
annotation.
The package expose an API which you can programmatically set up in your source code and have it perform the migrations.
The package exposes a migrateDB
method which creates and updates your tables and columns to match your GraphQL schema.
All the database operations are wrapped in a single transaction, so your database will be fully rolled back to its initial state if an error occurs.
The method takes three arguments as described in migrations options section.
Assuming the above code is ran against a PostgreSQL database, the following relations will be created:
And the note
table:
#
Advanced usageFor more advanced usage, visit the below pages: