# runtime-migrate

> Makes mongo database migrations at runtime with versioning.

Latest version **0.0.0** (published 2017-03-21) · 0 weekly downloads

## Install

```sh
npm install runtime-migrate
pnpm add runtime-migrate
yarn add runtime-migrate
bun add runtime-migrate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2017-03-21 |
| First published | 2017-03-21 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | David Dyke |
| Maintainers | daviddykeuk |

## Links

- npm: https://www.npmjs.com/package/runtime-migrate
- Repository: https://github.com/daviddykeuk/runtime-migrate
- Homepage: https://github.com/daviddykeuk/runtime-migrate#readme
- Issues: https://github.com/daviddykeuk/runtime-migrate/issues
- npm.io page: https://npm.io/package/runtime-migrate

## Dependencies (1)

- [mongoose](https://npm.io/package/mongoose.md) ^4.9.1

## Recent versions

- 0.0.0 (latest) — 2017-03-21

## README

# runtime-migrate [![Build Status](https://secure.travis-ci.org/daviddykeuk/runtime-migrate.png?branch=master)](https://travis-ci.org/daviddykeuk/runtime-migrate)

Makes mongo database migrations at runtime with versioning.

## Install

```bash
npm install --save runtime-migrate
```

## Usage
runtime-migrate will run scripts on a mongo database if they have not been executed before when your app starts, to achieve this follow the steps below.

Create a schema
```javascript
var mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var exampleSchema = new Schema({
    name: String,
    description: String,
});
```

Create a migration script
```javascript
var migrations = [{
    version: "1.0.0",
    description: "Initial setup",
    script: function(done) {
        exampleSchema.insertMany([{
            "name": "Object one",
            "description": "Added on first version"
        }]).then(done);
    }
}];
```

Execute the migrations at runtime
```javascript
var migrator = require('runtime-migrate');

// connect to mongo
mongoose.connect("mongodb://localhost/exampleDB");

// execute the migrations
migrator.migrate(migrations, function(result) {
    console.log("Database migration result: %s", result)
});
```

## Examples

See `examples/` for different use cases.

## License

MIT

---
_Source: https://npm.io/package/runtime-migrate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
