From 9631e58e6592b4278f24264ef025c3e5a84ab5db Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sat, 3 Jun 2017 12:04:13 -0700 Subject: [PATCH] Renamed collections table and added a new column for documents --- ...603185012-add-collection-documents-migration.js | 14 ++++++++++++++ server/models/Collection.js | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 server/migrations/20170603185012-add-collection-documents-migration.js diff --git a/server/migrations/20170603185012-add-collection-documents-migration.js b/server/migrations/20170603185012-add-collection-documents-migration.js new file mode 100644 index 00000000..6529706f --- /dev/null +++ b/server/migrations/20170603185012-add-collection-documents-migration.js @@ -0,0 +1,14 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + queryInterface.renameTable('atlases', 'collections'); + queryInterface.addColumn('collections', 'documents', { + type: Sequelize.ARRAY(Sequelize.JSONB), + allowNull: true, + }); + }, + + down: (queryInterface, _Sequelize) => { + queryInterface.renameTable('collections', 'atlases'); + queryInterface.removeColumn('atlases', 'documents'); + }, +}; diff --git a/server/models/Collection.js b/server/models/Collection.js index 01f8cf66..b750b1fb 100644 --- a/server/models/Collection.js +++ b/server/models/Collection.js @@ -1,3 +1,4 @@ +// @flow import slug from 'slug'; import randomstring from 'randomstring'; import { DataTypes, sequelize } from '../sequelize'; @@ -9,7 +10,7 @@ slug.defaults.mode = 'rfc3986'; const allowedCollectionTypes = [['atlas', 'journal']]; const Collection = sequelize.define( - 'atlas', + 'collection', { id: { type: DataTypes.UUID, @@ -26,10 +27,11 @@ const Collection = sequelize.define( creatorId: DataTypes.UUID, /* type: atlas */ - navigationTree: DataTypes.JSONB, + navigationTree: DataTypes.JSONB, // legacy + documents: DataTypes.ARRAY(DataTypes.JSONB), }, { - tableName: 'atlases', + tableName: 'collections', paranoid: true, hooks: { beforeValidate: collection => {