next/models/band.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ a8e113e969
refactor(db/models): remove model existence guards
this way, plugins are registered if `hasMigrated` is true. we've already enabled automatically overwriting models, therefore, the guard's condition will always be false
2023-12-29 16:36:26 -05:00

39 lines
721 B
TypeScript

import mongoose, { connect, Document, Model } from "mongoose";
const { Schema, model } = mongoose;
import SequenceFactory from "mongoose-sequence";
import { hasMigrated } from "@dbconfig";
const AutoIncrement = SequenceFactory(mongoose);
export interface IBand {
_id: number;
name: string;
locked: boolean;
characters: string[];
}
const BandSchema = new mongoose.Schema<IBand>({
_id: {
type: Number,
},
name: {
type: String,
},
locked: {
type: Boolean,
default: false,
},
characters: [
{
type: String,
},
],
});
hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" });
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>(
"Band",
BandSchema,
"bands",
);