Fix upsert of collections meta

This commit is contained in:
rijkvanzanten
2021-04-22 10:28:27 -04:00
parent f873f184f5
commit 1e3b64bf99
2 changed files with 12 additions and 3 deletions

View File

@@ -82,6 +82,7 @@ router.patch(
accountability: req.accountability,
schema: req.schema,
});
await collectionsService.updateOne(req.params.collection, req.body);
try {

View File

@@ -265,9 +265,17 @@ export class CollectionsService {
throw new InvalidPayloadException(`"meta" key is required`);
}
// We upsert the directus_collections row here, as the database itself can already exist, but
// the meta data missing
await collectionItemsService.upsertOne(payload.meta, opts);
const exists = !!(await this.knex
.select('collection')
.from('directus_collections')
.where({ collection: collectionKey })
.first());
if (exists) {
await collectionItemsService.updateOne(collectionKey, payload.meta, opts);
} else {
await collectionItemsService.createOne({ ...payload.meta, collection: collectionKey }, opts);
}
return collectionKey;
}