@cedarjs/cli-data-migrate 0.1.1 → 0.2.0
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var L=Object.create;var M=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var w=(t,r)=>()=>(t&&(r=t(t=0)),r);var W=(t,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of R(r))!U.call(t,o)&&o!==e&&M(t,o,{get:()=>r[o],enumerable:!(i=N(r,o))||i.enumerable});return t};var
|
|
3
|
-
${
|
|
4
|
-
`)),process.exitCode=0;return}let s={run:0,skipped:0,error:0},n=o.map(p=>{let
|
|
2
|
+
"use strict";var L=Object.create;var M=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var w=(t,r)=>()=>(t&&(r=t(t=0)),r);var W=(t,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of R(r))!U.call(t,o)&&o!==e&&M(t,o,{get:()=>r[o],enumerable:!(i=N(r,o))||i.enumerable});return t};var l=(t,r,e)=>(e=t!=null?L(V(t)):{},W(r||!t||!t.__esModule?M(e,"default",{value:t,enumerable:!0}):e,t));var a,c,C=w(()=>{"use strict";a=l(require("chalk")),c={error:a.default.bold.red,warning:a.default.hex("#ffa500"),highlight:a.default.hex("#ffa500"),success:a.default.green,info:a.default.grey,bold:a.default.bold,underline:a.default.underline,note:a.default.blue,tip:a.default.green,important:a.default.magenta,caution:a.default.red,link:a.default.hex("#e8e8e8")}});async function O({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,h.registerApiSideBabelHook)(),i=!0,e=require(m.default.join((0,b.getPaths)().api.lib,"db")).db;let o=await B(e);if(!o.length){console.info(c.success(`
|
|
3
|
+
${H}
|
|
4
|
+
`)),process.exitCode=0;return}let s={run:0,skipped:0,error:0},n=o.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,h.registerApiSideBabelHook)();try{let{startedAt:u,finishedAt:I}=await G(e,p.path);s.run++,await T(e,{version:p.version,name:d,startedAt:u,finishedAt:I})}catch(u){s.error++,console.error(c.error(`Error in data migration: ${u.message}`))}}}}),f=new j.Listr(n,{renderer:"verbose"});try{await f.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,b.getPaths)().api.dataMigrations;if(!g.default.existsSync(r))return[];let e=g.default.readdirSync(r).filter(n=>["js",".ts"].some(f=>n.endsWith(f))).map(n=>{let[f]=n.split("-");return{version:f,path:m.default.join(r,n)}}),o=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(n=>n.version.toString());return e.filter(({version:n})=>!o.includes(n)).sort(q)}function q(t,r){let e=parseInt(t.version),i=parseInt(r.version);return e>i?1:e<i?-1:0}async function G(t,r){let e=require(r),i=new Date;return await e.default({db:t}),{startedAt:i,finishedAt:new Date}}async function T(t,{version:r,name:e,startedAt:i,finishedAt:o}){await t.rW_DataMigration.create({data:{version:r,name:e,startedAt:i,finishedAt:o}})}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,h,b,H,P=w(()=>{"use strict";g=l(require("fs")),m=l(require("path")),j=require("listr2"),h=require("@cedarjs/babel-config"),b=require("@cedarjs/project-config");C();H="No pending data migrations run, already up-to-date."});var y=l(require("path")),S=require("dotenv-defaults"),$=require("yargs/helpers"),_=l(require("yargs/yargs")),D=require("@cedarjs/project-config");var v=require("termi-link"),x=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,x.getPaths)().api.dist}).epilogue(`Also see the ${(0,v.terminalLink)("Redwood CLI Reference","https://redwoodjs.com/docs/cli-commands#datamigrate-up")}`)}P();process.env.REDWOOD_ENV_FILES_LOADED||((0,S.config)({path:y.default.join((0,D.getPaths)().base,".env"),defaults:y.default.join((0,D.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,O).parse();
|
package/dist/commands/install.js
CHANGED
|
@@ -34,12 +34,12 @@ __export(install_exports, {
|
|
|
34
34
|
handler: () => handler
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(install_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_termi_link = require("termi-link");
|
|
38
38
|
const command = "install";
|
|
39
39
|
const description = "Add the RW_DataMigration model to your schema";
|
|
40
40
|
function builder(yargs) {
|
|
41
41
|
return yargs.epilogue(
|
|
42
|
-
`Also see the ${(0,
|
|
42
|
+
`Also see the ${(0, import_termi_link.terminalLink)(
|
|
43
43
|
"Redwood CLI Reference",
|
|
44
44
|
"https://redwoodjs.com/docs/cli-commands#datamigrate-install"
|
|
45
45
|
)}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installHandler.d.ts","sourceRoot":"","sources":["../../src/commands/installHandler.ts"],"names":[],"mappings":"AAUA,wBAAsB,OAAO,
|
|
1
|
+
{"version":3,"file":"installHandler.d.ts","sourceRoot":"","sources":["../../src/commands/installHandler.ts"],"names":[],"mappings":"AAUA,wBAAsB,OAAO,kBAmD5B;AAED,eAAO,MAAM,uBAAuB,8HAMlC,CAAA;AAEF,eAAO,MAAM,8BAA8B,2EAC+B,CAAA;AAE1E,eAAO,MAAM,KAAK,QAMN,CAAA"}
|
|
@@ -34,9 +34,9 @@ __export(installHandler_exports, {
|
|
|
34
34
|
notes: () => notes
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(installHandler_exports);
|
|
37
|
-
var
|
|
38
|
-
var import_node_path = __toESM(require("node:path"));
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
39
38
|
var import_execa = __toESM(require("execa"));
|
|
39
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
40
40
|
var import_listr2 = require("listr2");
|
|
41
41
|
var import_project_config = require("@cedarjs/project-config");
|
|
42
42
|
var import_colors = __toESM(require("../lib/colors"));
|
|
@@ -47,11 +47,8 @@ async function handler() {
|
|
|
47
47
|
{
|
|
48
48
|
title: "Creating the dataMigrations directory...",
|
|
49
49
|
task() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
import_node_fs.default.writeFileSync(
|
|
54
|
-
import_node_path.default.join(redwoodProjectPaths.api.dataMigrations, ".keep"),
|
|
50
|
+
import_fs_extra.default.outputFileSync(
|
|
51
|
+
import_path.default.join(redwoodProjectPaths.api.dataMigrations, ".keep"),
|
|
55
52
|
""
|
|
56
53
|
);
|
|
57
54
|
}
|
|
@@ -60,8 +57,8 @@ async function handler() {
|
|
|
60
57
|
title: "Adding the RW_DataMigration model to schema.prisma...",
|
|
61
58
|
task() {
|
|
62
59
|
const dbSchemaFilePath = redwoodProjectPaths.api.dbSchema;
|
|
63
|
-
const dbSchemaFileContent =
|
|
64
|
-
|
|
60
|
+
const dbSchemaFileContent = import_fs_extra.default.readFileSync(dbSchemaFilePath, "utf-8");
|
|
61
|
+
import_fs_extra.default.writeFileSync(
|
|
65
62
|
dbSchemaFilePath,
|
|
66
63
|
[dbSchemaFileContent.trim(), "", RW_DATA_MIGRATION_MODEL, ""].join(
|
|
67
64
|
"\n"
|
package/dist/commands/up.js
CHANGED
|
@@ -34,7 +34,7 @@ __export(up_exports, {
|
|
|
34
34
|
handler: () => handler
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(up_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_termi_link = require("termi-link");
|
|
38
38
|
var import_project_config = require("@cedarjs/project-config");
|
|
39
39
|
const command = "up";
|
|
40
40
|
const description = "Run any outstanding Data Migrations against the database";
|
|
@@ -50,7 +50,7 @@ function builder(yargs) {
|
|
|
50
50
|
description: "Path to the api dist directory",
|
|
51
51
|
default: (0, import_project_config.getPaths)().api.dist
|
|
52
52
|
}).epilogue(
|
|
53
|
-
`Also see the ${(0,
|
|
53
|
+
`Also see the ${(0, import_termi_link.terminalLink)(
|
|
54
54
|
"Redwood CLI Reference",
|
|
55
55
|
"https://redwoodjs.com/docs/cli-commands#datamigrate-up"
|
|
56
56
|
)}`
|
|
@@ -52,13 +52,11 @@ async function handler({
|
|
|
52
52
|
process.exitCode = 1;
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
const
|
|
55
|
+
const distLibPath = import_path.default.join(distPath, "lib");
|
|
56
|
+
const distLibDbPath = import_path.default.join(distLibPath, "db.js");
|
|
56
57
|
if (!import_fs.default.existsSync(distLibDbPath)) {
|
|
57
58
|
console.error(
|
|
58
|
-
`Can't find db.js at ${distLibDbPath}.
|
|
59
|
-
distPath,
|
|
60
|
-
"lib"
|
|
61
|
-
)} directory`
|
|
59
|
+
`Can't find db.js at ${distLibDbPath}. CedarJS expects the db.js file to be in the ${distLibPath} directory`
|
|
62
60
|
);
|
|
63
61
|
process.exitCode = 1;
|
|
64
62
|
return;
|
|
@@ -176,7 +174,7 @@ function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
|
|
|
176
174
|
return 0;
|
|
177
175
|
}
|
|
178
176
|
async function runDataMigration(db, dataMigrationPath) {
|
|
179
|
-
const dataMigration =
|
|
177
|
+
const dataMigration = require(dataMigrationPath);
|
|
180
178
|
const startedAt = /* @__PURE__ */ new Date();
|
|
181
179
|
await dataMigration.default({ db });
|
|
182
180
|
const finishedAt = /* @__PURE__ */ new Date();
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,21 +15,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var index_exports = {};
|
|
30
20
|
__export(index_exports, {
|
|
31
21
|
commands: () => commands
|
|
32
22
|
});
|
|
33
23
|
module.exports = __toCommonJS(index_exports);
|
|
34
|
-
var
|
|
24
|
+
var import_termi_link = require("termi-link");
|
|
35
25
|
var import_install = require("./commands/install");
|
|
36
26
|
var import_up = require("./commands/up");
|
|
37
27
|
const command = "data-migrate <command>";
|
|
@@ -39,7 +29,7 @@ const aliases = ["dataMigrate", "dm"];
|
|
|
39
29
|
const description = "Migrate the data in your database";
|
|
40
30
|
function builder(yargs) {
|
|
41
31
|
yargs.command(import_install.command, import_install.description, import_install.builder, import_install.handler).command(import_up.command, import_up.description, import_up.builder, import_up.handler).epilogue(
|
|
42
|
-
`Also see the ${(0,
|
|
32
|
+
`Also see the ${(0, import_termi_link.terminalLink)(
|
|
43
33
|
"Redwood CLI Reference",
|
|
44
34
|
"https://redwoodjs.com/docs/cli-commands#datamigrate"
|
|
45
35
|
)}`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli-data-migrate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -21,32 +21,32 @@
|
|
|
21
21
|
"build:types": "tsc --build --verbose",
|
|
22
22
|
"prepublishOnly": "NODE_ENV=production yarn build",
|
|
23
23
|
"test": "yarn test:unit && yarn test:dist",
|
|
24
|
-
"test:dist": "yarn
|
|
25
|
-
"test:unit": "yarn
|
|
24
|
+
"test:dist": "yarn jest ./dist.test.ts",
|
|
25
|
+
"test:unit": "yarn jest src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@cedarjs/babel-config": "0.
|
|
29
|
-
"@cedarjs/project-config": "0.
|
|
28
|
+
"@cedarjs/babel-config": "0.2.0",
|
|
29
|
+
"@cedarjs/project-config": "0.2.0",
|
|
30
30
|
"chalk": "4.1.2",
|
|
31
31
|
"dotenv-defaults": "5.0.2",
|
|
32
32
|
"execa": "5.1.1",
|
|
33
33
|
"fs-extra": "11.2.0",
|
|
34
34
|
"listr2": "7.0.2",
|
|
35
|
-
"
|
|
35
|
+
"termi-link": "1.1.0",
|
|
36
36
|
"yargs": "17.7.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@cedarjs/framework-tools": "0.
|
|
39
|
+
"@cedarjs/framework-tools": "0.2.0",
|
|
40
40
|
"@prisma/client": "5.20.0",
|
|
41
41
|
"@types/fs-extra": "11.0.4",
|
|
42
42
|
"@types/yargs": "17.0.33",
|
|
43
|
+
"jest": "29.7.0",
|
|
43
44
|
"memfs": "4.17.2",
|
|
44
|
-
"tsx": "4.19.
|
|
45
|
-
"typescript": "5.6.2"
|
|
46
|
-
"vitest": "2.1.9"
|
|
45
|
+
"tsx": "4.19.4",
|
|
46
|
+
"typescript": "5.6.2"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "568c8f994789688a43c5f57181505d7461417b0f"
|
|
52
52
|
}
|