Fix schema apply for changes in field meta options & display_options (#12712)

* Fix schema apply for changes in field meta options

* take display_options into account

* check changes in meta in general
This commit is contained in:
Azri Kahar
2022-04-16 01:27:47 +08:00
committed by GitHub
parent 763a993bca
commit 953eb99eb3
2 changed files with 19 additions and 8 deletions

View File

@@ -8,7 +8,7 @@ import logger from '../../../logger';
import { Snapshot } from '../../../types';
import { getSnapshot } from '../../../utils/get-snapshot';
import { getSnapshotDiff } from '../../../utils/get-snapshot-diff';
import { applySnapshot } from '../../../utils/apply-snapshot';
import { applySnapshot, isNestedMetaUpdate } from '../../../utils/apply-snapshot';
import { flushCaches } from '../../../cache';
export async function apply(snapshotPath: string, options?: { yes: boolean; dryRun: boolean }): Promise<void> {
@@ -82,13 +82,17 @@ export async function apply(snapshotPath: string, options?: { yes: boolean; dryR
message += '\n\n' + chalk.black.underline.bold('Fields:');
for (const { collection, field, diff } of snapshotDiff.fields) {
if (diff[0]?.kind === 'E') {
if (diff[0]?.kind === 'E' || isNestedMetaUpdate(diff[0])) {
message += `\n - ${chalk.blue('Update')} ${collection}.${field}`;
for (const change of diff) {
const path = change.path!.slice(1).join('.');
if (change.kind === 'E') {
const path = change.path!.slice(1).join('.');
message += `\n - Set ${path} to ${change.rhs}`;
} else if (change.kind === 'D') {
message += `\n - Remove ${path}`;
} else if (change.kind === 'N') {
message += `\n - Add ${path} and set it to ${change.rhs}`;
}
}
} else if (diff[0]?.kind === 'D') {