sb-mig 5.0.7-beta.2 → 5.0.7-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -188,12 +188,13 @@ export const doTheMigration = async ({ itemType = "story", from, itemsToMigrate,
|
|
|
188
188
|
const notNullMigratedItems = migratedItems.filter((item) => item);
|
|
189
189
|
// Saving result with migrated version of stories into file
|
|
190
190
|
await createAndSaveToFile({
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
datestamp: true,
|
|
192
|
+
ext: "json",
|
|
193
|
+
filename: `${from}---${itemType}-to-migrate`,
|
|
193
194
|
folder: "migrations",
|
|
194
195
|
res: notNullMigratedItems,
|
|
195
196
|
});
|
|
196
|
-
await modifyOrCreateAppliedMigrationsFile(migrationConfig);
|
|
197
|
+
await modifyOrCreateAppliedMigrationsFile(migrationConfig, itemType);
|
|
197
198
|
if (itemType === "story") {
|
|
198
199
|
await managementApi.stories.updateStories({
|
|
199
200
|
stories: notNullMigratedItems,
|
|
@@ -62,13 +62,21 @@ export const migrations = async (props) => {
|
|
|
62
62
|
});
|
|
63
63
|
const whatToMigrate = preselectMigrations(previousBackpackVersion, installedBackpackVersion.replaceAll("^", ""), versionMappingFileContent, alreadyAppliedMigrations);
|
|
64
64
|
console.log("Command you have to run to migrate (the best in that order): ");
|
|
65
|
-
if (whatToMigrate.length > 0) {
|
|
66
|
-
whatToMigrate.forEach((migration) => {
|
|
65
|
+
if (whatToMigrate.story.length > 0) {
|
|
66
|
+
whatToMigrate.story.forEach((migration) => {
|
|
67
67
|
console.log(`yarn sb-mig migrate content --all --migration ${migration} --yes`);
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
console.log("
|
|
71
|
+
console.log("No story to migrate. You are up to date.");
|
|
72
|
+
}
|
|
73
|
+
if (whatToMigrate.preset.length > 0) {
|
|
74
|
+
whatToMigrate.preset.forEach((migration) => {
|
|
75
|
+
console.log(`yarn sb-mig migrate presets --all --migration ${migration} --yes`);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.log("No story to migrate. You are up to date.");
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
82
|
break;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
type MigrationNames = "transitionsOnEnter" | "otherMigration" | "cardsMigration" | "hideToVisibility";
|
|
2
2
|
type VersionMapping = Record<string, MigrationNames[]>;
|
|
3
|
-
export declare const preselectMigrations: (currentVersion: string, installedVersion: string, versionMapping: VersionMapping, alreadyApplied?:
|
|
4
|
-
|
|
3
|
+
export declare const preselectMigrations: (currentVersion: string, installedVersion: string, versionMapping: VersionMapping, alreadyApplied?: {
|
|
4
|
+
story: string[];
|
|
5
|
+
preset: string[];
|
|
6
|
+
}) => {
|
|
7
|
+
story: never[];
|
|
8
|
+
preset: never[];
|
|
9
|
+
};
|
|
10
|
+
export declare const modifyOrCreateAppliedMigrationsFile: (migrationApplied: string, itemType: "story" | "preset") => Promise<void>;
|
|
5
11
|
export {};
|
package/dist/utils/migrations.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createJsonFile, readFile } from "./files.js";
|
|
2
|
-
const versionMapping = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export const preselectMigrations = (currentVersion, installedVersion, versionMapping, alreadyApplied = {
|
|
3
|
+
story: [],
|
|
4
|
+
preset: [],
|
|
5
|
+
}) => {
|
|
6
|
+
const final = {
|
|
7
|
+
story: [],
|
|
8
|
+
preset: [],
|
|
9
|
+
};
|
|
9
10
|
const versionThatApplies = Object.keys(versionMapping).filter((version) => {
|
|
10
11
|
if (version <= installedVersion && version > currentVersion) {
|
|
11
12
|
return version;
|
|
@@ -16,16 +17,28 @@ export const preselectMigrations = (currentVersion, installedVersion, versionMap
|
|
|
16
17
|
});
|
|
17
18
|
versionThatApplies.map((version) => {
|
|
18
19
|
// @ts-ignore
|
|
19
|
-
final.push(versionMapping[version]);
|
|
20
|
+
final.story.push(versionMapping[version]);
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
final.preset.push(versionMapping[version]);
|
|
20
23
|
});
|
|
21
|
-
|
|
24
|
+
if (Array.isArray(alreadyApplied)) {
|
|
25
|
+
alreadyApplied = {
|
|
26
|
+
story: alreadyApplied,
|
|
27
|
+
preset: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const storyFlatted = final.story
|
|
22
31
|
.flatMap((item) => item)
|
|
23
|
-
.filter((migration) => !alreadyApplied.includes(migration));
|
|
32
|
+
.filter((migration) => !alreadyApplied.story.includes(migration));
|
|
33
|
+
const presetFlatted = final.preset
|
|
34
|
+
.flatMap((item) => item)
|
|
35
|
+
.filter((migration) => !alreadyApplied.preset.includes(migration));
|
|
36
|
+
return {
|
|
37
|
+
story: storyFlatted,
|
|
38
|
+
preset: presetFlatted,
|
|
39
|
+
};
|
|
24
40
|
};
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
// const commands = (list: MigrationNames[]) => list.map(migration => `yarn sb-mig migrate content --all --migration ${migration} --yes`);
|
|
28
|
-
export const modifyOrCreateAppliedMigrationsFile = async (migrationApplied) => {
|
|
41
|
+
export const modifyOrCreateAppliedMigrationsFile = async (migrationApplied, itemType) => {
|
|
29
42
|
const fileName = "applied-backpack-migrations.json";
|
|
30
43
|
let alreadyAppliedFileContent;
|
|
31
44
|
let alreadyApplied;
|
|
@@ -36,9 +49,25 @@ export const modifyOrCreateAppliedMigrationsFile = async (migrationApplied) => {
|
|
|
36
49
|
catch (e) {
|
|
37
50
|
console.log(`No file named: ${fileName}`);
|
|
38
51
|
console.log("Will create one now.");
|
|
39
|
-
alreadyApplied =
|
|
52
|
+
alreadyApplied = {
|
|
53
|
+
story: [],
|
|
54
|
+
preset: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(alreadyApplied)) {
|
|
58
|
+
alreadyApplied = {
|
|
59
|
+
story: alreadyApplied,
|
|
60
|
+
preset: [],
|
|
61
|
+
};
|
|
40
62
|
}
|
|
41
|
-
const migrations =
|
|
63
|
+
const migrations = {
|
|
64
|
+
story: itemType === "story"
|
|
65
|
+
? [...new Set([...alreadyApplied.story, migrationApplied])]
|
|
66
|
+
: alreadyApplied.story,
|
|
67
|
+
preset: itemType === "preset"
|
|
68
|
+
? [...new Set([...alreadyApplied.preset, migrationApplied])]
|
|
69
|
+
: alreadyApplied.preset,
|
|
70
|
+
};
|
|
42
71
|
const appliedMigrationsFileContent = JSON.stringify({
|
|
43
72
|
migrations,
|
|
44
73
|
});
|
package/package.json
CHANGED