@underbase/babel-register-ts v2.2.0
What's this ?
Underbase is a MongoDB schema and data migration library that provides an easy-to-use abstract interface for writting, organizing and executing your database migrations. Usable both in the CLI and as a module, you can easily implement it in your framework's code base.
- Promised: uses promises and async/await. No callback hell.
- Flexible: Multiple databases support. Migrations can be grouped, organized. Migrator can have event listeners.
- Scalable: uses MongoDB cursor and aggregator.
- Testable: can be used with assertions.
Quick start
Install
npm install -g @underbase/cliUnderbase is compatible with any Node.js version above v7.x.
Configuration
// underbase.config.js
const path = require('path');
module.exports = {
db: 'mongodb://localhost:27017/example_db',
migrationsDir: __dirname,
collectionName: '_migrations',
};Usage
// migrations/1.0/index.js
module.exports = {
version: 1.0,
describe: 'Update users collection',
async up({ Query }) {
const Users = Query.collection('Users');
await Users.rename('datecreated', 'dateCreated').where({
datecreated: {
$exists: true,
},
});
},
async down({ Query }) {
const Users = Query.collection('Users');
await Users.rename('dateCreated', 'datecreated').where({
dateCreated: {
$exists: true,
},
});
},
};Then, you can migrate :
# From 0 to 1.0
underbase migrate 1.0 --config underbase.config.jsWant to rerun current migration version ?
underbase rerun --config underbase.config.jsWant to rollback a migration ?
# From 1.0 to 0
underbase migrate 0 --config underbase.config.jsDocumentation
Learn more about using Underbase on the official site!
Examples
Want to see real-world usage of Underbase ? We've created some examples for you.
Support
Underbase is continuously being tested with node 8 & 11, the latest version of the mongodb nodejs driver (3.x) and the latest version of the MongoDB docker image. Dependencies are frequently updated. It's compatible with any Node.js version above v7.x.
Contributing
- Fork it!
- Create your feature branch: git checkout -b feature/my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin feature/my-new-feature
- Submit a pull request
README Badge
Using Underbase in an open-source project? Add a README badge to show it off:
[](https://sundowndev.github.io/underbase/)Credits
This repository is a fork of emmanuelbuah/mgdb-migrator, which is a generic mongodb migration library based on percolatestudio/meteor-migrations. This fork was created in order to provide a CLI application to interact with the API and several new features.
Icon was made by Fabiana Antonioli and published on thenounproject.
License
© 2019-present Raphaël Cerveaux
6 years ago