Skip to content

Migration

Rocky edited this page Jan 5, 2023 · 9 revisions

What is migration?

Migration is a process in which we can add some data to the Database, design schema of DB, indexes etc. Migration scripts are run before starting the application. You can also use these scripts to migrate data from one database to another one.

When do I need to Create Migrations?

Migrations are needed when an application needs some pre-loaded data to get started. Elevate services need email templates, forms, and entities. This data is added to DB through migration which the frontend app can utilize.

You can create Migrations inside the migration folder.

Files for migration:

Each service has a modules folder within which you can find a migration folder for creating a migration. If this migration folder is present in modules, add the following line in the package.json file:

levate-migrations": "module/migrations/bin/migrations.js

How to create a migration file:

To create a migration, run the following command:

npm run elevate-migrations create <migration-file-name>

The migration-file-name should change to the filename after the above command is successfully executed. A command file will be created in src/migrations named -migration-file-name For example, 20220726145008-categoryEntity

Migration for specific operations can be written in -migration-file-name. For example, you can create a migration to create an index on a collection, or to update existing data.

Commands for Migration in Elevate.

To create a migration file.

npm run elevate-migrations create migration-file-name

To check the migration status

npm run elevate-migrations status

To run migration

npm run elevate-migrations up

To revert migration

npm run elevate-migrations down