import { Challenge } from "../models/challenges/gen";
import { MongoClient } from "mongodb";
import mongoose from "mongoose";
import { uri, olduri } from "../lib/dbconfig";

import { Band } from "../models/band";

const cli = new MongoClient(olduri);
export default async function () {
	try {
		await cli.connect()

		await mongoose.connect(uri).then(() => console.log("connect'd"));

		const db = cli.db("rockfic_old")
		const col = db.collection("challenges");
		const cursor = col.find({});
		for await(const s of cursor) {
			const nc = new Challenge({
				_id: s.chall_id, active: s.isActive,
				color: s.color.toLowerCase(),
				allowMultiple: s.allowMultiple,
				name: s.name,
				description: s.description,
				deadline: s.deadline
			})
			await nc.save()
		}
	} catch(e) {
		console.error(e)
	} finally {
		return 0
	}
}
