@cedarjs/cli-data-migrate 1.1.0 → 1.1.1-next.18
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 +2 -2
- package/dist/commands/installHandler.d.ts.map +1 -1
- package/dist/commands/installHandler.js +8 -11
- package/dist/commands/upHandler.d.ts.map +1 -1
- package/dist/commands/upHandler.js +3 -1
- package/dist/commands/upHandlerEsm.d.ts.map +1 -1
- package/dist/commands/upHandlerEsm.js +3 -1
- package/package.json +6 -6
package/dist/bin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
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
|
|
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,i,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of R(r))!V.call(t,a)&&a!==i&&w(t,a,{get:()=>r[a],enumerable:!(e=N(r,a))||e.enumerable});return t};var l=(t,r,i)=>(i=t!=null?L(U(t)):{},W(r||!t||!t.__esModule?w(i,"default",{value:t,enumerable:!0}):i,t));var o,c,A=v(()=>{"use strict";o=l(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 P({importDbClientFromDist:t,distPath:r}){let i,e=!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}i=(await import(d)).db}else(0,y.registerApiSideBabelHook)(),e=!0,i=require(m.default.join((0,u.getPaths)().api.lib,"db")).db;let a=await B(i);if(!a.length){console.info(c.success(`
|
|
3
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(){
|
|
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(){e||(0,y.registerApiSideBabelHook)();try{let{startedAt:h,finishedAt:I}=await q(i,p.path);s.run++,await J(i,{version:p.version,name:d,startedAt:h,finishedAt:I})}catch(h){s.error++,console.error(c.error(`Error in data migration: ${h.message}`))}}}}),f=new j.Listr(n,{renderer:"verbose"});try{await f.run(),await i.$disconnect(),console.log(),E(s),console.log(),s.error&&(process.exitCode=1)}catch{process.exitCode=1,await i.$disconnect(),console.log(),E(s),console.log()}}async function B(t){let r=await(0,u.getDataMigrationsPath)((0,u.getPaths)().api.prismaConfig);if(!g.default.existsSync(r))return[];let i=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)}}),a=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(n=>n.version.toString());return i.filter(({version:n})=>!a.includes(n)).sort(H)}function H(t,r){let i=parseInt(t.version),e=parseInt(r.version);return i>e?1:i<e?-1:0}async function q(t,r){let i=require(r),e=new Date;return await i.default({db:t}),{startedAt:e,finishedAt:new Date}}async function J(t,{version:r,name:i,startedAt:e,finishedAt:a}){await t.rW_DataMigration.create({data:{version:r,name:i,startedAt:e,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,y,u,G,S=v(()=>{"use strict";g=l(require("node:fs")),m=l(require("node:path")),j=require("listr2"),y=require("@cedarjs/babel-config"),u=require("@cedarjs/project-config");A();G="No pending data migrations run, already up-to-date."});var D=l(require("path")),O=require("dotenv-defaults"),$=require("yargs/helpers"),_=l(require("yargs/yargs")),M=require("@cedarjs/project-config");var x=require("termi-link"),b=require("@cedarjs/project-config");var C="Run any outstanding Data Migrations against the database";function k(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,b.getPaths)().api.dist}).epilogue(`Also see the ${(0,x.terminalLink)("CedarJS CLI Reference","https://cedarjs.com/docs/cli-commands#datamigrate-up")}`)}S();process.env.REDWOOD_ENV_FILES_LOADED||((0,O.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",C,k,P).parse();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installHandler.d.ts","sourceRoot":"","sources":["../../src/commands/installHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"installHandler.d.ts","sourceRoot":"","sources":["../../src/commands/installHandler.ts"],"names":[],"mappings":"AAcA,wBAAsB,OAAO,kBAmD5B;AAED,eAAO,MAAM,uBAAuB,8HAMlC,CAAA;AAEF,eAAO,MAAM,8BAA8B,2EAC+B,CAAA;AAE1E,eAAO,MAAM,KAAK,QAMN,CAAA"}
|
|
@@ -41,25 +41,22 @@ var import_listr2 = require("listr2");
|
|
|
41
41
|
var import_project_config = require("@cedarjs/project-config");
|
|
42
42
|
var import_colors = __toESM(require("../lib/colors"));
|
|
43
43
|
async function handler() {
|
|
44
|
-
const
|
|
44
|
+
const cedarProjectPaths = (0, import_project_config.getPaths)();
|
|
45
|
+
const prismaConfigPath = cedarProjectPaths.api.prismaConfig;
|
|
46
|
+
const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(prismaConfigPath);
|
|
45
47
|
const tasks = new import_listr2.Listr(
|
|
46
48
|
[
|
|
47
49
|
{
|
|
48
50
|
title: "Creating the dataMigrations directory...",
|
|
49
51
|
task() {
|
|
50
|
-
import_node_fs.default.mkdirSync(
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
import_node_fs.default.writeFileSync(
|
|
54
|
-
import_node_path.default.join(redwoodProjectPaths.api.dataMigrations, ".keep"),
|
|
55
|
-
""
|
|
56
|
-
);
|
|
52
|
+
import_node_fs.default.mkdirSync(dataMigrationsPath, { recursive: true });
|
|
53
|
+
import_node_fs.default.writeFileSync(import_node_path.default.join(dataMigrationsPath, ".keep"), "");
|
|
57
54
|
}
|
|
58
55
|
},
|
|
59
56
|
{
|
|
60
57
|
title: "Adding the RW_DataMigration model to schema.prisma...",
|
|
61
|
-
task() {
|
|
62
|
-
const dbSchemaFilePath =
|
|
58
|
+
async task() {
|
|
59
|
+
const dbSchemaFilePath = await (0, import_project_config.getSchemaPath)(prismaConfigPath);
|
|
63
60
|
const dbSchemaFileContent = import_node_fs.default.readFileSync(dbSchemaFilePath, "utf-8");
|
|
64
61
|
import_node_fs.default.writeFileSync(
|
|
65
62
|
dbSchemaFilePath,
|
|
@@ -73,7 +70,7 @@ async function handler() {
|
|
|
73
70
|
title: "Creating the database migration...",
|
|
74
71
|
task() {
|
|
75
72
|
return import_execa.default.command(createDatabaseMigrationCommand, {
|
|
76
|
-
cwd:
|
|
73
|
+
cwd: cedarProjectPaths.base
|
|
77
74
|
}).stdout;
|
|
78
75
|
}
|
|
79
76
|
}
|
|
@@ -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,iBA2GtB;
|
|
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;AA8ED,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
|
|
@@ -134,7 +134,9 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
async function getPendingDataMigrations(db) {
|
|
137
|
-
const dataMigrationsPath = (0, import_project_config.
|
|
137
|
+
const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(
|
|
138
|
+
(0, import_project_config.getPaths)().api.prismaConfig
|
|
139
|
+
);
|
|
138
140
|
if (!import_node_fs.default.existsSync(dataMigrationsPath)) {
|
|
139
141
|
return [];
|
|
140
142
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upHandlerEsm.d.ts","sourceRoot":"","sources":["../../src/commands/upHandlerEsm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upHandlerEsm.d.ts","sourceRoot":"","sources":["../../src/commands/upHandlerEsm.ts"],"names":[],"mappings":"AAcA,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"}
|
|
@@ -138,7 +138,9 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
async function getPendingDataMigrations(db) {
|
|
141
|
-
const dataMigrationsPath = (0, import_project_config.
|
|
141
|
+
const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(
|
|
142
|
+
(0, import_project_config.getPaths)().api.prismaConfig
|
|
143
|
+
);
|
|
142
144
|
if (!import_node_fs.default.existsSync(dataMigrationsPath)) {
|
|
143
145
|
return [];
|
|
144
146
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli-data-migrate",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1-next.18+5ffd3124d",
|
|
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": "vitest run src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@cedarjs/babel-config": "1.1.
|
|
29
|
-
"@cedarjs/project-config": "1.1.
|
|
28
|
+
"@cedarjs/babel-config": "1.1.1-next.18+5ffd3124d",
|
|
29
|
+
"@cedarjs/project-config": "1.1.1-next.18+5ffd3124d",
|
|
30
30
|
"ansis": "4.1.0",
|
|
31
31
|
"bundle-require": "^5.1.0",
|
|
32
32
|
"dotenv-defaults": "5.0.2",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"yargs": "17.7.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@cedarjs/framework-tools": "1.1.
|
|
40
|
-
"@prisma/client": "
|
|
39
|
+
"@cedarjs/framework-tools": "1.1.1-next.18",
|
|
40
|
+
"@prisma/client": "6.19.0",
|
|
41
41
|
"@types/yargs": "17.0.33",
|
|
42
42
|
"memfs": "4.17.2",
|
|
43
43
|
"tsx": "4.20.5",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "5ffd3124d3d4ceb7843408264c96ecceff8542f5"
|
|
51
51
|
}
|