feat: add user-defined schema and migrations (#7418)
This commit is contained in:
committed by
GitHub
parent
653d25731f
commit
25d5c30be2
@@ -212,7 +212,7 @@ class MongoSchemaCollection {
|
||||
.then(
|
||||
schema => {
|
||||
// If a field with this name already exists, it will be handled elsewhere.
|
||||
if (schema.fields[fieldName] != undefined) {
|
||||
if (schema.fields[fieldName] !== undefined) {
|
||||
return;
|
||||
}
|
||||
// The schema exists. Check for existing GeoPoints.
|
||||
@@ -274,6 +274,22 @@ class MongoSchemaCollection {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async updateFieldOptions(className: string, fieldName: string, fieldType: any) {
|
||||
const { ...fieldOptions } = fieldType;
|
||||
delete fieldOptions.type;
|
||||
delete fieldOptions.targetClass;
|
||||
|
||||
await this.upsertSchema(
|
||||
className,
|
||||
{ [fieldName]: { $exists: true } },
|
||||
{
|
||||
$set: {
|
||||
[`_metadata.fields_options.${fieldName}`]: fieldOptions,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Exported for testing reasons and because we haven't moved all mongo schema format
|
||||
|
||||
@@ -362,6 +362,11 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
async updateFieldOptions(className: string, fieldName: string, type: any) {
|
||||
const schemaCollection = await this._schemaCollection();
|
||||
await schemaCollection.updateFieldOptions(className, fieldName, type);
|
||||
}
|
||||
|
||||
addFieldIfNotExists(className: string, fieldName: string, type: any): Promise<void> {
|
||||
return this._schemaCollection()
|
||||
.then(schemaCollection => schemaCollection.addFieldIfNotExists(className, fieldName, type))
|
||||
|
||||
Reference in New Issue
Block a user