|
@@ -0,0 +1,35 @@
|
|
|
+'use strict';
|
|
|
+const Schema = require('mongoose').Schema;
|
|
|
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
+
|
|
|
+const column = new Schema(
|
|
|
+ {
|
|
|
+ title: { type: String, required: true },
|
|
|
+ type: { type: String, default: String },
|
|
|
+ required: { type: Boolean, default: false },
|
|
|
+ maxLength: { type: Number },
|
|
|
+ remark: { type: String },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ _id: false,
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+
|
|
|
+const table = {
|
|
|
+ name: { type: String, required: true },
|
|
|
+ project: { type: ObjectId, required: true },
|
|
|
+ columns: [ column ],
|
|
|
+ remark: { type: String },
|
|
|
+};
|
|
|
+const schema = new Schema(table, { toJSON: { virtuals: true } });
|
|
|
+schema.index({ id: 1 });
|
|
|
+schema.index({ name: 1 });
|
|
|
+schema.index({ project: 1 });
|
|
|
+schema.index({ 'meta.createdAt': 1 });
|
|
|
+schema.plugin(metaPlugin);
|
|
|
+module.exports = app => {
|
|
|
+ const { mongoose } = app;
|
|
|
+ return mongoose.model('Table', schema, 'table');
|
|
|
+};
|