@cedarjs/cli-data-migrate 1.0.0-canary.12612 → 1.0.0-canary.12615
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.
- package/dist/bin.js +3 -3
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +7 -2
- package/dist/commands/upHandler.d.ts.map +1 -1
- package/dist/commands/upHandler.js +10 -18
- package/dist/commands/upHandlerEsm.d.ts +4 -0
- package/dist/commands/upHandlerEsm.d.ts.map +1 -0
- package/dist/commands/upHandlerEsm.js +220 -0
- package/package.json +5 -5
package/dist/bin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
3
|
-
${
|
|
4
|
-
`)),process.exitCode=0;return}let
|
|
2
|
+
"use strict";var L=Object.create;var w=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var v=(t,r)=>()=>(t&&(r=t(t=0)),r);var W=(t,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of R(r))!V.call(t,a)&&a!==e&&w(t,a,{get:()=>r[a],enumerable:!(i=N(r,a))||i.enumerable});return t};var f=(t,r,e)=>(e=t!=null?L(U(t)):{},W(r||!t||!t.__esModule?w(e,"default",{value:t,enumerable:!0}):e,t));var o,c,C=v(()=>{"use strict";o=f(require("ansis")),c={error:o.default.bold.red,warning:o.default.hex("#ffa500"),highlight:o.default.hex("#ffa500"),success:o.default.green,info:o.default.gray,bold:o.default.bold,underline:o.default.underline,note:o.default.blue,tip:o.default.green,important:o.default.magenta,caution:o.default.red,link:o.default.hex("#e8e8e8")}});async function S({importDbClientFromDist:t,distPath:r}){let e,i=!1;if(t){if(!g.default.existsSync(r)){console.warn(`Can't find api dist at ${r}. You may need to build first: yarn rw build api`),process.exitCode=1;return}let p=m.default.join(r,"lib"),d=m.default.join(p,"db.js");if(!g.default.existsSync(d)){console.error(`Can't find db.js at ${d}. CedarJS expects the db.js file to be in the ${p} directory`),process.exitCode=1;return}e=(await import(d)).db}else(0,b.registerApiSideBabelHook)(),i=!0,e=require(m.default.join((0,y.getPaths)().api.lib,"db")).db;let a=await B(e);if(!a.length){console.info(c.success(`
|
|
3
|
+
${G}
|
|
4
|
+
`)),process.exitCode=0;return}let s={run:0,skipped:0,error:0},n=a.map(p=>{let d=m.default.basename(p.path,".js");return{title:d,skip(){return s.error>0?(s.skipped++,!0):!1},async task(){i||(0,b.registerApiSideBabelHook)();try{let{startedAt:u,finishedAt:I}=await q(e,p.path);s.run++,await J(e,{version:p.version,name:d,startedAt:u,finishedAt:I})}catch(u){s.error++,console.error(c.error(`Error in data migration: ${u.message}`))}}}}),l=new j.Listr(n,{renderer:"verbose"});try{await l.run(),await e.$disconnect(),console.log(),E(s),console.log(),s.error&&(process.exitCode=1)}catch{process.exitCode=1,await e.$disconnect(),console.log(),E(s),console.log()}}async function B(t){let r=(0,y.getPaths)().api.dataMigrations;if(!g.default.existsSync(r))return[];let e=g.default.readdirSync(r).filter(n=>["js",".ts"].some(l=>n.endsWith(l))).map(n=>{let[l]=n.split("-");return{version:l,path:m.default.join(r,n)}}),a=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(n=>n.version.toString());return e.filter(({version:n})=>!a.includes(n)).sort(H)}function H(t,r){let e=parseInt(t.version),i=parseInt(r.version);return e>i?1:e<i?-1:0}async function q(t,r){let e=require(r),i=new Date;return await e.default({db:t}),{startedAt:i,finishedAt:new Date}}async function J(t,{version:r,name:e,startedAt:i,finishedAt:a}){await t.rW_DataMigration.create({data:{version:r,name:e,startedAt:i,finishedAt:a}})}function E(t){t.run&&console.info(c.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(c.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(c.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var g,m,j,b,y,G,O=v(()=>{"use strict";g=f(require("fs")),m=f(require("path")),j=require("listr2"),b=require("@cedarjs/babel-config"),y=require("@cedarjs/project-config");C();G="No pending data migrations run, already up-to-date."});var D=f(require("path")),P=require("dotenv-defaults"),$=require("yargs/helpers"),_=f(require("yargs/yargs")),M=require("@cedarjs/project-config");var x=require("termi-link"),h=require("@cedarjs/project-config");var k="Run any outstanding Data Migrations against the database";function A(t){return t.option("import-db-client-from-dist",{type:"boolean",alias:["db-from-dist"],description:"Import the db client from dist",default:!1}).option("dist-path",{type:"string",alias:"d",description:"Path to the api dist directory",default:(0,h.getPaths)().api.dist}).epilogue(`Also see the ${(0,x.terminalLink)("CedarJS CLI Reference","https://cedarjs.com/docs/cli-commands#datamigrate-up")}`)}O();process.env.REDWOOD_ENV_FILES_LOADED||((0,P.config)({path:D.default.join((0,M.getPaths)().base,".env"),defaults:D.default.join((0,M.getPaths)().base,".env.defaults"),multiline:!0}),process.env.REDWOOD_ENV_FILES_LOADED="true");(0,_.default)((0,$.hideBin)(process.argv)).scriptName("data-migrate").command("$0",k,A,S).parse();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"up.d.ts","sourceRoot":"","sources":["../../src/commands/up.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAIjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD,eAAO,MAAM,OAAO,OAAO,CAAA;AAC3B,eAAO,MAAM,WAAW,6DACoC,CAAA;AAE5D,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAoBzC;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"up.d.ts","sourceRoot":"","sources":["../../src/commands/up.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAIjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD,eAAO,MAAM,OAAO,OAAO,CAAA;AAC3B,eAAO,MAAM,WAAW,6DACoC,CAAA;AAE5D,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAoBzC;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ1E"}
|
package/dist/commands/up.js
CHANGED
|
@@ -57,8 +57,13 @@ function builder(yargs) {
|
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
async function handler(options) {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
if ((0, import_project_config.projectIsEsm)()) {
|
|
61
|
+
const { handler: dataMigrateUpHandler } = await import("./upHandlerEsm.js");
|
|
62
|
+
await dataMigrateUpHandler(options);
|
|
63
|
+
} else {
|
|
64
|
+
const { handler: dataMigrateUpHandler } = await import("./upHandler.js");
|
|
65
|
+
await dataMigrateUpHandler(options);
|
|
66
|
+
}
|
|
62
67
|
}
|
|
63
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
64
69
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upHandler.d.ts","sourceRoot":"","sources":["../../src/commands/upHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,UAAU,CAAA;AAEnE,wBAAsB,OAAO,CAAC,EAC5B,sBAAsB,EACtB,QAAQ,GACT,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"upHandler.d.ts","sourceRoot":"","sources":["../../src/commands/upHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,UAAU,CAAA;AAEnE,wBAAsB,OAAO,CAAC,EAC5B,sBAAsB,EACtB,QAAQ,GACT,EAAE,oBAAoB,iBA2GtB;AA4ED,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
|
|
@@ -34,8 +34,8 @@ __export(upHandler_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(upHandler_exports);
|
|
35
35
|
var import_fs = __toESM(require("fs"));
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
|
-
var import_bundle_require = require("bundle-require");
|
|
38
37
|
var import_listr2 = require("listr2");
|
|
38
|
+
var import_babel_config = require("@cedarjs/babel-config");
|
|
39
39
|
var import_project_config = require("@cedarjs/project-config");
|
|
40
40
|
var import_colors = __toESM(require("../lib/colors"));
|
|
41
41
|
async function handler({
|
|
@@ -43,6 +43,7 @@ async function handler({
|
|
|
43
43
|
distPath
|
|
44
44
|
}) {
|
|
45
45
|
let db;
|
|
46
|
+
let requireHookRegistered = false;
|
|
46
47
|
if (importDbClientFromDist) {
|
|
47
48
|
if (!import_fs.default.existsSync(distPath)) {
|
|
48
49
|
console.warn(
|
|
@@ -62,17 +63,9 @@ async function handler({
|
|
|
62
63
|
}
|
|
63
64
|
db = (await import(distLibDbPath)).db;
|
|
64
65
|
} else {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
process.exitCode = 1;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const { mod } = await (0, import_bundle_require.bundleRequire)({
|
|
72
|
-
filepath: dbPath
|
|
73
|
-
// TODO: Add plugins
|
|
74
|
-
});
|
|
75
|
-
db = mod.db;
|
|
66
|
+
(0, import_babel_config.registerApiSideBabelHook)();
|
|
67
|
+
requireHookRegistered = true;
|
|
68
|
+
db = require(import_path.default.join((0, import_project_config.getPaths)().api.lib, "db")).db;
|
|
76
69
|
}
|
|
77
70
|
const pendingDataMigrations = await getPendingDataMigrations(db);
|
|
78
71
|
if (!pendingDataMigrations.length) {
|
|
@@ -96,6 +89,9 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
|
96
89
|
}
|
|
97
90
|
},
|
|
98
91
|
async task() {
|
|
92
|
+
if (!requireHookRegistered) {
|
|
93
|
+
(0, import_babel_config.registerApiSideBabelHook)();
|
|
94
|
+
}
|
|
99
95
|
try {
|
|
100
96
|
const { startedAt, finishedAt } = await runDataMigration(
|
|
101
97
|
db,
|
|
@@ -178,13 +174,9 @@ function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
|
|
|
178
174
|
return 0;
|
|
179
175
|
}
|
|
180
176
|
async function runDataMigration(db, dataMigrationPath) {
|
|
181
|
-
const
|
|
182
|
-
filepath: dataMigrationPath
|
|
183
|
-
// TODO: Add plugins
|
|
184
|
-
});
|
|
185
|
-
const dataMigration = mod.default;
|
|
177
|
+
const dataMigration = require(dataMigrationPath);
|
|
186
178
|
const startedAt = /* @__PURE__ */ new Date();
|
|
187
|
-
await dataMigration({ db });
|
|
179
|
+
await dataMigration.default({ db });
|
|
188
180
|
const finishedAt = /* @__PURE__ */ new Date();
|
|
189
181
|
return { startedAt, finishedAt };
|
|
190
182
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DataMigrateUpOptions } from '../types';
|
|
2
|
+
export declare function handler({ importDbClientFromDist, distPath, }: DataMigrateUpOptions): Promise<void>;
|
|
3
|
+
export declare const NO_PENDING_MIGRATIONS_MESSAGE = "No pending data migrations run, already up-to-date.";
|
|
4
|
+
//# sourceMappingURL=upHandlerEsm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upHandlerEsm.d.ts","sourceRoot":"","sources":["../../src/commands/upHandlerEsm.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,UAAU,CAAA;AAEnE,wBAAsB,OAAO,CAAC,EAC5B,sBAAsB,EACtB,QAAQ,GACT,EAAE,oBAAoB,iBAuHtB;AAiFD,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var upHandlerEsm_exports = {};
|
|
30
|
+
__export(upHandlerEsm_exports, {
|
|
31
|
+
NO_PENDING_MIGRATIONS_MESSAGE: () => NO_PENDING_MIGRATIONS_MESSAGE,
|
|
32
|
+
handler: () => handler
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(upHandlerEsm_exports);
|
|
35
|
+
var import_fs = __toESM(require("fs"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_bundle_require = require("bundle-require");
|
|
38
|
+
var import_listr2 = require("listr2");
|
|
39
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
40
|
+
var import_colors = __toESM(require("../lib/colors"));
|
|
41
|
+
async function handler({
|
|
42
|
+
importDbClientFromDist,
|
|
43
|
+
distPath
|
|
44
|
+
}) {
|
|
45
|
+
let db;
|
|
46
|
+
if (importDbClientFromDist) {
|
|
47
|
+
if (!import_fs.default.existsSync(distPath)) {
|
|
48
|
+
console.warn(
|
|
49
|
+
`Can't find api dist at ${distPath}. You may need to build first: yarn rw build api`
|
|
50
|
+
);
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const distLibPath = import_path.default.join(distPath, "lib");
|
|
55
|
+
const distLibDbPath = import_path.default.join(distLibPath, "db.js");
|
|
56
|
+
if (!import_fs.default.existsSync(distLibDbPath)) {
|
|
57
|
+
console.error(
|
|
58
|
+
`Can't find db.js at ${distLibDbPath}. CedarJS expects the db.js file to be in the ${distLibPath} directory`
|
|
59
|
+
);
|
|
60
|
+
process.exitCode = 1;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
db = (await import(distLibDbPath)).db;
|
|
64
|
+
} else {
|
|
65
|
+
const dbPath = (0, import_project_config.resolveFile)(import_path.default.join((0, import_project_config.getPaths)().api.lib, "db"));
|
|
66
|
+
if (!dbPath) {
|
|
67
|
+
console.error(`Can't find your db file in ${(0, import_project_config.getPaths)().api.lib}`);
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const { mod } = await (0, import_bundle_require.bundleRequire)({
|
|
72
|
+
filepath: dbPath
|
|
73
|
+
// TODO: Add plugins
|
|
74
|
+
});
|
|
75
|
+
db = mod.db;
|
|
76
|
+
}
|
|
77
|
+
const pendingDataMigrations = await getPendingDataMigrations(db);
|
|
78
|
+
if (!pendingDataMigrations.length) {
|
|
79
|
+
console.info(import_colors.default.success(`
|
|
80
|
+
${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
81
|
+
`));
|
|
82
|
+
process.exitCode = 0;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const counters = { run: 0, skipped: 0, error: 0 };
|
|
86
|
+
const dataMigrationTasks = pendingDataMigrations.map((dataMigration) => {
|
|
87
|
+
const dataMigrationName = import_path.default.basename(dataMigration.path, ".js");
|
|
88
|
+
return {
|
|
89
|
+
title: dataMigrationName,
|
|
90
|
+
skip() {
|
|
91
|
+
if (counters.error > 0) {
|
|
92
|
+
counters.skipped++;
|
|
93
|
+
return true;
|
|
94
|
+
} else {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
async task() {
|
|
99
|
+
try {
|
|
100
|
+
const { startedAt, finishedAt } = await runDataMigration(
|
|
101
|
+
db,
|
|
102
|
+
dataMigration.path
|
|
103
|
+
);
|
|
104
|
+
counters.run++;
|
|
105
|
+
await recordDataMigration(db, {
|
|
106
|
+
version: dataMigration.version,
|
|
107
|
+
name: dataMigrationName,
|
|
108
|
+
startedAt,
|
|
109
|
+
finishedAt
|
|
110
|
+
});
|
|
111
|
+
} catch (e) {
|
|
112
|
+
counters.error++;
|
|
113
|
+
console.error(
|
|
114
|
+
import_colors.default.error(`Error in data migration: ${e.message}`)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
const tasks = new import_listr2.Listr(dataMigrationTasks, {
|
|
121
|
+
renderer: "verbose"
|
|
122
|
+
});
|
|
123
|
+
try {
|
|
124
|
+
await tasks.run();
|
|
125
|
+
await db.$disconnect();
|
|
126
|
+
console.log();
|
|
127
|
+
reportDataMigrations(counters);
|
|
128
|
+
console.log();
|
|
129
|
+
if (counters.error) {
|
|
130
|
+
process.exitCode = 1;
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
process.exitCode = 1;
|
|
134
|
+
await db.$disconnect();
|
|
135
|
+
console.log();
|
|
136
|
+
reportDataMigrations(counters);
|
|
137
|
+
console.log();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function getPendingDataMigrations(db) {
|
|
141
|
+
const dataMigrationsPath = (0, import_project_config.getPaths)().api.dataMigrations;
|
|
142
|
+
if (!import_fs.default.existsSync(dataMigrationsPath)) {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
const dataMigrations = import_fs.default.readdirSync(dataMigrationsPath).filter(
|
|
146
|
+
(dataMigrationFileName) => ["js", ".ts"].some(
|
|
147
|
+
(extension) => dataMigrationFileName.endsWith(extension)
|
|
148
|
+
)
|
|
149
|
+
).map((dataMigrationFileName) => {
|
|
150
|
+
const [version] = dataMigrationFileName.split("-");
|
|
151
|
+
return {
|
|
152
|
+
version,
|
|
153
|
+
path: import_path.default.join(dataMigrationsPath, dataMigrationFileName)
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
const ranDataMigrations = await db.rW_DataMigration.findMany(
|
|
157
|
+
{
|
|
158
|
+
orderBy: { version: "asc" }
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
const ranDataMigrationVersions = ranDataMigrations.map(
|
|
162
|
+
(dataMigration) => dataMigration.version.toString()
|
|
163
|
+
);
|
|
164
|
+
const pendingDataMigrations = dataMigrations.filter(({ version }) => {
|
|
165
|
+
return !ranDataMigrationVersions.includes(version);
|
|
166
|
+
}).sort(sortDataMigrationsByVersion);
|
|
167
|
+
return pendingDataMigrations;
|
|
168
|
+
}
|
|
169
|
+
function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
|
|
170
|
+
const aVersion = parseInt(dataMigrationA.version);
|
|
171
|
+
const bVersion = parseInt(dataMigrationB.version);
|
|
172
|
+
if (aVersion > bVersion) {
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
if (aVersion < bVersion) {
|
|
176
|
+
return -1;
|
|
177
|
+
}
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
async function runDataMigration(db, dataMigrationPath) {
|
|
181
|
+
const { mod } = await (0, import_bundle_require.bundleRequire)({
|
|
182
|
+
filepath: dataMigrationPath
|
|
183
|
+
// TODO: Add plugins
|
|
184
|
+
});
|
|
185
|
+
const dataMigration = mod.default;
|
|
186
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
187
|
+
await dataMigration({ db });
|
|
188
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
189
|
+
return { startedAt, finishedAt };
|
|
190
|
+
}
|
|
191
|
+
const NO_PENDING_MIGRATIONS_MESSAGE = "No pending data migrations run, already up-to-date.";
|
|
192
|
+
async function recordDataMigration(db, { version, name, startedAt, finishedAt }) {
|
|
193
|
+
await db.rW_DataMigration.create({
|
|
194
|
+
data: { version, name, startedAt, finishedAt }
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function reportDataMigrations(counters) {
|
|
198
|
+
if (counters.run) {
|
|
199
|
+
console.info(
|
|
200
|
+
import_colors.default.success(`${counters.run} data migration(s) completed successfully.`)
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
if (counters.error) {
|
|
204
|
+
console.error(
|
|
205
|
+
import_colors.default.error(`${counters.error} data migration(s) exited with errors.`)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
if (counters.skipped) {
|
|
209
|
+
console.warn(
|
|
210
|
+
import_colors.default.warning(
|
|
211
|
+
`${counters.skipped} data migration(s) skipped due to previous error.`
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
+
0 && (module.exports = {
|
|
218
|
+
NO_PENDING_MIGRATIONS_MESSAGE,
|
|
219
|
+
handler
|
|
220
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli-data-migrate",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.12615+59790336c",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"test:unit": "yarn jest src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@cedarjs/babel-config": "1.0.0-canary.
|
|
29
|
-
"@cedarjs/project-config": "1.0.0-canary.
|
|
28
|
+
"@cedarjs/babel-config": "1.0.0-canary.12615",
|
|
29
|
+
"@cedarjs/project-config": "1.0.0-canary.12615",
|
|
30
30
|
"ansis": "4.1.0",
|
|
31
31
|
"bundle-require": "^5.1.0",
|
|
32
32
|
"dotenv-defaults": "5.0.2",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"yargs": "17.7.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@cedarjs/framework-tools": "1.0.0-canary.
|
|
40
|
+
"@cedarjs/framework-tools": "1.0.0-canary.12615",
|
|
41
41
|
"@prisma/client": "5.20.0",
|
|
42
42
|
"@types/fs-extra": "11.0.4",
|
|
43
43
|
"@types/yargs": "17.0.33",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"tsx": "4.20.4",
|
|
47
47
|
"typescript": "5.6.2"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "59790336c230f7ed586328093973ab67a923b2f3"
|
|
50
50
|
}
|