feat: Ensure that editorVersion is saved with document/revisions (#1212)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// @flow
|
||||
import { action, set, computed } from 'mobx';
|
||||
import pkg from 'rich-markdown-editor/package.json';
|
||||
import addDays from 'date-fns/add_days';
|
||||
import invariant from 'invariant';
|
||||
import { client } from 'utils/ApiClient';
|
||||
@@ -180,6 +181,7 @@ export default class Document extends BaseModel {
|
||||
try {
|
||||
if (isCreating) {
|
||||
return await this.store.create({
|
||||
editorVersion: pkg.version,
|
||||
parentDocumentId: this.parentDocumentId,
|
||||
collectionId: this.collectionId,
|
||||
title: this.title,
|
||||
@@ -193,6 +195,7 @@ export default class Document extends BaseModel {
|
||||
title: this.title,
|
||||
text: this.text,
|
||||
lastRevision: this.revision,
|
||||
editorVersion: pkg.version,
|
||||
...options,
|
||||
});
|
||||
} finally {
|
||||
|
||||
@@ -688,6 +688,7 @@ router.post('documents.create', auth(), async ctx => {
|
||||
const {
|
||||
title = '',
|
||||
text = '',
|
||||
editorVersion,
|
||||
publish,
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
@@ -726,6 +727,7 @@ router.post('documents.create', auth(), async ctx => {
|
||||
|
||||
let document = await Document.create({
|
||||
parentDocumentId,
|
||||
editorVersion,
|
||||
collectionId: collection.id,
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
@@ -781,6 +783,7 @@ router.post('documents.update', auth(), async ctx => {
|
||||
publish,
|
||||
autosave,
|
||||
done,
|
||||
editorVersion,
|
||||
lastRevision,
|
||||
append,
|
||||
} = ctx.body;
|
||||
@@ -798,6 +801,7 @@ router.post('documents.update', auth(), async ctx => {
|
||||
|
||||
// Update document
|
||||
if (title) document.title = title;
|
||||
if (editorVersion) document.editorVersion = editorVersion;
|
||||
|
||||
if (append) {
|
||||
document.text += text;
|
||||
|
||||
19
server/migrations/20200316040755-document-editor-version.js
Normal file
19
server/migrations/20200316040755-document-editor-version.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.addColumn('documents', 'editorVersion', {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
});
|
||||
await queryInterface.addColumn('revisions', 'editorVersion', {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn('documents', 'editorVersion');
|
||||
await queryInterface.removeColumn('revisions', 'editorVersion');
|
||||
}
|
||||
};
|
||||
@@ -37,6 +37,7 @@ const createRevision = (doc, options = {}) => {
|
||||
title: doc.title,
|
||||
text: doc.text,
|
||||
userId: doc.lastModifiedById,
|
||||
editorVersion: doc.editorVersion,
|
||||
documentId: doc.id,
|
||||
},
|
||||
{
|
||||
@@ -91,6 +92,7 @@ const Document = sequelize.define(
|
||||
},
|
||||
},
|
||||
},
|
||||
editorVersion: DataTypes.STRING,
|
||||
text: DataTypes.TEXT,
|
||||
isWelcome: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
revisionCount: { type: DataTypes.INTEGER, defaultValue: 0 },
|
||||
|
||||
@@ -7,6 +7,7 @@ const Revision = sequelize.define('revision', {
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
editorVersion: DataTypes.STRING,
|
||||
title: DataTypes.STRING,
|
||||
text: DataTypes.TEXT,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user