This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/server/models/Revision.js
Tom Moor 9274005cbb feat: Upgrade editor (#1227)
* WIP

* document migration

* fix: Handle clashing keyboard events

* fix: convert getSummary

* fix: parseDocumentIds

* lint

* fix: Remove unused plugin

* Move editor version to header
Add editor version check for API endpoints

* fix: Editor update auto-reload
Bump RME

* test

* bump rme

* Remove slate flow types, improve themeing, bump rme

* bump rme

* fix: parseDocumentIds returning duplicate ID's, improved regression tests

* test

* fix: Missing code styles

* lint

* chore: Upgrade v2 migration to use AST

* Bump RME

* Update welcome doc

* add highlight to keyboard shortcuts ref

* theming improvements

* fix: Code comments show as headings, closes #1255

* loop

* fix: TOC highlighting

* lint

* add: Automated backup of docs before migration

* Update embeds to new format

* fix: React warning

* bump to final editor version 10.0.0

* test
2020-05-19 20:39:34 -07:00

69 lines
1.7 KiB
JavaScript

// @flow
import { DataTypes, sequelize } from '../sequelize';
import MarkdownSerializer from 'slate-md-serializer';
const serializer = new MarkdownSerializer();
const Revision = sequelize.define('revision', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
version: DataTypes.SMALLINT,
editorVersion: DataTypes.STRING,
title: DataTypes.STRING,
text: DataTypes.TEXT,
// backup contains a record of text at the moment it was converted to v2
// this is a safety measure during deployment of new editor and will be
// dropped in a future update
backup: DataTypes.TEXT,
});
Revision.associate = models => {
Revision.belongsTo(models.Document, {
as: 'document',
foreignKey: 'documentId',
onDelete: 'cascade',
});
Revision.belongsTo(models.User, {
as: 'user',
foreignKey: 'userId',
});
Revision.addScope(
'defaultScope',
{
include: [{ model: models.User, as: 'user', paranoid: false }],
},
{ override: true }
);
};
Revision.prototype.migrateVersion = function() {
let migrated = false;
// migrate from document version 0 -> 1
if (!this.version) {
// removing the title from the document text attribute
this.text = this.text.replace(/^#\s(.*)\n/, '');
this.version = 1;
migrated = true;
}
// migrate from document version 1 -> 2
if (this.version === 1) {
const nodes = serializer.deserialize(this.text);
this.backup = this.text;
this.text = serializer.serialize(nodes, { version: 2 });
this.version = 2;
migrated = true;
}
if (migrated) {
return this.save({ silent: true, hooks: false });
}
};
export default Revision;