Skip to content

Commit

Permalink
feat: upgraded mongoose version to support new mongo connection types
Browse files Browse the repository at this point in the history
feat: .env support
  • Loading branch information
balmasi committed Jul 7, 2019
1 parent dcdc96d commit d84336d
Show file tree
Hide file tree
Showing 8 changed files with 2,981 additions and 231 deletions.
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# migrate-mongoose
A node based migration framework for mongoose
A node based migration framework for ES6+ for mongoose

#### Motivation
migrate-mongoose is a migration framework for projects which are already using mongoose.
Expand Down Expand Up @@ -89,6 +89,14 @@ If you want to not provide the options such as `--dbConnectionUri` to the progra
```
export MIGRATE_dbConnectionUri=localhost/migrations
```

`.env` files are also supported. All variables will be read from the `.env` file and set by migrate-mongoose.

```bash
#.env
MIGRATE_dbConnectionUri=mongodb://localhost:27017/mydb
```

**2. Provide a config file (defaults to *migrate.json* or *migrate.js*)**
```bash
# If you have migrate.json in the directory, you don't need to do anything
Expand All @@ -115,7 +123,7 @@ Here's how you can access your `mongoose` models and handle errors in your migra
* Easy flow control
*/
// Notice no need for callback
export async function up() {
async function up() {
// Error handling is as easy as throwing an error
if (condition) {
throw new Error('This is an error. Could not complete migration');
Expand Down Expand Up @@ -148,9 +156,9 @@ const UserSchema = new Schema({
module.exports = mongoose.model('user', UserSchema);

// 1459287720919-my-migration.js
export async function up() {
async function up() {
// Then you can access it in the migration like so
await this('user').update({}, {
await this('user').updateMany({}, {
$rename: { firstName: 'first' }
}, { multi: true });

Expand All @@ -172,4 +180,4 @@ example: `-d mongodb://localhost:27017/development` . If you don't want to pass
### How to contribute
1. Start an issue. We will discuss the best approach
2. Make a pull request. I'll review it and comment until we are both confident about it
3. Profit
3. I'll merge your PR and bump the version of the package
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export async function up () {
async function up () {
await this('users').updateMany({}, { $set: { state: 'California' } });
}

export async function down () {
async function down () {
await this('users').updateMany({}, { $unset: { state: 1 } });
}

module.exports = {
down,
up
}
Loading

0 comments on commit d84336d

Please sign in to comment.