fix(db/models): only register counter plugin if model doesn't already exist
This commit is contained in:
		
							parent
							
								
									a63a470a10
								
							
						
					
					
						commit
						2085131d5a
					
				| @ -30,7 +30,9 @@ const BandSchema = new mongoose.Schema<IBand>({ | ||||
| 	], | ||||
| }); | ||||
| 
 | ||||
| hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" }); | ||||
| hasMigrated && | ||||
| 	!mongoose.models.Band && | ||||
| 	BandSchema.plugin(AutoIncrement, { id: "band" }); | ||||
| export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>( | ||||
| 	"Band", | ||||
| 	BandSchema, | ||||
|  | ||||
| @ -67,7 +67,7 @@ const biffnoschema = new mongoose.Schema<IBiffno>({ | ||||
| 	}, | ||||
| }); | ||||
| 
 | ||||
| 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<IBiffno> = | ||||
| 	mongoose.models.Biffno || mongoose.model("Biffno", biffnoschema, "biffno"); | ||||
|  | ||||
| @ -48,7 +48,9 @@ export const FicmasSchema = new mongoose.Schema<IFicmas>({ | ||||
| 	}, | ||||
| }); | ||||
| 
 | ||||
| hasMigrated && FicmasSchema.plugin(AutoIncrement, { id: "ficmas_wishes" }); | ||||
| hasMigrated && | ||||
| 	!mongoose.models.Ficmas && | ||||
| 	FicmasSchema.plugin(AutoIncrement, { id: "ficmas_wishes", inc_field: "_id" }); | ||||
| 
 | ||||
| export const Ficmas: Model<IFicmas> = | ||||
| 	mongoose.models.Ficmas || model("Ficmas", FicmasSchema, "ficmas_wishes"); | ||||
|  | ||||
| @ -45,7 +45,9 @@ const challengeSchema = new mongoose.Schema<IChallenge>({ | ||||
| 	}, | ||||
| }); | ||||
| 
 | ||||
| hasMigrated && challengeSchema.plugin(AutoIncrement, { id: "challenges" }); | ||||
| hasMigrated && | ||||
| 	!mongoose.models.Challenge && | ||||
| 	challengeSchema.plugin(AutoIncrement, { id: "challenges" }); | ||||
| export const Challenge: Model<IChallenge> = | ||||
| 	mongoose.models.Challenge || | ||||
| 	mongoose.model("Challenge", challengeSchema, "challenges"); | ||||
|  | ||||
| @ -50,7 +50,9 @@ const PMSchema = new mongoose.Schema<IPrivMsg>({ | ||||
| 	}, | ||||
| }); | ||||
| 
 | ||||
| hasMigrated && PMSchema.plugin(AutoIncrement, { id: "private_message" }); | ||||
| hasMigrated && | ||||
| 	!mongoose.models.PrivMsg && | ||||
| 	PMSchema.plugin(AutoIncrement, { id: "private_message" }); | ||||
| 
 | ||||
| export const PrivMsg: Model<IPrivMsg> = | ||||
| 	/* mongoose.models.PrivMsg || */ mongoose.model( | ||||
|  | ||||
| @ -36,7 +36,9 @@ const DraftSchema = new Schema<IDraft>({ | ||||
| 	chapters: [Chapter], | ||||
| }); | ||||
| 
 | ||||
| hasMigrated && DraftSchema.plugin(AutoIncrement, { id: "drafts" }); | ||||
| hasMigrated && | ||||
| 	!mongoose.models.Draft && | ||||
| 	DraftSchema.plugin(AutoIncrement, { id: "drafts" }); | ||||
| 
 | ||||
| export const Draft: Model<IDraft> = | ||||
| 	/* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts"); | ||||
|  | ||||
| @ -87,9 +87,11 @@ const StorySchema = new mongoose.Schema<IStory>({ | ||||
| 		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<IStory> = | ||||
| 	/* mongoose.models.Story || */ mongoose.model( | ||||
| 		"Story", | ||||
|  | ||||
| @ -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<IReview> = | ||||
| 	/* mongoose.models.Review || */ mongoose.model( | ||||
|  | ||||
| @ -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<IUser, UModel>("User", UserSchema, "users"); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user