Migrate atlasId -> collectionId

This commit is contained in:
Tom Moor
2018-08-07 23:23:26 -07:00
parent f49c495a9a
commit 18cfe26e83
11 changed files with 50 additions and 24 deletions

View File

@ -119,7 +119,7 @@ const Document = sequelize.define(
Document.associate = models => {
Document.belongsTo(models.Collection, {
as: 'collection',
foreignKey: 'atlasId',
foreignKey: 'collectionId',
onDelete: 'cascade',
});
Document.belongsTo(models.Team, {
@ -266,7 +266,7 @@ Document.searchForUser = async (
Document.addHook('beforeSave', async model => {
if (!model.publishedAt) return;
const collection = await Collection.findById(model.atlasId);
const collection = await Collection.findById(model.collectionId);
if (collection.type !== 'atlas') return;
await collection.updateDocument(model);
@ -276,7 +276,7 @@ Document.addHook('beforeSave', async model => {
Document.addHook('afterCreate', async model => {
if (!model.publishedAt) return;
const collection = await Collection.findById(model.atlasId);
const collection = await Collection.findById(model.collectionId);
if (collection.type !== 'atlas') return;
await collection.addDocumentToStructure(model);
@ -295,7 +295,7 @@ Document.addHook('afterDestroy', model =>
Document.prototype.publish = async function() {
if (this.publishedAt) return this.save();
const collection = await Collection.findById(this.atlasId);
const collection = await Collection.findById(this.collectionId);
if (collection.type !== 'atlas') return this.save();
await collection.addDocumentToStructure(this);