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;
|
||||
let where = { teamId: user.teamId };
|
||||
if (collection) where = { ...where, atlasId: collection };
|
||||
if (collection) where = { ...where, collectionId: collection };
|
||||
|
||||
const starredScope = { method: ['withStarred', user.id] };
|
||||
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({
|
||||
where: {
|
||||
teamId: user.teamId,
|
||||
atlasId: collection,
|
||||
collectionId: collection,
|
||||
pinnedById: {
|
||||
// $FlowFixMe
|
||||
[Op.ne]: null,
|
||||
@ -329,7 +329,7 @@ router.post('documents.create', auth(), async ctx => {
|
||||
parentDocumentObj = await Document.findOne({
|
||||
where: {
|
||||
id: parentDocument,
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
},
|
||||
});
|
||||
authorize(user, 'read', parentDocumentObj);
|
||||
@ -337,7 +337,7 @@ router.post('documents.create', auth(), async ctx => {
|
||||
|
||||
let document = await Document.create({
|
||||
parentDocumentId: parentDocumentObj.id,
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
lastModifiedById: user.id,
|
||||
|
@ -155,7 +155,10 @@ describe('#documents.list', async () => {
|
||||
it('should allow filtering by collection', async () => {
|
||||
const { user, document } = await seed();
|
||||
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();
|
||||
|
||||
|
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
|
||||
const document = await Document.create({
|
||||
parentDocumentId: null,
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
@ -78,7 +78,7 @@ const Collection = sequelize.define(
|
||||
Collection.associate = models => {
|
||||
Collection.hasMany(models.Document, {
|
||||
as: 'documents',
|
||||
foreignKey: 'atlasId',
|
||||
foreignKey: 'collectionId',
|
||||
onDelete: 'cascade',
|
||||
});
|
||||
Collection.belongsTo(models.Team, {
|
||||
@ -99,7 +99,7 @@ Collection.associate = models => {
|
||||
Collection.addHook('afterDestroy', async model => {
|
||||
await Document.destroy({
|
||||
where: {
|
||||
atlasId: model.id,
|
||||
collectionId: model.id,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
@ -124,7 +124,7 @@ describe('#updateDocument', () => {
|
||||
// Add a child for testing
|
||||
const newDocument = await Document.create({
|
||||
parentDocumentId: document.id,
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
@ -160,7 +160,7 @@ describe('#moveDocument', () => {
|
||||
// Add a child for testing
|
||||
const newDocument = await Document.create({
|
||||
parentDocumentId: document.id,
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
@ -195,7 +195,7 @@ describe('#removeDocument', () => {
|
||||
// Verify that the document was removed
|
||||
const collectionDocuments = await Document.findAndCountAll({
|
||||
where: {
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
},
|
||||
});
|
||||
expect(collectionDocuments.count).toBe(1);
|
||||
@ -207,7 +207,7 @@ describe('#removeDocument', () => {
|
||||
// Add a child for testing
|
||||
const newDocument = await Document.create({
|
||||
parentDocumentId: document.id,
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
@ -223,7 +223,7 @@ describe('#removeDocument', () => {
|
||||
expect(collection.documentStructure.length).toBe(1);
|
||||
const collectionDocuments = await Document.findAndCountAll({
|
||||
where: {
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
},
|
||||
});
|
||||
expect(collectionDocuments.count).toBe(1);
|
||||
@ -235,7 +235,7 @@ describe('#removeDocument', () => {
|
||||
// Add a child for testing
|
||||
const newDocument = await Document.create({
|
||||
parentDocumentId: document.id,
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
@ -257,7 +257,7 @@ describe('#removeDocument', () => {
|
||||
|
||||
const collectionDocuments = await Document.findAndCountAll({
|
||||
where: {
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
},
|
||||
});
|
||||
expect(collectionDocuments.count).toBe(2);
|
||||
|
@ -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);
|
||||
|
@ -20,6 +20,10 @@ Event.associate = models => {
|
||||
as: 'collection',
|
||||
foreignKey: 'collectionId',
|
||||
});
|
||||
Event.belongsTo(models.Collection, {
|
||||
as: 'document',
|
||||
foreignKey: 'documentId',
|
||||
});
|
||||
Event.belongsTo(models.Team, {
|
||||
as: 'team',
|
||||
foreignKey: 'teamId',
|
||||
|
@ -50,7 +50,7 @@ async function present(ctx: Object, document: Document, options: ?Options) {
|
||||
|
||||
if (!options.isPublic) {
|
||||
data.pinned = !!document.pinnedById;
|
||||
data.collectionId = document.atlasId;
|
||||
data.collectionId = document.collectionId;
|
||||
data.createdBy = presentUser(ctx, document.createdBy);
|
||||
data.updatedBy = presentUser(ctx, document.updatedBy);
|
||||
|
||||
|
@ -63,7 +63,7 @@ class Slack {
|
||||
const integration = await Integration.findOne({
|
||||
where: {
|
||||
teamId: document.teamId,
|
||||
collectionId: document.atlasId,
|
||||
collectionId: document.collectionId,
|
||||
service: 'slack',
|
||||
type: 'post',
|
||||
},
|
||||
|
@ -81,9 +81,9 @@ export async function buildDocument(overrides: Object = {}) {
|
||||
overrides.userId = user.id;
|
||||
}
|
||||
|
||||
if (!overrides.atlasId) {
|
||||
if (!overrides.collectionId) {
|
||||
const collection = await buildCollection(overrides);
|
||||
overrides.atlasId = collection.id;
|
||||
overrides.collectionId = collection.id;
|
||||
}
|
||||
|
||||
return Document.create({
|
||||
|
@ -65,7 +65,7 @@ const seed = async () => {
|
||||
|
||||
const document = await Document.create({
|
||||
parentDocumentId: null,
|
||||
atlasId: collection.id,
|
||||
collectionId: collection.id,
|
||||
teamId: team.id,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
|
Reference in New Issue
Block a user