Skip to content

Commit

Permalink
feat(readme.md): modified documentation and added mongodb and mongoos…
Browse files Browse the repository at this point in the history
…e as dev dependencies
  • Loading branch information
Stradivario committed Apr 23, 2024
1 parent de27408 commit 6f0fc32
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 40 deletions.
50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ chmod +x xmigrate-linux
```

```bash
./xmigrate up|down|create
./xmigrate up|down|create|status
```

Using `NodeJS`
Expand All @@ -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',
Expand All @@ -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({
Expand All @@ -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;
},
},
};
Expand Down Expand Up @@ -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<Config> => {
return {
Expand Down Expand Up @@ -435,11 +445,14 @@ export default async (): Promise<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;
},
},
};
Expand Down Expand Up @@ -467,6 +480,8 @@ import {
LoggerConfig,
Config,
} from '@rxdi/xmigrate';
import { MongoClient } from 'mongodb';
import { connect } from 'mongoose';

const config = {
changelogCollectionName: 'migrations',
Expand All @@ -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;
},
},
};
Expand Down
168 changes: 168 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
4 changes: 3 additions & 1 deletion src/migrations.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 6f0fc32

Please sign in to comment.