Migrate atlasId -> collectionId
This commit is contained in:
@ -19,7 +19,7 @@ router.post('documents.list', auth(), pagination(), async ctx => {
|
|||||||
|
|
||||||
const user = ctx.state.user;
|
const user = ctx.state.user;
|
||||||
let where = { teamId: user.teamId };
|
let where = { teamId: user.teamId };
|
||||||
if (collection) where = { ...where, atlasId: collection };
|
if (collection) where = { ...where, collectionId: collection };
|
||||||
|
|
||||||
const starredScope = { method: ['withStarred', user.id] };
|
const starredScope = { method: ['withStarred', user.id] };
|
||||||
const documents = await Document.scope('defaultScope', starredScope).findAll({
|
const documents = await Document.scope('defaultScope', starredScope).findAll({
|
||||||
@ -49,7 +49,7 @@ router.post('documents.pinned', auth(), pagination(), async ctx => {
|
|||||||
const documents = await Document.scope('defaultScope', starredScope).findAll({
|
const documents = await Document.scope('defaultScope', starredScope).findAll({
|
||||||
where: {
|
where: {
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
atlasId: collection,
|
collectionId: collection,
|
||||||
pinnedById: {
|
pinnedById: {
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
[Op.ne]: null,
|
[Op.ne]: null,
|
||||||
@ -329,7 +329,7 @@ router.post('documents.create', auth(), async ctx => {
|
|||||||
parentDocumentObj = await Document.findOne({
|
parentDocumentObj = await Document.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: parentDocument,
|
id: parentDocument,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
authorize(user, 'read', parentDocumentObj);
|
authorize(user, 'read', parentDocumentObj);
|
||||||
@ -337,7 +337,7 @@ router.post('documents.create', auth(), async ctx => {
|
|||||||
|
|
||||||
let document = await Document.create({
|
let document = await Document.create({
|
||||||
parentDocumentId: parentDocumentObj.id,
|
parentDocumentId: parentDocumentObj.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
lastModifiedById: user.id,
|
lastModifiedById: user.id,
|
||||||
|
@ -155,7 +155,10 @@ describe('#documents.list', async () => {
|
|||||||
it('should allow filtering by collection', async () => {
|
it('should allow filtering by collection', async () => {
|
||||||
const { user, document } = await seed();
|
const { user, document } = await seed();
|
||||||
const res = await server.post('/api/documents.list', {
|
const res = await server.post('/api/documents.list', {
|
||||||
body: { token: user.getJwtToken(), collection: document.atlasId },
|
body: {
|
||||||
|
token: user.getJwtToken(),
|
||||||
|
collection: document.collectionId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
|
|
||||||
|
19
server/migrations/20180808061353-cleanup.js
Normal file
19
server/migrations/20180808061353-cleanup.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
module.exports = {
|
||||||
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.renameColumn('documents', 'atlasId', 'collectionId');
|
||||||
|
await queryInterface.removeColumn('documents', 'private');
|
||||||
|
await queryInterface.addColumn('events', 'documentId', {
|
||||||
|
type: Sequelize.UUID,
|
||||||
|
allowNull: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
down: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.renameColumn('documents', 'collectionId', 'atlasId');
|
||||||
|
await queryInterface.removeColumn('events', 'documentId');
|
||||||
|
await queryInterface.addColumn('documents', 'private', {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -53,7 +53,7 @@ const Collection = sequelize.define(
|
|||||||
// Create intro document if first collection for team
|
// Create intro document if first collection for team
|
||||||
const document = await Document.create({
|
const document = await Document.create({
|
||||||
parentDocumentId: null,
|
parentDocumentId: null,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -78,7 +78,7 @@ const Collection = sequelize.define(
|
|||||||
Collection.associate = models => {
|
Collection.associate = models => {
|
||||||
Collection.hasMany(models.Document, {
|
Collection.hasMany(models.Document, {
|
||||||
as: 'documents',
|
as: 'documents',
|
||||||
foreignKey: 'atlasId',
|
foreignKey: 'collectionId',
|
||||||
onDelete: 'cascade',
|
onDelete: 'cascade',
|
||||||
});
|
});
|
||||||
Collection.belongsTo(models.Team, {
|
Collection.belongsTo(models.Team, {
|
||||||
@ -99,7 +99,7 @@ Collection.associate = models => {
|
|||||||
Collection.addHook('afterDestroy', async model => {
|
Collection.addHook('afterDestroy', async model => {
|
||||||
await Document.destroy({
|
await Document.destroy({
|
||||||
where: {
|
where: {
|
||||||
atlasId: model.id,
|
collectionId: model.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -124,7 +124,7 @@ describe('#updateDocument', () => {
|
|||||||
// Add a child for testing
|
// Add a child for testing
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: document.id,
|
parentDocumentId: document.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -160,7 +160,7 @@ describe('#moveDocument', () => {
|
|||||||
// Add a child for testing
|
// Add a child for testing
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: document.id,
|
parentDocumentId: document.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -195,7 +195,7 @@ describe('#removeDocument', () => {
|
|||||||
// Verify that the document was removed
|
// Verify that the document was removed
|
||||||
const collectionDocuments = await Document.findAndCountAll({
|
const collectionDocuments = await Document.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(collectionDocuments.count).toBe(1);
|
expect(collectionDocuments.count).toBe(1);
|
||||||
@ -207,7 +207,7 @@ describe('#removeDocument', () => {
|
|||||||
// Add a child for testing
|
// Add a child for testing
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: document.id,
|
parentDocumentId: document.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -223,7 +223,7 @@ describe('#removeDocument', () => {
|
|||||||
expect(collection.documentStructure.length).toBe(1);
|
expect(collection.documentStructure.length).toBe(1);
|
||||||
const collectionDocuments = await Document.findAndCountAll({
|
const collectionDocuments = await Document.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(collectionDocuments.count).toBe(1);
|
expect(collectionDocuments.count).toBe(1);
|
||||||
@ -235,7 +235,7 @@ describe('#removeDocument', () => {
|
|||||||
// Add a child for testing
|
// Add a child for testing
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: document.id,
|
parentDocumentId: document.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -257,7 +257,7 @@ describe('#removeDocument', () => {
|
|||||||
|
|
||||||
const collectionDocuments = await Document.findAndCountAll({
|
const collectionDocuments = await Document.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(collectionDocuments.count).toBe(2);
|
expect(collectionDocuments.count).toBe(2);
|
||||||
|
@ -119,7 +119,7 @@ const Document = sequelize.define(
|
|||||||
Document.associate = models => {
|
Document.associate = models => {
|
||||||
Document.belongsTo(models.Collection, {
|
Document.belongsTo(models.Collection, {
|
||||||
as: 'collection',
|
as: 'collection',
|
||||||
foreignKey: 'atlasId',
|
foreignKey: 'collectionId',
|
||||||
onDelete: 'cascade',
|
onDelete: 'cascade',
|
||||||
});
|
});
|
||||||
Document.belongsTo(models.Team, {
|
Document.belongsTo(models.Team, {
|
||||||
@ -266,7 +266,7 @@ Document.searchForUser = async (
|
|||||||
Document.addHook('beforeSave', async model => {
|
Document.addHook('beforeSave', async model => {
|
||||||
if (!model.publishedAt) return;
|
if (!model.publishedAt) return;
|
||||||
|
|
||||||
const collection = await Collection.findById(model.atlasId);
|
const collection = await Collection.findById(model.collectionId);
|
||||||
if (collection.type !== 'atlas') return;
|
if (collection.type !== 'atlas') return;
|
||||||
|
|
||||||
await collection.updateDocument(model);
|
await collection.updateDocument(model);
|
||||||
@ -276,7 +276,7 @@ Document.addHook('beforeSave', async model => {
|
|||||||
Document.addHook('afterCreate', async model => {
|
Document.addHook('afterCreate', async model => {
|
||||||
if (!model.publishedAt) return;
|
if (!model.publishedAt) return;
|
||||||
|
|
||||||
const collection = await Collection.findById(model.atlasId);
|
const collection = await Collection.findById(model.collectionId);
|
||||||
if (collection.type !== 'atlas') return;
|
if (collection.type !== 'atlas') return;
|
||||||
|
|
||||||
await collection.addDocumentToStructure(model);
|
await collection.addDocumentToStructure(model);
|
||||||
@ -295,7 +295,7 @@ Document.addHook('afterDestroy', model =>
|
|||||||
Document.prototype.publish = async function() {
|
Document.prototype.publish = async function() {
|
||||||
if (this.publishedAt) return this.save();
|
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();
|
if (collection.type !== 'atlas') return this.save();
|
||||||
|
|
||||||
await collection.addDocumentToStructure(this);
|
await collection.addDocumentToStructure(this);
|
||||||
|
@ -20,6 +20,10 @@ Event.associate = models => {
|
|||||||
as: 'collection',
|
as: 'collection',
|
||||||
foreignKey: 'collectionId',
|
foreignKey: 'collectionId',
|
||||||
});
|
});
|
||||||
|
Event.belongsTo(models.Collection, {
|
||||||
|
as: 'document',
|
||||||
|
foreignKey: 'documentId',
|
||||||
|
});
|
||||||
Event.belongsTo(models.Team, {
|
Event.belongsTo(models.Team, {
|
||||||
as: 'team',
|
as: 'team',
|
||||||
foreignKey: 'teamId',
|
foreignKey: 'teamId',
|
||||||
|
@ -50,7 +50,7 @@ async function present(ctx: Object, document: Document, options: ?Options) {
|
|||||||
|
|
||||||
if (!options.isPublic) {
|
if (!options.isPublic) {
|
||||||
data.pinned = !!document.pinnedById;
|
data.pinned = !!document.pinnedById;
|
||||||
data.collectionId = document.atlasId;
|
data.collectionId = document.collectionId;
|
||||||
data.createdBy = presentUser(ctx, document.createdBy);
|
data.createdBy = presentUser(ctx, document.createdBy);
|
||||||
data.updatedBy = presentUser(ctx, document.updatedBy);
|
data.updatedBy = presentUser(ctx, document.updatedBy);
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class Slack {
|
|||||||
const integration = await Integration.findOne({
|
const integration = await Integration.findOne({
|
||||||
where: {
|
where: {
|
||||||
teamId: document.teamId,
|
teamId: document.teamId,
|
||||||
collectionId: document.atlasId,
|
collectionId: document.collectionId,
|
||||||
service: 'slack',
|
service: 'slack',
|
||||||
type: 'post',
|
type: 'post',
|
||||||
},
|
},
|
||||||
|
@ -81,9 +81,9 @@ export async function buildDocument(overrides: Object = {}) {
|
|||||||
overrides.userId = user.id;
|
overrides.userId = user.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!overrides.atlasId) {
|
if (!overrides.collectionId) {
|
||||||
const collection = await buildCollection(overrides);
|
const collection = await buildCollection(overrides);
|
||||||
overrides.atlasId = collection.id;
|
overrides.collectionId = collection.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Document.create({
|
return Document.create({
|
||||||
|
@ -65,7 +65,7 @@ const seed = async () => {
|
|||||||
|
|
||||||
const document = await Document.create({
|
const document = await Document.create({
|
||||||
parentDocumentId: null,
|
parentDocumentId: null,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
|
Reference in New Issue
Block a user