How to manage complex schema database with JSON Schema
superdevofficial opened this issue · 1 comments
When I export a service, I can't export complex schema information into Sequelize or Mongoose schema. Example : relationship information or constraint are ignored, so Sequelize and Mongoose are missing some parameters.
Here I submit a PR to solve a part of this issue for Mongoose : #236
BUT I'm not sure is good solution, so guys, how do you manage this kind of problem ?
There is an example project with complex database schema ?
Steps to reproduce
If you need a relationship like this:
let schema = {
//...
properties: {
//foreign key or ref to another model in order to join or populate
parentId: { type: 'ID', ref: 'User' },
}
}
Expected behavior
You expect something like this :
//sequelize
parent_id: {
type: Sequelize.INTEGER,
references: {
model: User,
key: 'id',
deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE
}
//or mongoose
parentId: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
Actual behavior
But actually you get :
//sequelize
parentId: {
type: DataTypes.INTEGER
},
//mongoose
parentId: mongoose.Schema.Types.ObjectId,
System configuration
Module versions (especially the part that's not working):
0.8.3
NodeJS version:
v10
You can add to or overwrite parts of the generated Mongoose schema with a custom object placed in serviceName.mongoose.?s at // !code: moduleExports // !end
.
Its better to do this than remove <DEFAULT>
on the generated schema and customizing it because the moduleExports
way still regenerates the schema if you make any changes to the JSON-schema.