refactor: migrate to objection.js + knex
This commit is contained in:
16
server/models_old/_relations.js
Normal file
16
server/models_old/_relations.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Associate DB Model relations
|
||||
*/
|
||||
module.exports = db => {
|
||||
db.User.belongsToMany(db.Group, { through: 'userGroups' })
|
||||
db.Group.belongsToMany(db.User, { through: 'userGroups' })
|
||||
db.Group.hasMany(db.Right)
|
||||
db.Right.belongsTo(db.Group)
|
||||
db.Document.belongsToMany(db.Tag, { through: 'documentTags' })
|
||||
db.Document.hasMany(db.Comment)
|
||||
db.Tag.belongsToMany(db.Document, { through: 'documentTags' })
|
||||
db.File.belongsTo(db.Folder)
|
||||
db.Folder.hasMany(db.File)
|
||||
db.Comment.belongsTo(db.Document)
|
||||
db.Comment.belongsTo(db.User, { as: 'author' })
|
||||
}
|
16
server/models_old/comment.js
Normal file
16
server/models_old/comment.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Comment schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let commentSchema = sequelize.define('comment', {
|
||||
content: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true
|
||||
})
|
||||
|
||||
return commentSchema
|
||||
}
|
64
server/models_old/document.js
Normal file
64
server/models_old/document.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Document schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let documentSchema = sequelize.define('setting', {
|
||||
path: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
len: [2, 255]
|
||||
}
|
||||
},
|
||||
subtitle: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
},
|
||||
parentPath: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
},
|
||||
parentTitle: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
},
|
||||
isDirectory: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
isEntry: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
isDraft: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
searchContent: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['path']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return documentSchema
|
||||
}
|
42
server/models_old/file.js
Normal file
42
server/models_old/file.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* File schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let fileSchema = sequelize.define('file', {
|
||||
category: {
|
||||
type: DataTypes.ENUM('binary', 'image'),
|
||||
allowNull: false,
|
||||
defaultValue: 'binary'
|
||||
},
|
||||
mime: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: 'application/octet-stream'
|
||||
},
|
||||
extra: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true
|
||||
},
|
||||
filename: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
basename: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
filesize: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isInt: true,
|
||||
min: 0
|
||||
}
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true
|
||||
})
|
||||
|
||||
return fileSchema
|
||||
}
|
22
server/models_old/folder.js
Normal file
22
server/models_old/folder.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Folder schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let folderSchema = sequelize.define('folder', {
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['name']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return folderSchema
|
||||
}
|
16
server/models_old/group.js
Normal file
16
server/models_old/group.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Group schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let groupSchema = sequelize.define('group', {
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true
|
||||
})
|
||||
|
||||
return groupSchema
|
||||
}
|
39
server/models_old/locale.js
Normal file
39
server/models_old/locale.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Locale schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let localeSchema = sequelize.define('locale', {
|
||||
code: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
strings: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true
|
||||
},
|
||||
isRTL: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
nativeName: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['code']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return localeSchema
|
||||
}
|
36
server/models_old/right.js
Normal file
36
server/models_old/right.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Right schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let rightSchema = sequelize.define('right', {
|
||||
path: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
role: {
|
||||
type: DataTypes.ENUM('read', 'write', 'manage'),
|
||||
allowNull: false,
|
||||
defaultValue: 'read'
|
||||
},
|
||||
exact: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
allow: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
fields: ['path']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return rightSchema
|
||||
}
|
26
server/models_old/setting.js
Normal file
26
server/models_old/setting.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Settings schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let settingSchema = sequelize.define('setting', {
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
config: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['key']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return settingSchema
|
||||
}
|
22
server/models_old/tag.js
Normal file
22
server/models_old/tag.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Tags schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let tagSchema = sequelize.define('tag', {
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['key']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return tagSchema
|
||||
}
|
Reference in New Issue
Block a user