Skip to content

Commit 613ec22

Browse files
authored
fix: keep migrations as commonjs (#244)
1 parent ea1e201 commit 613ec22

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

.vscode/launch.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,26 @@
1616
"request": "launch",
1717
"name": "Debug current test",
1818
"env": {
19-
"NODE_OPTIONS": "--experimental-vm-modules",
19+
"NODE_OPTIONS": "--experimental-vm-modules"
2020
},
2121
"program": "${workspaceFolder}/node_modules/.bin/jest",
22-
"args": [
23-
"${relativeFile}"
24-
],
22+
"args": ["${relativeFile}"],
2523
"console": "integratedTerminal",
26-
"internalConsoleOptions": "neverOpen",
27-
"disableOptimisticBPs": true
24+
"internalConsoleOptions": "neverOpen"
25+
},
26+
{
27+
"type": "node",
28+
"request": "launch",
29+
"name": "Debug migrations",
30+
"skipFiles": ["<node_internals>/**"],
31+
"runtimeArgs": [
32+
"--inspect-brk",
33+
"${workspaceRoot}/node_modules/.bin/migrate-mongo",
34+
"up",
35+
"-f",
36+
"migrate-mongo-config.cjs"
37+
],
38+
"console": "integratedTerminal"
2839
}
2940
]
3041
}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WORKDIR /usr/src/app
55

66
COPY ./app ./app
77
COPY ./migrations ./migrations
8-
COPY ./migrate-mongo-config.js ./
8+
COPY ./migrate-mongo-config.cjs ./
99
COPY ./package*.json ./
1010

1111
RUN yarn
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import 'dotenv/config';
1+
require('dotenv').config();
22

33
const { MONGO_CONNECTION_STRING, MONGO_DATABASE_NAME } = process.env;
44

5-
export default {
5+
module.exports = {
66
mongodb: {
77
url: MONGO_CONNECTION_STRING,
88
databaseName: MONGO_DATABASE_NAME,
99
},
1010
migrationsDir: 'migrations',
1111
changelogCollectionName: 'changelog',
12+
migrationFileExtension: '.cjs',
1213
};

migrations/20190923213928-add_user_schema.js renamed to migrations/20190923213928-add_user_schema.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const up = async (db) =>
4949

5050
const down = async (db) => db.collection(USERS_COLLECTION).drop();
5151

52-
export default {
52+
module.exports = {
5353
up,
5454
down,
5555
};

migrations/20191002205600-bootstrap_superadmin_user.js renamed to migrations/20191002205600-bootstrap_superadmin_user.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require('dotenv').config();
2-
import bcrypt from 'bcrypt';
2+
const bcrypt = require('bcrypt');
33

44
const USERS_COLLECTION = 'users';
55

@@ -21,7 +21,7 @@ const down = async (db) =>
2121
email: SUPERADMIN_EMAIL,
2222
});
2323

24-
export default {
24+
module.exports = {
2525
up,
2626
down,
2727
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"dev": "./node_modules/.bin/nodemon ./app",
9+
"migrate": "./node_modules/.bin/migrate-mongo up -f migrate-mongo-config.cjs",
910
"test": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
1011
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest -i --collectCoverage --forceExit",
1112
"start": "node ./app",

0 commit comments

Comments
 (0)