Skip to content

Commit

Permalink
don't recreate model every reload if already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep-ghosh committed Jul 11, 2024
1 parent f2f03ff commit 973273f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/lib/models/file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import mongoose from 'mongoose';
import { Schema, models, model } from 'mongoose';
import type { Document, Model } from 'mongoose';

const fileSchema = new mongoose.Schema({
interface IFile extends Document {
name: string;
size: number;
type: string;
key: string;
expires: Date;
created_at: Date;
}

const fileSchema = new Schema<IFile>({
name: {
type: String,
required: true
Expand All @@ -27,4 +37,4 @@ const fileSchema = new mongoose.Schema({
}
});

export default mongoose.model('File', fileSchema);
export default (models?.File as Model<IFile>) || model('File', fileSchema);

0 comments on commit 973273f

Please sign in to comment.