const mongoose = require('mongoose');
// eslint-disable-next-line no-unused-vars
const { info, error } = require('../src/logger');

const { connect, close } = require('../src/utils/database');

// use your own name for your model, otherwise other migrations may fail.
// The third parameter is the actually relevent one for what collection to write to.
const User = mongoose.model('makeMeUnique', new mongoose.Schema({
	firstName: { type: String, required: true },
	lastName: { type: String, required: true },
}, {
	timestamps: true,
}), 'user');

// How to use more than one schema per collection on mongodb
// https://stackoverflow.com/questions/14453864/use-more-than-one-schema-per-collection-on-mongodb

module.exports = {
	up: async function up() {
		await connect();
		// ////////////////////////////////////////////////////
		// Make changes to the database here.
		// Hint: Access models via this('modelName'), not an imported model to have
		// access to the correct database connection. Otherwise Mongoose calls never return.
		await User.findOneAndUpdate({
			firstName: 'Marla',
			lastName: 'Mathe',
		}, {
			firstName: 'Max',
		}).lean().exec();
		// ////////////////////////////////////////////////////
		await close();
		return Promise.resolve();
	},

	down: async function down() {
		await connect();
		// ////////////////////////////////////////////////////
		// Implement the necessary steps to roll back the migration here.
		await User.findOneAndUpdate({
			firstName: 'Max',
			lastName: 'Mathe',
		}, {
			firstName: 'Marla',
		}).lean().exec();
		// ////////////////////////////////////////////////////
		await close();
		return Promise.resolve();
	},
};

@@ -702,16 +702,119 @@
 ongodb%0A%0A
+%0A// TODO npm run migration-persist and remove this line%0A// TODO update seed data and remove this line%0A%0A
 module.e
@@ -1337,36 +1337,8 @@
 ();%0A
-%09%09return Promise.resolve();%0A
 %09%7D,%0A
@@ -1718,36 +1718,8 @@
 ();%0A
-%09%09return Promise.resolve();%0A
 %09%7D,%0A

update migration template