mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 23:24:03 +00:00
Merge pull request #15609 from strapi/enhancement/add-datatype-diff-type
This commit is contained in:
commit
e73b7873c5
@ -346,7 +346,7 @@ class TransferEngine<
|
||||
keys.forEach((key) => {
|
||||
const sourceSchema = sourceSchemas[key];
|
||||
const destinationSchema = destinationSchemas[key];
|
||||
const schemaDiffs = compareSchemas(destinationSchema, sourceSchema, strategy);
|
||||
const schemaDiffs = compareSchemas(sourceSchema, destinationSchema, strategy);
|
||||
|
||||
if (schemaDiffs.length) {
|
||||
diffs[key] = schemaDiffs;
|
||||
@ -364,15 +364,19 @@ class TransferEngine<
|
||||
const path = diff.path.join('.');
|
||||
|
||||
if (diff.kind === 'added') {
|
||||
return `Added "${path}": "${diff.value}" (${diff.type})`;
|
||||
return `${path} exists in destination schema but not in source schema`;
|
||||
}
|
||||
|
||||
if (diff.kind === 'deleted') {
|
||||
return `Removed "${path}"`;
|
||||
return `${path} exists in source schema but not in destination schema`;
|
||||
}
|
||||
|
||||
if (diff.kind === 'modified') {
|
||||
return `Modified "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
|
||||
if (diff.types[0] === diff.types[1]) {
|
||||
return `Schema value changed at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
|
||||
}
|
||||
|
||||
return `Schema has differing data types at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
|
||||
}
|
||||
|
||||
throw new TransferEngineValidationError(`Invalid diff found for "${uid}"`, {
|
||||
|
||||
@ -38,14 +38,6 @@ export const diff = (a: unknown, b: unknown, ctx: Context = createContext()): Di
|
||||
return diffs;
|
||||
};
|
||||
|
||||
if (aType === 'undefined') {
|
||||
return added();
|
||||
}
|
||||
|
||||
if (bType === 'undefined') {
|
||||
return deleted();
|
||||
}
|
||||
|
||||
if (isArray(a) && isArray(b)) {
|
||||
let k = 0;
|
||||
|
||||
@ -77,6 +69,14 @@ export const diff = (a: unknown, b: unknown, ctx: Context = createContext()): Di
|
||||
}
|
||||
|
||||
if (!isEqual(a, b)) {
|
||||
if (aType === 'undefined') {
|
||||
return added();
|
||||
}
|
||||
|
||||
if (bType === 'undefined') {
|
||||
return deleted();
|
||||
}
|
||||
|
||||
return modified();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user