From 5728dedd187a9f92949135da9454bf74dd476acd Mon Sep 17 00:00:00 2001 From: Juji Date: Mon, 24 Feb 2020 13:50:09 +0700 Subject: [PATCH 1/6] show error line and file --- src/cli.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli.js b/src/cli.js index 86cdd91..fec1a25 100755 --- a/src/cli.js +++ b/src/cli.js @@ -165,6 +165,7 @@ switch (command) { promise .then(() => { process.exit(0); }) .catch((err) => { + console.error(err) console.warn(err.message.yellow); process.exit(1); }); From 352746e54e36d81b704cce5ac345e847311479f1 Mon Sep 17 00:00:00 2001 From: juji Date: Wed, 10 Nov 2021 00:18:44 +0700 Subject: [PATCH 2/6] print complete error --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8f98f7d..0e329b3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "migrate-mongoose", + "name": "@juji/migrate-mongoose", "version": "4.0.0", "description": "A mongoose based migration framework for node", "main": "./src/lib.js", @@ -24,7 +24,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/balmasi/migrate-mongoose.git" + "url": "https://github.com/juji/migrate-mongoose" }, "dependencies": { "bluebird": "^3.3.3", From 506dc724d46aed9ef6ce14dcad7cde6577db4cb5 Mon Sep 17 00:00:00 2001 From: juji Date: Wed, 10 Nov 2021 00:22:01 +0700 Subject: [PATCH 3/6] print complete error --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0e329b3..f17a151 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@juji/migrate-mongoose", - "version": "4.0.0", + "name": "@juji-migrate-mongoose", + "version": "4.0.1", "description": "A mongoose based migration framework for node", "main": "./src/lib.js", "scripts": { From 32ced1096c919c24968412888ae5d697f6f32b5a Mon Sep 17 00:00:00 2001 From: juji Date: Wed, 10 Nov 2021 00:22:19 +0700 Subject: [PATCH 4/6] print complete error --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f17a151..41ffac6 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@juji-migrate-mongoose", + "name": "juji-migrate-mongoose", "version": "4.0.1", "description": "A mongoose based migration framework for node", "main": "./src/lib.js", From d671b99f266365bcf210a4462127f0895bfc3ea6 Mon Sep 17 00:00:00 2001 From: juji Date: Thu, 12 May 2022 23:46:02 +0700 Subject: [PATCH 5/6] connectionOptions in config --- README.md | 39 +++++++++++++++----------- package.json | 2 +- src/cli.js | 3 +- src/lib.js | 13 +++++---- yarn-error.log | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 yarn-error.log diff --git a/README.md b/README.md index 769cac5..74ad4f7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,12 @@ A node based migration framework for ES6+ for mongoose #### Motivation migrate-mongoose is a migration framework for projects which are already using mongoose. - + +#### Update by juji + +- add `connectionOptions` in config +- log full error + **Most other migration frameworks:** - Use a local state file to keep track of which migrations have been run: This is a problem for PaS providers like heroku where the file system is wiped each time you deploy @@ -12,13 +17,13 @@ migrate-mongoose is a migration framework for projects which are already using m **migrate-mongoose:** - Stores migration state in MongoDB -- Provides plenty of features such as +- Provides plenty of features such as - Access to mongoose models in migrations - Use of promises or standard callbacks - custom config files or env variables for migration options - ability to delete unused migrations -- Relies on a simple *GLOBAL* state of whether or not each migration has been called - +- Relies on a simple *GLOBAL* state of whether or not each migration has been called + ### Getting Started with the CLI @@ -58,8 +63,8 @@ Commands: prune Allows you to delete extraneous migrations by removing extraneous local migration files/database migrations. - - + + Options: -d, --dbConnectionUri The URI of the database connection [string] [required] --collection The mongo collection name to use for migrations [string] [default: "migrations"] @@ -70,8 +75,8 @@ Options: rather than asking interactively (use in scripts) -h, --help Show help [boolean] - - + + Examples: node_modules/.bin/migrate list -d mongodb://localhost/migrations node_modules/.bin/migrate create add_users -d mongodb://localhost/migrations @@ -101,7 +106,7 @@ MIGRATE_dbConnectionUri=mongodb://localhost:27017/mydb ```bash # If you have migrate.json in the directory, you don't need to do anything migrate list - + # Otherwise you can provide a config file migrate list --config somePath/myCustomConfigFile[.json] ``` @@ -124,22 +129,22 @@ Here's an example of a migration created using `migrate create some-migration-na /** * Easy flow control */ -// Notice no need for callback +// Notice no need for callback 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'); } - + // You can just run your updates and when function finishes the migration is assumed to be done! await new Promise((resolve, reject) => { setTimeout(()=> { resolve('ok'); }, 3000); }); - + // ======== OR =========== - // just return the promise! It will succeed when it resolves or fail when rejected + // just return the promise! It will succeed when it resolves or fail when rejected return lib.getPromise(); - + } module.exports = { up, down }; @@ -185,7 +190,7 @@ import { User } from '../models' async function up() { // Then you can use it in the migration like so await User.create({ firstName: 'Ada', lastName: 'Lovelace' }); - + // OR do something such as const users = await User.find(); /* Do something with users */ @@ -197,7 +202,7 @@ If you're using the package programmatically. You can access your models using t ```javascript async function up() { // "this('user')" is the same as calling "connection.model('user')" using the connection you passed to the Migrator constructor. - // + // await this('user').create({ firstName: 'Ada', lastName: 'Lovelace' }); } ``` @@ -206,7 +211,7 @@ async function up() { Currently, the **-d**/**dbConnectionUri** must include the database to use for migrations in the uri. -example: `-d mongodb://localhost:27017/development` . +example: `-d mongodb://localhost:27017/development` . If you don't want to pass it in every time feel free to use the `migrate.json` config file or an environment variable diff --git a/package.json b/package.json index 41ffac6..69a5cd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "juji-migrate-mongoose", - "version": "4.0.1", + "version": "4.0.2", "description": "A mongoose based migration framework for node", "main": "./src/lib.js", "scripts": { diff --git a/src/cli.js b/src/cli.js index fec1a25..4363db4 100755 --- a/src/cli.js +++ b/src/cli.js @@ -114,6 +114,7 @@ let migrator = new Migrator({ migrationsPath: path.resolve(args['migrations-dir']), templatePath: args['template-file'], dbConnectionUri: args.dbConnectionUri, + connectionOptions: args.connectionOptions, // juji's addition collectionName: args.collection, autosync: args.autosync, cli: true @@ -165,7 +166,7 @@ switch (command) { promise .then(() => { process.exit(0); }) .catch((err) => { - console.error(err) + console.error(err) // juji's addition console.warn(err.message.yellow); process.exit(1); }); diff --git a/src/lib.js b/src/lib.js index 85d68a0..711f407 100644 --- a/src/lib.js +++ b/src/lib.js @@ -37,6 +37,7 @@ class Migrator { templatePath, migrationsPath = './migrations', dbConnectionUri, + connectionOptions, collectionName = 'migrations', autosync = false, cli = false, @@ -45,7 +46,10 @@ class Migrator { const defaultTemplate = migrationTemplate; this.template = templatePath ? fs.readFileSync(templatePath, 'utf-8') : defaultTemplate; this.migrationPath = path.resolve(migrationsPath); - this.connection = connection || mongoose.createConnection(dbConnectionUri, { useNewUrlParser: true }); + this.connection = connection || mongoose.createConnection( + dbConnectionUri, + connectionOptions || { useNewUrlParser: true } // juji's addition + ); this.collection = collectionName; this.autosync = autosync; this.cli = cli; @@ -199,10 +203,10 @@ class Migrator { /** * sync file system -> database - * + * * Imports any migrations that are on the file system but * missing in the database into the database - * + * * This functionality is opposite of prune() */ async sync() { @@ -256,7 +260,7 @@ class Migrator { /** * sync migration database -> file system - * + * * Opposite of sync(). * Removes files in migration directory which don't exist in database. */ @@ -346,4 +350,3 @@ function fileRequired(error) { module.exports = Migrator; - diff --git a/yarn-error.log b/yarn-error.log new file mode 100644 index 0000000..a99e7b4 --- /dev/null +++ b/yarn-error.log @@ -0,0 +1,76 @@ +Arguments: + /usr/local/Cellar/node@14/14.19.1/bin/node /usr/local/Cellar/yarn/1.22.18/libexec/bin/yarn.js publish + +PATH: + /Users/juji/.platformsh/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin + +Yarn version: + 1.22.18 + +Node version: + 14.19.1 + +Platform: + darwin x64 + +Trace: + Error: canceled + at Interface. (/usr/local/Cellar/yarn/1.22.18/libexec/lib/cli.js:137143:13) + at Interface.emit (events.js:400:28) + at Interface._ttyWrite (readline.js:1001:16) + at ReadStream.onkeypress (readline.js:265:10) + at ReadStream.emit (events.js:400:28) + at emitKeys (internal/readline/utils.js:358:14) + at emitKeys.next () + at ReadStream.onData (readline.js:1270:36) + at ReadStream.emit (events.js:400:28) + at addChunk (internal/streams/readable.js:293:12) + +npm manifest: + { + "name": "juji-migrate-mongoose", + "version": "4.0.2", + "description": "A mongoose based migration framework for node", + "main": "./src/lib.js", + "scripts": { + "prepublish": "scripts/prepublish.sh", + "release": "np --no-tests", + "test": "echo 'Error: no test specified'" + }, + "bin": { + "migrate": "./src/cli.js" + }, + "keywords": [ + "migrate", + "migration", + "mongoose", + "schema", + "mongodb", + "db", + "nosql" + ], + "author": "Borna Almasi ", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/juji/migrate-mongoose" + }, + "dependencies": { + "bluebird": "^3.3.3", + "colors": "^1.1.2", + "dotenv": "^8.0.0", + "inquirer": "^0.12.0", + "mkdirp": "^0.5.1", + "mongoose": "^5.6.3", + "yargs": "^4.8.1" + }, + "devDependencies": { + "np": "^5.0.3" + } + } + +yarn manifest: + No manifest + +Lockfile: + No lockfile From c3fc7c579ac226b5b956abdad71367af99373c56 Mon Sep 17 00:00:00 2001 From: juji Date: Thu, 12 May 2022 23:57:45 +0700 Subject: [PATCH 6/6] remove error log --- yarn-error.log | 76 -------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 yarn-error.log diff --git a/yarn-error.log b/yarn-error.log deleted file mode 100644 index a99e7b4..0000000 --- a/yarn-error.log +++ /dev/null @@ -1,76 +0,0 @@ -Arguments: - /usr/local/Cellar/node@14/14.19.1/bin/node /usr/local/Cellar/yarn/1.22.18/libexec/bin/yarn.js publish - -PATH: - /Users/juji/.platformsh/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin - -Yarn version: - 1.22.18 - -Node version: - 14.19.1 - -Platform: - darwin x64 - -Trace: - Error: canceled - at Interface. (/usr/local/Cellar/yarn/1.22.18/libexec/lib/cli.js:137143:13) - at Interface.emit (events.js:400:28) - at Interface._ttyWrite (readline.js:1001:16) - at ReadStream.onkeypress (readline.js:265:10) - at ReadStream.emit (events.js:400:28) - at emitKeys (internal/readline/utils.js:358:14) - at emitKeys.next () - at ReadStream.onData (readline.js:1270:36) - at ReadStream.emit (events.js:400:28) - at addChunk (internal/streams/readable.js:293:12) - -npm manifest: - { - "name": "juji-migrate-mongoose", - "version": "4.0.2", - "description": "A mongoose based migration framework for node", - "main": "./src/lib.js", - "scripts": { - "prepublish": "scripts/prepublish.sh", - "release": "np --no-tests", - "test": "echo 'Error: no test specified'" - }, - "bin": { - "migrate": "./src/cli.js" - }, - "keywords": [ - "migrate", - "migration", - "mongoose", - "schema", - "mongodb", - "db", - "nosql" - ], - "author": "Borna Almasi ", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/juji/migrate-mongoose" - }, - "dependencies": { - "bluebird": "^3.3.3", - "colors": "^1.1.2", - "dotenv": "^8.0.0", - "inquirer": "^0.12.0", - "mkdirp": "^0.5.1", - "mongoose": "^5.6.3", - "yargs": "^4.8.1" - }, - "devDependencies": { - "np": "^5.0.3" - } - } - -yarn manifest: - No manifest - -Lockfile: - No lockfile