Skip to content

Commit

Permalink
chore(api): Add generic migration helper script (#4780)
Browse files Browse the repository at this point in the history
* chore(api): Add generic migration helper script
* docs(api): Add documentation for migrations
  • Loading branch information
rifont authored Nov 7, 2023
1 parent f7c7b98 commit 4219509
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 26 additions & 0 deletions apps/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,29 @@ $ npm run test

### E2E tests
See the docs for [Running on Local Machine - API Tests](https://docs.novu.co/community/run-in-local-machine#api).

## Migrations
Database migrations are included for features that have a hard dependency on specific data being available on database entities. These migrations are run by both Novu Cloud and Novu Self-Hosted users to support new feature releases.

### How to Run

The `npm run migration` script is available in the `package.json` to ensure script changes are DRY and consistent. This script is included in user-facing communications such as our documentation and release notes, and the script naming therefore MUST remain stable.

The path to the migration to run is passed as a positional argument to the script. For example, to run the Add Integration Identifier script, we would enter the following:

```bash
npm run migration -- ./migrations/integration-scheme-update/add-integration-identifier-migration.ts
```

### Conventions

These migrations live in the `./migrations` directory, and follow the naming convention of:
`./migrations/<CHANGE_DESCRIPTION>/<CHANGE_ACTION>.ts`. Each `<CHANGE_DESCRIPTION>` may have 1 or more `<CHANGE_ACTION>.ts` scripts. For example:

```
.
└── migrations/
└── integration-scheme-update/
├── add-integration-identifier-migration.ts
└── add-primary-priority-migration.ts
```
4 changes: 1 addition & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"test": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts src/**/**/*.spec.ts",
"test:e2e": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts src/**/*.e2e.ts",
"test:e2e:ee": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts src/**/*.e2e-ee.ts",
"migration": "cross-env NODE_ENV=local MIGRATION=true ts-node --transpileOnly ./migrations/expire-at/expire-at.migration.ts",
"migration:in-app": "cross-env NODE_ENV=local MIGRATION=true ts-node --transpileOnly ./migrations/integration-scheme-update/add-primary-priority-migration.ts",
"migration:primary-provider": "cross-env NODE_ENV=local MIGRATION=true ts-node --transpileOnly ./migrations/integration-scheme-update/add-primary-priority-migration.ts",
"migration": "cross-env NODE_ENV=local MIGRATION=true ts-node --transpileOnly",
"link:submodules": "pnpm link ../../enterprise/packages/auth"
},
"dependencies": {
Expand Down

0 comments on commit 4219509

Please sign in to comment.