Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example for multiple glob dirs #343

Merged
merged 4 commits into from
Oct 11, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,29 @@ const umzug = new Umzug({
});
```

The glob syntax allows loading migrations from multiple locations:

```js
const { Umzug } = require('umzug')
const { Sequelize } = require('sequelize')

const umzug = new Umzug({
migrations: {
glob: '{first-folder/*.js,second-folder-with-different-naming-convention/*.js}',
},
context: new Sequelize(...),
logger: console,
});
```

Note on migration file sorting:

- file matches, found using [glob](https://npmjs.com/package/glob), will be alphabetically sorted based on their paths
mmkal marked this conversation as resolved.
Show resolved Hide resolved
- so if your migrations are `one/m1.js`, `two/m2.js`, `three/m3.js`, the resultant order will be `one/m1.js`, `three/m3.js`, `two/m2.js`
- similarly, if your migrations are called `m1.js`, `m2.js`, ... `m10.js`, `m11.js`, the resultant ordering will be `m1.js`, `m10.js`, `m11.js`, ... `m2.js`
- The easiest way to deal with this is to ensure your migrations appear in a single folder, and their paths match alphabetically with the order they should run in
mmkal marked this conversation as resolved.
Show resolved Hide resolved
- If this isn't possible, the ordering can be customised using `.extend(...)` (see below)

### Upgrading from v2.x

The Umzug class should be imported as a named import, i.e. `import { Umzug } from 'umzug'`.
Expand Down