Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the migration to be able to run it smoothly inside the pods #454

Merged
merged 3 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ SMTP_HOST=<SMTP_HOST>
SMTP_MESSAGE_FROM=<SMTP_MESSAGE_FROM>
SMTP_PORT=<SMTP_PORT>
SMTP_SECURE=<SMTP_SECURE>
DB_MIGRATE_MONGODB_URL="mongodb://<HOST>:<PORT>"
DB_MIGRATE_DATABASE_NAME="<DATABASE_NAME>"
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,12 @@ Where the [current SciCat Backend](https://github.com/SciCatProject/backend) acc
All database [migration scripts](https://github.com/SciCatProject/scicat-backend-next/tree/master/migrations) located in the [migrations](/migrations/) folder. Copy these together with [`migrate-mongo-config.js`](https://github.com/SciCatProject/scicat-backend-next/blob/master/migrate-mongo-config.js) file to a location were you can access your MongoDB instance and have `migrate-mongo` package installed either globally(which is preferred) or locally if global installation is not possible. Then modify the config file to contain your MongoDB instance details like database name and url. Once modified, start the migration by running

```sh
migrate-mongo up
npm run migrate:db:up
```

if `migrate-mongo` is installed globally at the location where you want to run it from or if it is locally installed just run

For down migration use:
```sh
./node_modules/migrate-mongo/bin/migrate-mongo.js up
npm run migrate:db:down
```

---
Expand Down
4 changes: 2 additions & 2 deletions migrate-mongo-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const config = {
mongodb: {
// TODO Change (or review) the url to your MongoDB:
url: "mongodb://localhost:27017",
url: process.env.DB_MIGRATE_MONGODB_URL,

// TODO Change this to your database name:
databaseName: "dacat",
databaseName: process.env.DB_MIGRATE_DATABASE_NAME,

options: {
useNewUrlParser: true, // removes a deprecation warning when connecting
Expand Down
1 change: 1 addition & 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 @@ -10,7 +10,8 @@
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"migrate:db:up": "node ./node_modules/migrate-mongo/bin/migrate-mongo.js up",
"migrate:db:up": "node ./scripts/setVariables.js && node ./node_modules/migrate-mongo/bin/migrate-mongo.js up",
"migrate:db:down": "node ./scripts/setVariables.js && node ./node_modules/migrate-mongo/bin/migrate-mongo.js down",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
Expand Down Expand Up @@ -44,6 +45,7 @@
"bcrypt": "^5.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"dotenv": "^16.0.3",
"express-session": "^1.17.3",
"handlebars": "^4.7.7",
"lodash": "^4.17.21",
Expand Down
1 change: 1 addition & 0 deletions scripts/setVariables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("dotenv").config();