@cedarjs/cli-data-migrate 1.0.0-canary.12316 → 1.0.0-canary.12318
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/upHandler.d.ts.map +1 -1
- package/dist/commands/upHandler.js +18 -10
- package/package.json +6 -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 I=Object.create;var D=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var M=(t,r)=>()=>(t&&(r=t(t=0)),r);var U=(t,r,i,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of N(r))!V.call(t,e)&&e!==i&&D(t,e,{get:()=>r[e],enumerable:!(o=L(r,e))||o.enumerable});return t};var p=(t,r,i)=>(i=t!=null?I(R(t)):{},U(r||!t||!t.__esModule?D(i,"default",{value:t,enumerable:!0}):i,t));var n,c,k=M(()=>{"use strict";n=p(require("chalk")),c={error:n.default.bold.red,warning:n.default.hex("#ffa500"),highlight:n.default.hex("#ffa500"),success:n.default.green,info:n.default.grey,bold:n.default.bold,underline:n.default.underline,note:n.default.blue,tip:n.default.green,important:n.default.magenta,caution:n.default.red,link:n.default.hex("#e8e8e8")}});async function P({importDbClientFromDist:t,distPath:r}){let i;if(t){if(!f.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 a=m.default.join(r,"lib"),d=m.default.join(a,"db.js");if(!f.default.existsSync(d)){console.error(`Can't find db.js at ${d}. CedarJS expects the db.js file to be in the ${a} directory`),process.exitCode=1;return}i=(await import(d)).db}else{let a=(0,l.resolveFile)(m.default.join((0,l.getPaths)().api.lib,"db"));if(!a){console.error(`Can't find your db file in ${(0,l.getPaths)().api.lib}`),process.exitCode=1;return}let{mod:d}=await(0,h.bundleRequire)({filepath:a});i=d.db}let o=await W(i);if(!o.length){console.info(c.success(`
|
|
3
|
+
${F}
|
|
4
|
+
`)),process.exitCode=0;return}let e={run:0,skipped:0,error:0},g=o.map(a=>{let d=m.default.basename(a.path,".js");return{title:d,skip(){return e.error>0?(e.skipped++,!0):!1},async task(){try{let{startedAt:u,finishedAt:_}=await G(i,a.path);e.run++,await T(i,{version:a.version,name:d,startedAt:u,finishedAt:_})}catch(u){e.error++,console.error(c.error(`Error in data migration: ${u.message}`))}}}}),s=new E.Listr(g,{renderer:"verbose"});try{await s.run(),await i.$disconnect(),console.log(),A(e),console.log(),e.error&&(process.exitCode=1)}catch{process.exitCode=1,await i.$disconnect(),console.log(),A(e),console.log()}}async function W(t){let r=(0,l.getPaths)().api.dataMigrations;if(!f.default.existsSync(r))return[];let i=f.default.readdirSync(r).filter(s=>["js",".ts"].some(a=>s.endsWith(a))).map(s=>{let[a]=s.split("-");return{version:a,path:m.default.join(r,s)}}),e=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(s=>s.version.toString());return i.filter(({version:s})=>!e.includes(s)).sort(B)}function B(t,r){let i=parseInt(t.version),o=parseInt(r.version);return i>o?1:i<o?-1:0}async function G(t,r){let{mod:i}=await(0,h.bundleRequire)({filepath:r}),o=i.default,e=new Date;return await o({db:t}),{startedAt:e,finishedAt:new Date}}async function T(t,{version:r,name:i,startedAt:o,finishedAt:e}){await t.rW_DataMigration.create({data:{version:r,name:i,startedAt:o,finishedAt:e}})}function A(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 f,m,h,E,l,F,$=M(()=>{"use strict";f=p(require("fs")),m=p(require("path")),h=require("bundle-require"),E=require("listr2"),l=require("@cedarjs/project-config");k();F="No pending data migrations run, already up-to-date."});var b=p(require("path")),j=require("dotenv-defaults"),O=require("yargs/helpers"),S=p(require("yargs/yargs")),y=require("@cedarjs/project-config");var w=p(require("terminal-link")),v=require("@cedarjs/project-config");var x="Run any outstanding Data Migrations against the database";function C(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,v.getPaths)().api.dist}).epilogue(`Also see the ${(0,w.default)("Redwood CLI Reference","https://redwoodjs.com/docs/cli-commands#datamigrate-up")}`)}$();process.env.REDWOOD_ENV_FILES_LOADED||((0,j.config)({path:b.default.join((0,y.getPaths)().base,".env"),defaults:b.default.join((0,y.getPaths)().base,".env.defaults"),multiline:!0}),process.env.REDWOOD_ENV_FILES_LOADED="true");(0,S.default)((0,O.hideBin)(process.argv)).scriptName("data-migrate").command("$0",x,C,P).parse();
|
|
@@ -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,iBAuHtB;AAiFD,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");
|
|
37
38
|
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,7 +43,6 @@ async function handler({
|
|
|
43
43
|
distPath
|
|
44
44
|
}) {
|
|
45
45
|
let db;
|
|
46
|
-
let requireHookRegistered = false;
|
|
47
46
|
if (importDbClientFromDist) {
|
|
48
47
|
if (!import_fs.default.existsSync(distPath)) {
|
|
49
48
|
console.warn(
|
|
@@ -63,9 +62,17 @@ async function handler({
|
|
|
63
62
|
}
|
|
64
63
|
db = (await import(distLibDbPath)).db;
|
|
65
64
|
} else {
|
|
66
|
-
(0,
|
|
67
|
-
|
|
68
|
-
|
|
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;
|
|
69
76
|
}
|
|
70
77
|
const pendingDataMigrations = await getPendingDataMigrations(db);
|
|
71
78
|
if (!pendingDataMigrations.length) {
|
|
@@ -89,9 +96,6 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
|
89
96
|
}
|
|
90
97
|
},
|
|
91
98
|
async task() {
|
|
92
|
-
if (!requireHookRegistered) {
|
|
93
|
-
(0, import_babel_config.registerApiSideBabelHook)();
|
|
94
|
-
}
|
|
95
99
|
try {
|
|
96
100
|
const { startedAt, finishedAt } = await runDataMigration(
|
|
97
101
|
db,
|
|
@@ -174,9 +178,13 @@ function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
|
|
|
174
178
|
return 0;
|
|
175
179
|
}
|
|
176
180
|
async function runDataMigration(db, dataMigrationPath) {
|
|
177
|
-
const
|
|
181
|
+
const { mod } = await (0, import_bundle_require.bundleRequire)({
|
|
182
|
+
filepath: dataMigrationPath
|
|
183
|
+
// TODO: Add plugins
|
|
184
|
+
});
|
|
185
|
+
const dataMigration = mod.default;
|
|
178
186
|
const startedAt = /* @__PURE__ */ new Date();
|
|
179
|
-
await dataMigration
|
|
187
|
+
await dataMigration({ db });
|
|
180
188
|
const finishedAt = /* @__PURE__ */ new Date();
|
|
181
189
|
return { startedAt, finishedAt };
|
|
182
190
|
}
|
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.12318+74d039296",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -25,8 +25,9 @@
|
|
|
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.12318",
|
|
29
|
+
"@cedarjs/project-config": "1.0.0-canary.12318",
|
|
30
|
+
"bundle-require": "^5.1.0",
|
|
30
31
|
"chalk": "4.1.2",
|
|
31
32
|
"dotenv-defaults": "5.0.2",
|
|
32
33
|
"execa": "5.1.1",
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"yargs": "17.7.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@cedarjs/framework-tools": "1.0.0-canary.
|
|
40
|
+
"@cedarjs/framework-tools": "1.0.0-canary.12318",
|
|
40
41
|
"@prisma/client": "5.20.0",
|
|
41
42
|
"@types/fs-extra": "11.0.4",
|
|
42
43
|
"@types/yargs": "17.0.33",
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"tsx": "4.19.4",
|
|
46
47
|
"typescript": "5.6.2"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "74d03929677d47123af04b297d4748e7d125d36e"
|
|
49
50
|
}
|