From bb5e021f201c8ad83fe2736dee0faef123bfca50 Mon Sep 17 00:00:00 2001
From: Max Wu <jackymaxj@gmail.com>
Date: Fri, 9 Feb 2018 21:27:06 +0800
Subject: [PATCH] Fix field type to prevent data truncation of authorship
 (#721)

* Fix field type to prevent data truncation of authorship
---
 .../20180209120907-longtext-of-authorship.js        | 13 +++++++++++++
 lib/models/note.js                                  |  2 +-
 lib/models/revision.js                              |  2 +-
 3 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 lib/migrations/20180209120907-longtext-of-authorship.js

diff --git a/lib/migrations/20180209120907-longtext-of-authorship.js b/lib/migrations/20180209120907-longtext-of-authorship.js
new file mode 100644
index 0000000..4cca544
--- /dev/null
+++ b/lib/migrations/20180209120907-longtext-of-authorship.js
@@ -0,0 +1,13 @@
+'use strict'
+
+module.exports = {
+  up: function (queryInterface, Sequelize) {
+    queryInterface.changeColumn('Notes', 'authorship', {type: Sequelize.TEXT('long')})
+    queryInterface.changeColumn('Revisions', 'authorship', {type: Sequelize.TEXT('long')})
+  },
+
+  down: function (queryInterface, Sequelize) {
+    queryInterface.changeColumn('Notes', 'authorship', {type: Sequelize.TEXT})
+    queryInterface.changeColumn('Revisions', 'authorship', {type: Sequelize.TEXT})
+  }
+}
diff --git a/lib/models/note.js b/lib/models/note.js
index 33dde80..484f1a8 100644
--- a/lib/models/note.js
+++ b/lib/models/note.js
@@ -69,7 +69,7 @@ module.exports = function (sequelize, DataTypes) {
       }
     },
     authorship: {
-      type: DataTypes.TEXT,
+      type: DataTypes.TEXT('long'),
       get: function () {
         return sequelize.processData(this.getDataValue('authorship'), [], JSON.parse)
       },
diff --git a/lib/models/revision.js b/lib/models/revision.js
index 170931b..9ecd14d 100644
--- a/lib/models/revision.js
+++ b/lib/models/revision.js
@@ -88,7 +88,7 @@ module.exports = function (sequelize, DataTypes) {
       type: DataTypes.INTEGER
     },
     authorship: {
-      type: DataTypes.TEXT,
+      type: DataTypes.TEXT('long'),
       get: function () {
         return sequelize.processData(this.getDataValue('authorship'), [], JSON.parse)
       },