https://github.com/sleavely/exodus-migrations
🧘 Framework-agnostic 🛬 migrations 🛫 for NodeJS
https://github.com/sleavely/exodus-migrations
cli migrations nodejs
Last synced: 5 months ago
JSON representation
🧘 Framework-agnostic 🛬 migrations 🛫 for NodeJS
- Host: GitHub
- URL: https://github.com/sleavely/exodus-migrations
- Owner: Sleavely
- License: mit
- Created: 2020-04-24T14:12:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T14:13:57.000Z (about 2 years ago)
- Last Synced: 2024-11-13T07:12:18.346Z (5 months ago)
- Topics: cli, migrations, nodejs
- Language: JavaScript
- Homepage:
- Size: 1.17 MB
- Stars: 4
- Watchers: 4
- Forks: 2
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# exodus
> Framework-agnostic migrations
[  ](https://npmjs.org/package/exodus "View this project on npm") [  ](https://circleci.com/gh/Sleavely/exodus-migrations)
[Github](https://github.com/Sleavely/exodus-migrations) | [NPM](https://www.npmjs.com/package/exodus) | [Changelog](https://github.com/Sleavely/exodus-migrations/releases)
## Install
```
$ npm i -g exodus
```Node 10+ is recommended.
## Usage
Exodus allows you to create migration definitions, modules that allow you to introduce version-controlled changes in your application, such as adding a field to a database or changing a configuration for your e-commerce.
Exodus was largely inspired by the flexibility and user experience of [`migrat`](https://github.com/naturalatlas/migrat), and much of the configurable behavior and templates have been forked from there.
### CLI
```
$ exodus --helpUsage
$ exodusPossible actions
init Adds a config file in your project directory
create Creates a new file in your migrations dir
migrate Runs all remaining migrationsOptions
--helpFor more information, see:
https://github.com/Sleavely/exodus-migrations
```### Migrations
A migration definition is a regular Node module that exposes an `up()` method that introduces a change, and a `down()` method that allows the user (that's you!) to reverse the change later.
An example migration might look like:
```js
const { load, save } = require('../utils/db-methods')
//Apply the change
exports.up = async () => {
const users = await load('users')
for (let user of users) {
user.age = user.age + 1
}
await save('users', users)
}// Revert the change
exports.down = async () => {
const users = await load('users')
for (let user of users) {
user.age = user.age - 1
}
await save('users', users)
}
```### Configuration
The `init` command will create a configuration file in your current directory.
All properties are optional.
```js
module.exports = exports = {
/**
* @name migrationsDirectory
*
* The folder to store migration scripts in,
* relative to your configuration file.
*/
// migrationsDirectory: './migrations',/**
* @name context
*
* Invoked at the beginning of a run, this method can return
* an object with any details you want passed through to all
* migrations, such as database connections, loggers, etc.
*
* @return {object}
*/
// context: async () => { return {} },/**
* @name storeState
*
* Called to persist current migration state. Use this to store
* the `state` argument in Redis, to disk, your database etc.
* If undefined, Exodus falls back to exodus.state.json
*
* @param state The state object to be stored.
* @param context The object you returned in `context`
*/
// storeState: async (state, context) => {},/**
* @name fetchState
*
* This method is responsible for fetching the current
* migration state, persisted by `storeState`.
* If undefined, Exodus falls back to exodus.state.json
*
* @param context The object you returned in `context`
* @return {object}
*/
// fetchState: async (context) => {},/**
* @name beforeAll
*
* Executed right before any of the queued migrations are run.
*
* @param {migrationJob[]}
*/
// beforeAll: async (pendingMigrations) => {},/**
* @name beforeEach
*
* Executed before each migration.
*
* @param {migrationJob}
*/
// beforeEach: async (migrationJob) => {},/**
* @name afterEach
*
* Executed after each migration.
*
* @param {migrationJob}
*/
// afterEach: async (migrationJob) => {},/**
* @name afterAll
*
* Executed after the final pending migration was run.
*
* @param {migrationJob[]}
*/
// afterAll: async (pendingMigrations) => {},}
```### Examples
See the [examples directory](./examples) for guides on use-cases the community has found helpful.
## Contributing
Open source software is awesome, and so are you!