From 75bf265bd5faaed68f12a6d38e38ebe3b5871417 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 15 Oct 2017 18:35:28 -0700 Subject: [PATCH] Removed legacy navigationtree --- README.md | 8 +++---- ...012353-remove-collection-navigationtree.js | 12 ++++++++++ server/models/Collection.js | 23 ------------------- server/presenters/collection.js | 2 +- 4 files changed, 17 insertions(+), 28 deletions(-) create mode 100644 server/migrations/20171016012353-remove-collection-navigationtree.js diff --git a/README.md b/README.md index b4b11cf2..0bd90ab2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 1. Install dependencies with `yarn` 1. Register a Slack app at https://api.slack.com/apps 1. Copy the file `.env.sample` to `.env` and fill out the keys - 1. Run DB migrations `yarn run sequelize -- db:migrate` + 1. Run DB migrations `yarn sequelize -- db:migrate` 1. Start the development server `yarn start` @@ -16,12 +16,12 @@ Sequelize is used to create and run migrations, for example: ``` -yarn run sequelize migration:create -yarn run sequelize db:migrate +yarn sequelize migration:create +yarn sequelize db:migrate ``` Or to run migrations on test database: ``` -yarn run sequelize db:migrate -- --env test +yarn sequelize db:migrate -- --env test ``` diff --git a/server/migrations/20171016012353-remove-collection-navigationtree.js b/server/migrations/20171016012353-remove-collection-navigationtree.js new file mode 100644 index 00000000..0ba1eb4c --- /dev/null +++ b/server/migrations/20171016012353-remove-collection-navigationtree.js @@ -0,0 +1,12 @@ +module.exports = { + up: function(queryInterface, Sequelize) { + queryInterface.removeColumn('collections', 'navigationTree'); + }, + + down: function(queryInterface, Sequelize) { + queryInterface.addColumn('collections', 'navigationTree', { + type: Sequelize.JSONB, + allowNull: true, + }); + }, +}; diff --git a/server/models/Collection.js b/server/models/Collection.js index 1ca29075..a05f0289 100644 --- a/server/models/Collection.js +++ b/server/models/Collection.js @@ -29,7 +29,6 @@ const Collection = sequelize.define( creatorId: DataTypes.UUID, /* type: atlas */ - navigationTree: DataTypes.JSONB, // legacy documentStructure: DataTypes.JSONB, }, { @@ -98,28 +97,6 @@ Collection.prototype.getUrl = function() { return `/collections/${this.id}`; }; -Collection.prototype.getDocumentsStructure = async function() { - // Lazy fill this.documentStructure - TMP for internal release - if (!this.documentStructure) { - this.documentStructure = this.navigationTree.children; - - // Remove parent references from all root documents - await this.navigationTree.children.forEach(async ({ id }) => { - const document = await Document.findById(id); - document.parentDocumentId = null; - await document.save(); - }); - - // Remove root document - const rootDocument = await Document.findById(this.navigationTree.id); - await rootDocument.destroy(); - - await this.save(); - } - - return this.documentStructure; -}; - Collection.prototype.addDocumentToStructure = async function( document, index, diff --git a/server/presenters/collection.js b/server/presenters/collection.js index a6fdbc8e..aeae3dce 100644 --- a/server/presenters/collection.js +++ b/server/presenters/collection.js @@ -19,7 +19,7 @@ async function present(ctx: Object, collection: Collection) { }; if (collection.type === 'atlas') { - data.documents = await collection.getDocumentsStructure(); + data.documents = collection.documentStructure; } if (collection.documents) {