Skip to content

Commit

Permalink
fix(migration): add game server model migration
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc committed Mar 25, 2021
1 parent 4716e08 commit a3150da
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions migrations/1616687902073-mark-all-game-servers-as-not-deleted.js
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());
}

0 comments on commit a3150da

Please sign in to comment.