Check for schema identity before updating it. (#5608)

This commit is contained in:
Oreille
2021-05-11 20:36:33 +02:00
committed by GitHub
parent bc30ee2bde
commit 316ac9076b

View File

@@ -16,6 +16,7 @@ import { Field } from '../types/field';
import getDefaultValue from '../utils/get-default-value';
import getLocalType from '../utils/get-local-type';
import { toArray } from '../utils/to-array';
import { isEqual } from 'lodash';
export type RawField = DeepPartial<Field> & { field: string; type: typeof types[number] };
@@ -255,13 +256,15 @@ export class FieldsService {
if (field.schema) {
const existingColumn = await this.schemaInspector.columnInfo(collection, field.field);
try {
await this.knex.schema.alterTable(collection, (table) => {
if (!field.schema) return;
this.addColumnToTable(table, field, existingColumn);
});
} catch (err) {
throw await translateDatabaseError(err);
if (!isEqual(existingColumn, field.schema)) {
try {
await this.knex.schema.alterTable(collection, (table) => {
if (!field.schema) return;
this.addColumnToTable(table, field, existingColumn);
});
} catch (err) {
throw await translateDatabaseError(err);
}
}
}