Skip to content

Commit

Permalink
fix: status command table output and other minor improvements deps (#96)
Browse files Browse the repository at this point in the history
* fix status command table output format

* upgrade mongodb to version ^5.8.1 and remove deprecated types

* add missing await in down cmd

* add missing async in some functions

* add test for isTsNode func

* replace any from MigrationInterface by void
  • Loading branch information
mycodeself authored Sep 15, 2023
1 parent c813985 commit ba6684b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 38 deletions.
14 changes: 14 additions & 0 deletions __tests__/isTsNode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { isTsNode } from '../lib/utils/isTsNode';

describe('isTsNode', () => {
beforeEach(() => {
delete process.env.TS_NODE_DEV;
});
it('should return true when process.env.TS_NODE_DEV is true', () => {
process.env.TS_NODE_DEV = 'true';
expect(isTsNode()).toBeTruthy();
});
it('should return false when process.env.TS_NODE_DEV is false', () => {
expect(isTsNode()).toBeFalsy();
});
});
4 changes: 2 additions & 2 deletions examples/migrations/1585933701415_Migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Db } from 'mongodb';
import { MigrationInterface } from '../../lib';

export class Migration1585933701415 implements MigrationInterface {
public async up(db: Db): Promise<any> {
public async up(db: Db): Promise<void> {
db.createCollection('mycol');
}

public async down(db: Db): Promise<any> {
public async down(db: Db): Promise<void> {
db.dropCollection('mycol');
}
}
4 changes: 2 additions & 2 deletions examples/migrations/1691171075957_Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Db, MongoClient } from 'mongodb';
import { MigrationInterface } from '../../lib';

export class Transaction1691171075957 implements MigrationInterface {
public async up(db: Db, client: MongoClient): Promise<any> {
public async up(db: Db, client: MongoClient): Promise<void> {
const session = client.startSession();
try {
await session.withTransaction(async () => {
Expand All @@ -15,7 +15,7 @@ export class Transaction1691171075957 implements MigrationInterface {
}
}

public async down(db: Db, client: MongoClient): Promise<any> {
public async down(db: Db, client: MongoClient): Promise<void> {
const session = client.startSession();
try {
await session.withTransaction(async () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/MigrationInterface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Db, MongoClient } from 'mongodb';

export interface MigrationInterface {
up(db: Db, client: MongoClient): Promise<any>;
down(db: Db, client: MongoClient): Promise<any>;
up(db: Db, client: MongoClient): Promise<void>;
down(db: Db, client: MongoClient): Promise<void>;
}
8 changes: 4 additions & 4 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ export const cli = (config?: Config): void => {
.description('Undo migrations')
.option('-l, --last', 'Undo the last applied migration')
.option('-a, --all', 'Undo all applied migrations')
.action((opts) => {
.action(async (opts) => {
if (!opts.last && !opts.all) {
program.outputHelp();
process.exit(-1);
}

down({
await down({
config,
mode: opts.last ? 'last' : 'all',
});
Expand All @@ -81,8 +81,8 @@ export const cli = (config?: Config): void => {
program
.command('status')
.description('Show the status of the migrations')
.action(() => {
status({ config });
.action(async () => {
await status({ config });
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ export const down = async ({
break;
}
} finally {
connection.client.close();
await connection.client.close();
}
};
2 changes: 1 addition & 1 deletion lib/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const status = async (opts: CommandStatusOptions): Promise<void> => {

const table = new CliTable({
head: ['Migration', 'Status', 'Timestamp'],
colWidths: [100, 200],
colWidths: [48, 14, 18],
});

appliedMigrations.map((migration: MigrationModel) => {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@types/cli-table": "^0.3.1",
"@types/commander": "^2.12.2",
"@types/jest": "^27.4.0",
"@types/mongodb": "^4.0.7",
"@types/node": "^17.0.13",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
Expand All @@ -40,7 +39,7 @@
"husky": "^8.0.3",
"jest": "^29.5.0",
"lint-staged": "^12.3.2",
"mongodb": "^5.7.0",
"mongodb": "^5.8.1",
"prettier": "^2.5.1",
"rimraf": "^4.4.0",
"rollup": "^2.66.1",
Expand Down
41 changes: 17 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,13 @@
"@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14"

"@mongodb-js/saslprep@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@mongodb-js/saslprep/-/saslprep-1.1.0.tgz#022fa36620a7287d17acd05c4aae1e5f390d250d"
integrity sha512-Xfijy7HvfzzqiOAhAepF4SGN5e9leLkMvg/OPOF97XemjfVCYN/oWa75wnkc6mltMSTwY+XlbhWgUOJmkFspSw==
dependencies:
sparse-bitfield "^3.0.3"

"@nodelib/[email protected]":
version "2.1.5"
resolved "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz"
Expand Down Expand Up @@ -1355,13 +1362,6 @@
resolved "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz"
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==

"@types/mongodb@^4.0.7":
version "4.0.7"
resolved "https://registry.npmjs.org/@types/mongodb/-/mongodb-4.0.7.tgz"
integrity sha512-lPUYPpzA43baXqnd36cZ9xxorprybxXDzteVKCPAdp14ppHtFJHnXYvNpmBvtMUTb5fKXVv6sVbzo1LHkWhJlw==
dependencies:
mongodb "*"

"@types/node@*", "@types/node@^17.0.13":
version "17.0.45"
resolved "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz"
Expand Down Expand Up @@ -1900,10 +1900,10 @@ [email protected]:
dependencies:
node-int64 "^0.4.0"

bson@^5.4.0:
version "5.4.0"
resolved "https://registry.npmjs.org/bson/-/bson-5.4.0.tgz"
integrity sha512-WRZ5SQI5GfUuKnPTNmAYPiKIof3ORXAF4IRU5UcgmivNIon01rWQlw5RUH954dpu8yGL8T59YShVddIPaU/gFA==
bson@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/bson/-/bson-5.5.0.tgz#a419cc69f368d2def3b8b22ea03ed1c9be40e53f"
integrity sha512-B+QB4YmDx9RStKv8LLSl/aVIEV3nYJc3cJNNTK2Cd1TL+7P+cNpw9mAPeCgc5K+j01Dv6sxUzcITXDx7ZU3F0w==

buffer-from@^1.0.0:
version "1.1.2"
Expand Down Expand Up @@ -4689,16 +4689,16 @@ mongodb-connection-string-url@^2.6.0:
"@types/whatwg-url" "^8.2.1"
whatwg-url "^11.0.0"

mongodb@*, mongodb@^5.7.0:
version "5.7.0"
resolved "https://registry.npmjs.org/mongodb/-/mongodb-5.7.0.tgz"
integrity sha512-zm82Bq33QbqtxDf58fLWBwTjARK3NSvKYjyz997KSy6hpat0prjeX/kxjbPVyZY60XYPDNETaHkHJI2UCzSLuw==
mongodb@^5.8.1:
version "5.9.0"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-5.9.0.tgz#5a22065fa8cfaf1d58bf2e3c451cd2c4bfa983a2"
integrity sha512-g+GCMHN1CoRUA+wb1Agv0TI4YTSiWr42B5ulkiAfLLHitGK1R+PkSAf3Lr5rPZwi/3F04LiaZEW0Kxro9Fi2TA==
dependencies:
bson "^5.4.0"
bson "^5.5.0"
mongodb-connection-string-url "^2.6.0"
socks "^2.7.1"
optionalDependencies:
saslprep "^1.0.3"
"@mongodb-js/saslprep" "^1.1.0"

[email protected]:
version "2.1.2"
Expand Down Expand Up @@ -5833,13 +5833,6 @@ safe-buffer@~5.2.0:
resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

saslprep@^1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz"
integrity sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==
dependencies:
sparse-bitfield "^3.0.3"

semantic-release@^21.0.7:
version "21.0.7"
resolved "https://registry.npmjs.org/semantic-release/-/semantic-release-21.0.7.tgz"
Expand Down

0 comments on commit ba6684b

Please sign in to comment.