-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(migration): add game server model migration
- Loading branch information
1 parent
4716e08
commit a3150da
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
migrations/1616687902073-mark-all-game-servers-as-not-deleted.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
'use strict' | ||
|
||
// | ||
// Set deleted to false on all game servers that do not have the 'deleted' property. | ||
// | ||
|
||
const { config } = require('dotenv'); | ||
const { MongoClient } = require('mongodb'); | ||
|
||
module.exports.up = next => { | ||
config(); | ||
|
||
let credentials = ''; | ||
if (process.env.MONGODB_USERNAME) { | ||
if (process.env.MONGODB_PASSWORD) { | ||
credentials = `${process.env.MONGODB_USERNAME}:${process.env.MONGODB_PASSWORD}@`; | ||
} else { | ||
credentials = `${process.env.MONGODB_USERNAME}@`; | ||
} | ||
} | ||
|
||
const uri = `mongodb://${credentials}${process.env.MONGODB_HOST}:${process.env.MONGODB_PORT}/${process.env.MONGODB_DB}`; | ||
|
||
MongoClient.connect(uri, { useUnifiedTopology: true }) | ||
.then(client => client.db()) | ||
.then(db => db.collection('gameservers')) | ||
.then(collection => collection.updateMany( | ||
{ | ||
deleted: { $exists: false }, | ||
}, | ||
{ | ||
$set: { deleted: false }, | ||
}, | ||
)) | ||
.then(() => next()); | ||
} |