From 6f0fc3209c83b35a596a007dd4e2727a28f6ec63 Mon Sep 17 00:00:00 2001 From: Kristiyan Tachev Date: Tue, 23 Apr 2024 11:31:45 +0300 Subject: [PATCH] feat(readme.md): modified documentation and added mongodb and mongoose as dev dependencies --- README.md | 50 ++++++++---- package-lock.json | 168 +++++++++++++++++++++++++++++++++++++++ package.json | 4 +- src/migrations.module.ts | 4 +- xmigrate.ts | 40 +++++----- 5 files changed, 226 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 282247b..3cee4f9 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ chmod +x xmigrate-linux ``` ```bash -./xmigrate up|down|create +./xmigrate up|down|create|status ``` Using `NodeJS` @@ -55,6 +55,9 @@ Manual configuration You can create a `xmigrate.js` file where you execute the `xmigrate` command: ```typescript +import { MongoClient } from 'mongodb'; +import { connect } from 'mongoose'; + export default async () => { return { changelogCollectionName: 'migrations', @@ -64,6 +67,9 @@ export default async () => { outDir: './.xmigrate', /* Custom datetime formatting can be applied like so */ // dateTimeFormat: () => new Date().toISOString(), + /* If you do need some better bundling of your migrations when there are tsconfig paths namespaces @shared/my-namespace + You should consider using `bundler.build()` configuration. + */ // bundler: { // build(entryPoints: string[], outdir: string) { // return esbuild.build({ @@ -90,11 +96,13 @@ export default async () => { error: 'down.error.log', }, }, - mongodb: { - url: `mongodb://localhost:27017`, - databaseName: 'test', - options: { - useNewUrlParser: true, + database: { + async connect() { + const url = 'mongodb://localhost:27017'; + + await connect(url); + const client = await MongoClient.connect(url); + return client; }, }, }; @@ -401,6 +409,8 @@ When you change your configuration file to `xmigrate.ts` it will automatically t ```typescript import { Config } from '@rxdi/xmigrate'; +import { MongoClient } from 'mongodb'; +import { connect } from 'mongoose'; export default async (): Promise => { return { @@ -435,11 +445,14 @@ export default async (): Promise => { error: 'down.error.log', }, }, - mongodb: { - url: `mongodb://localhost:27017`, - databaseName: 'test', - options: { - useNewUrlParser: true, + database: { + async connect() { + const url = + process.env.MONGODB_CONNECTION_STRING ?? 'mongodb://localhost:27017'; + + await connect(url); + const client = await MongoClient.connect(url); + return client; }, }, }; @@ -467,6 +480,8 @@ import { LoggerConfig, Config, } from '@rxdi/xmigrate'; +import { MongoClient } from 'mongodb'; +import { connect } from 'mongoose'; const config = { changelogCollectionName: 'migrations', @@ -485,11 +500,14 @@ const config = { error: 'down.error.log', }, }, - mongodb: { - url: 'mongodb://localhost:27017', - databaseName: 'test', - options: { - useNewUrlParser: true, + database: { + async connect() { + const url = + process.env.MONGODB_CONNECTION_STRING ?? 'mongodb://localhost:27017'; + + await connect(url); + const client = await MongoClient.connect(url); + return client; }, }, }; diff --git a/package-lock.json b/package-lock.json index 9305000..7eef242 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1760,6 +1760,12 @@ "file-uri-to-path": "1.0.0" } }, + "bluebird": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", + "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==", + "dev": true + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1840,6 +1846,12 @@ "node-int64": "^0.4.0" } }, + "bson": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", + "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==", + "dev": true + }, "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", @@ -2122,6 +2134,23 @@ } } }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "requires": { + "ms": "2.0.0" + }, + "dependencies": { + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "dev": true + } + } + }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", @@ -4753,6 +4782,12 @@ "verror": "1.10.0" } }, + "kareem": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.1.tgz", + "integrity": "sha512-l3hLhffs9zqoDe8zjmb/mAN4B8VT3L56EUvKNqLFVs9YlFA+zx7ke1DO8STAdDyYNkeSo1nKmjuvQeI12So8Xw==", + "dev": true + }, "kind-of": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", @@ -4890,6 +4925,13 @@ "object-visit": "^1.0.0" } }, + "memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "dev": true, + "optional": true + }, "merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -4991,6 +5033,78 @@ } } }, + "mongodb": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.3.3.tgz", + "integrity": "sha512-MdRnoOjstmnrKJsK8PY0PjP6fyF/SBS4R8coxmhsfEU7tQ46/J6j+aSHF2n4c2/H8B+Hc/Klbfp8vggZfI0mmA==", + "dev": true, + "requires": { + "bson": "^1.1.1", + "require_optional": "^1.0.1", + "safe-buffer": "^5.1.2", + "saslprep": "^1.0.0" + } + }, + "mongoose": { + "version": "5.7.6", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.7.6.tgz", + "integrity": "sha512-2r87HmQMDCeZocoFmYGnJSpCW9ut95iQyPUcseG2B6EiAJjJBmR3pA01QyDF2+zQWpA8Ui4wH7xOq05U1nF6wg==", + "dev": true, + "requires": { + "bson": "~1.1.1", + "kareem": "2.3.1", + "mongodb": "3.3.3", + "mongoose-legacy-pluralize": "1.0.2", + "mpath": "0.6.0", + "mquery": "3.2.2", + "ms": "2.1.2", + "regexp-clone": "1.0.0", + "safe-buffer": "5.1.2", + "sift": "7.0.1", + "sliced": "1.0.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + } + } + }, + "mongoose-legacy-pluralize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", + "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==", + "dev": true + }, + "mpath": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.6.0.tgz", + "integrity": "sha512-i75qh79MJ5Xo/sbhxrDrPSEG0H/mr1kcZXJ8dH6URU5jD/knFxCVqVC/gVSW7GIXL/9hHWlT9haLbCXWOll3qw==", + "dev": true + }, + "mquery": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.2.tgz", + "integrity": "sha512-XB52992COp0KP230I3qloVUbkLUxJIu328HBP2t2EsxSFtf4W1HPSOBWOXf1bqxK4Xbb66lfMJ+Bpfd9/yZE1Q==", + "dev": true, + "requires": { + "bluebird": "3.5.1", + "debug": "3.1.0", + "regexp-clone": "^1.0.0", + "safe-buffer": "5.1.2", + "sliced": "1.0.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + } + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -5536,6 +5650,12 @@ "safe-regex": "^1.1.0" } }, + "regexp-clone": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz", + "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw==", + "dev": true + }, "regexpp": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", @@ -5620,6 +5740,16 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, + "require_optional": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", + "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==", + "dev": true, + "requires": { + "resolve-from": "^2.0.0", + "semver": "^5.1.0" + } + }, "reselect": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/reselect/-/reselect-4.0.0.tgz", @@ -5652,6 +5782,12 @@ } } }, + "resolve-from": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", + "integrity": "sha512-qpFcKaXsq8+oRoLilkwyc7zHGF5i9Q2/25NIgLQQ/+VVv9rU4qvr6nXVAw1DsnXJyQkZsR4Ytfbtg5ehfcUssQ==", + "dev": true + }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -5748,6 +5884,16 @@ "walker": "~1.0.5" } }, + "saslprep": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", + "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", + "dev": true, + "optional": true, + "requires": { + "sparse-bitfield": "^3.0.3" + } + }, "sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", @@ -5810,6 +5956,12 @@ "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", "dev": true }, + "sift": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz", + "integrity": "sha512-oqD7PMJ+uO6jV9EQCl0LrRw1OwsiPsiFQR5AR30heR+4Dl7jBBbDLnNvWiak20tzZlSE1H7RB30SX/1j/YYT7g==", + "dev": true + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -5839,6 +5991,12 @@ "is-fullwidth-code-point": "^2.0.0" } }, + "sliced": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", + "integrity": "sha512-VZBmZP8WU3sMOZm1bdgTadsQbcscK0UM8oKxKVBs4XAhUo2Xxzm/OFMGBkPusxw9xL3Uy8LrzEqGqJhclsr0yA==", + "dev": true + }, "snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", @@ -6002,6 +6160,16 @@ "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=", "dev": true }, + "sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "dev": true, + "optional": true, + "requires": { + "memory-pager": "^1.0.2" + } + }, "spdx-correct": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", diff --git a/package.json b/package.json index 4b37000..ac9ecfb 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,9 @@ "jest": "^24.8.0", "prettier": "^2.0.4", "ts-jest": "^24.0.2", - "typescript": "^3.5.3" + "typescript": "^3.5.3", + "mongodb": "3.3.3", + "mongoose": "5.7.6" }, "peerDependencies": { "mongodb": "*", diff --git a/src/migrations.module.ts b/src/migrations.module.ts index 38df2f7..0006de2 100644 --- a/src/migrations.module.ts +++ b/src/migrations.module.ts @@ -135,7 +135,9 @@ export class MigrationsModule { settings = (await (settings as Function)()) as Config; } configService.set(settings as Config); - } catch (e) {} + } catch (e) { + console.error('Cannot load xmigrate configuration file', e); + } await ensureDir(configService.config.logger.folder); await ensureDir(configService.config.migrationsDir); let hasCrashed: boolean; diff --git a/xmigrate.ts b/xmigrate.ts index c64970c..a0bb116 100644 --- a/xmigrate.ts +++ b/xmigrate.ts @@ -1,4 +1,4 @@ -import esbuild from 'esbuild'; +// import esbuild from 'esbuild'; import { MongoClient } from 'mongodb'; import { connect } from 'mongoose'; @@ -8,31 +8,27 @@ export default async () => { outDir: './.xmigrate', typescript: true, builder: 'custom', - bundler: { - build(entryPoints: string[], outdir: string) { - return esbuild.build({ - entryPoints, - bundle: true, - sourcemap: true, - minify: false, - platform: 'node', - format: 'cjs', - outdir, - logLevel: 'info', - }); - }, - }, + /* If bundler is not set default esbuild configuration will be added */ + // bundler: { + // build(entryPoints: string[], outdir: string) { + // return esbuild.build({ + // entryPoints, + // bundle: true, + // sourcemap: true, + // minify: false, + // platform: 'node', + // format: 'cjs', + // outdir, + // logLevel: 'info', + // }); + // }, + // }, // dateTimeFormat: () => new Date().toISOString(), database: { async connect() { const url = 'mongodb://localhost:27017'; - - await connect(url, { - useNewUrlParser: true, - }); - const client = await MongoClient.connect(url, { - useNewUrlParser: true, - }); + await connect(url); + const client = await MongoClient.connect(url); return client; }, },