mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Check for schema identity before updating it. (#5608)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user