diff --git a/models/band.ts b/models/band.ts index d6c3710..a58fef9 100644 --- a/models/band.ts +++ b/models/band.ts @@ -30,7 +30,9 @@ const BandSchema = new mongoose.Schema({ ], }); -hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" }); +hasMigrated && + !mongoose.models.Band && + BandSchema.plugin(AutoIncrement, { id: "band" }); export const Band: Model = /* mongoose.models.Band || */ model( "Band", BandSchema, diff --git a/models/challenges/biffno.ts b/models/challenges/biffno.ts index fef1891..587e4fe 100644 --- a/models/challenges/biffno.ts +++ b/models/challenges/biffno.ts @@ -67,7 +67,7 @@ const biffnoschema = new mongoose.Schema({ }, }); -hasMigrated && - biffnoschema.plugin(AutoIncrement, { start_seq: 1, id: "bif_id" }); +hasMigrated && !mongoose.models.Biffno; +biffnoschema.plugin(AutoIncrement, { start_seq: 1, id: "bif_id" }); export const Biffno: Model = mongoose.models.Biffno || mongoose.model("Biffno", biffnoschema, "biffno"); diff --git a/models/challenges/ficmas.ts b/models/challenges/ficmas.ts index 79f6271..9f240d5 100644 --- a/models/challenges/ficmas.ts +++ b/models/challenges/ficmas.ts @@ -48,7 +48,9 @@ export const FicmasSchema = new mongoose.Schema({ }, }); -hasMigrated && FicmasSchema.plugin(AutoIncrement, { id: "ficmas_wishes" }); +hasMigrated && + !mongoose.models.Ficmas && + FicmasSchema.plugin(AutoIncrement, { id: "ficmas_wishes", inc_field: "_id" }); export const Ficmas: Model = mongoose.models.Ficmas || model("Ficmas", FicmasSchema, "ficmas_wishes"); diff --git a/models/challenges/gen.ts b/models/challenges/gen.ts index 3344631..d6f140d 100644 --- a/models/challenges/gen.ts +++ b/models/challenges/gen.ts @@ -45,7 +45,9 @@ const challengeSchema = new mongoose.Schema({ }, }); -hasMigrated && challengeSchema.plugin(AutoIncrement, { id: "challenges" }); +hasMigrated && + !mongoose.models.Challenge && + challengeSchema.plugin(AutoIncrement, { id: "challenges" }); export const Challenge: Model = mongoose.models.Challenge || mongoose.model("Challenge", challengeSchema, "challenges"); diff --git a/models/privMsg.ts b/models/privMsg.ts index 11bb785..9f863a5 100644 --- a/models/privMsg.ts +++ b/models/privMsg.ts @@ -50,7 +50,9 @@ const PMSchema = new mongoose.Schema({ }, }); -hasMigrated && PMSchema.plugin(AutoIncrement, { id: "private_message" }); +hasMigrated && + !mongoose.models.PrivMsg && + PMSchema.plugin(AutoIncrement, { id: "private_message" }); export const PrivMsg: Model = /* mongoose.models.PrivMsg || */ mongoose.model( diff --git a/models/stories/draft.ts b/models/stories/draft.ts index d689199..f98c0b5 100644 --- a/models/stories/draft.ts +++ b/models/stories/draft.ts @@ -36,7 +36,9 @@ const DraftSchema = new Schema({ chapters: [Chapter], }); -hasMigrated && DraftSchema.plugin(AutoIncrement, { id: "drafts" }); +hasMigrated && + !mongoose.models.Draft && + DraftSchema.plugin(AutoIncrement, { id: "drafts" }); export const Draft: Model = /* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts"); diff --git a/models/stories/index.ts b/models/stories/index.ts index 9360a52..386f867 100644 --- a/models/stories/index.ts +++ b/models/stories/index.ts @@ -87,9 +87,11 @@ const StorySchema = new mongoose.Schema({ default: new Date(), }, }); +hasMigrated && !mongoose.models.Story; +Chapter.plugin(AutoIncrement, { id: "chapterid", inc_field: "id" }); hasMigrated && - Chapter.plugin(AutoIncrement, { id: "chapterid", inc_field: "id" }); -hasMigrated && StorySchema.plugin(AutoIncrement, { id: "storyid" }); + !mongoose.models.Story && + StorySchema.plugin(AutoIncrement, { id: "storyid" }); export const Story: Model = /* mongoose.models.Story || */ mongoose.model( "Story", diff --git a/models/stories/review.ts b/models/stories/review.ts index 5760205..78a01a1 100644 --- a/models/stories/review.ts +++ b/models/stories/review.ts @@ -65,7 +65,9 @@ CommentSchema.pre("findOne", populate("replies")) .pre("findOne", populateSelected("replyingTo", "-replies")) .pre("find", populateSelected("replyingTo", "-replies")); -hasMigrated && CommentSchema.plugin(AutoIncrement, { id: "reviews" }); +hasMigrated && + !mongoose.models.Review && + CommentSchema.plugin(AutoIncrement, { id: "reviews" }); export const Review: Model = /* mongoose.models.Review || */ mongoose.model( diff --git a/models/user.ts b/models/user.ts index d3e24b2..d411c06 100644 --- a/models/user.ts +++ b/models/user.ts @@ -293,5 +293,6 @@ UserSchema.methods.generateToken = function (jwtKey: string): string { }; hasMigrated && + !mongoose.models.User && UserSchema.plugin(AutoIncrement, { id: "userid", inc_field: "_id" }); export const User = mongoose.model("User", UserSchema, "users");