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
This commit is contained in:
parent
922807ba6a
commit
a8e113e969
@ -30,9 +30,7 @@ const BandSchema = new mongoose.Schema<IBand>({
|
||||
],
|
||||
});
|
||||
|
||||
hasMigrated &&
|
||||
!mongoose.models.Band &&
|
||||
BandSchema.plugin(AutoIncrement, { id: "band" });
|
||||
hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" });
|
||||
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>(
|
||||
"Band",
|
||||
BandSchema,
|
||||
|
@ -68,7 +68,6 @@ const biffnoschema = new mongoose.Schema<IBiffno>({
|
||||
});
|
||||
|
||||
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");
|
||||
|
@ -49,7 +49,6 @@ export const FicmasSchema = new mongoose.Schema<IFicmas>({
|
||||
});
|
||||
|
||||
hasMigrated &&
|
||||
!mongoose.models.Ficmas &&
|
||||
FicmasSchema.plugin(AutoIncrement, { id: "ficmas_wishes", inc_field: "_id" });
|
||||
|
||||
export const Ficmas: Model<IFicmas> =
|
||||
|
@ -45,9 +45,7 @@ const challengeSchema = new mongoose.Schema<IChallenge>({
|
||||
},
|
||||
});
|
||||
|
||||
hasMigrated &&
|
||||
!mongoose.models.Challenge &&
|
||||
challengeSchema.plugin(AutoIncrement, { id: "challenges" });
|
||||
hasMigrated && challengeSchema.plugin(AutoIncrement, { id: "challenges" });
|
||||
export const Challenge: Model<IChallenge> =
|
||||
// mongoose.models.Challenge ||
|
||||
mongoose.model("Challenge", challengeSchema, "challenges");
|
||||
|
@ -50,9 +50,7 @@ const PMSchema = new mongoose.Schema<IPrivMsg>({
|
||||
},
|
||||
});
|
||||
|
||||
hasMigrated &&
|
||||
!mongoose.models.PrivMsg &&
|
||||
PMSchema.plugin(AutoIncrement, { id: "private_message" });
|
||||
hasMigrated && PMSchema.plugin(AutoIncrement, { id: "private_message" });
|
||||
|
||||
export const PrivMsg: Model<IPrivMsg> =
|
||||
/* mongoose.models.PrivMsg || */ mongoose.model(
|
||||
|
@ -17,28 +17,29 @@ export type IDraft = Omit<
|
||||
|
||||
// const Cha
|
||||
|
||||
const DraftSchema = new Schema<IDraft>({
|
||||
title: {
|
||||
type: String,
|
||||
const DraftSchema = new Schema<IDraft>(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
coAuthor: {
|
||||
type: Number,
|
||||
ref: "User",
|
||||
default: null,
|
||||
},
|
||||
author: {
|
||||
type: Number,
|
||||
ref: "User",
|
||||
},
|
||||
chapters: [Chapter],
|
||||
},
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
coAuthor: {
|
||||
type: Number,
|
||||
ref: "User",
|
||||
default: null,
|
||||
},
|
||||
author: {
|
||||
type: Number,
|
||||
ref: "User",
|
||||
},
|
||||
chapters: [Chapter],
|
||||
});
|
||||
{ timestamps: true },
|
||||
);
|
||||
|
||||
hasMigrated &&
|
||||
!mongoose.models.Draft &&
|
||||
DraftSchema.plugin(AutoIncrement, { id: "drafts" });
|
||||
hasMigrated && DraftSchema.plugin(AutoIncrement, { id: "drafts" });
|
||||
|
||||
export const Draft: Model<IDraft> =
|
||||
/* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts");
|
||||
|
@ -88,7 +88,6 @@ const StorySchema = new mongoose.Schema<IStory>({
|
||||
},
|
||||
});
|
||||
hasMigrated &&
|
||||
!mongoose.models.Story &&
|
||||
Chapter.plugin(AutoIncrement, { id: "chapterid", inc_field: "id" });
|
||||
hasMigrated && StorySchema.plugin(AutoIncrement, { id: "storyid" });
|
||||
export const Story: Model<IStory> =
|
||||
|
@ -72,9 +72,7 @@ CommentSchema
|
||||
populateSelected("author", "User", "profile username _id blocked"),
|
||||
);
|
||||
|
||||
hasMigrated &&
|
||||
!mongoose.models.Review &&
|
||||
CommentSchema.plugin(AutoIncrement, { id: "reviews" });
|
||||
hasMigrated && CommentSchema.plugin(AutoIncrement, { id: "reviews" });
|
||||
|
||||
export const Review: Model<IReview> =
|
||||
/* mongoose.models.Review || */ mongoose.model(
|
||||
|
@ -293,6 +293,5 @@ UserSchema.methods.generateJWT = 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…
Reference in New Issue
Block a user