@cedarjs/cli-data-migrate 1.0.0 → 1.0.1-next.30
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
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
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();
|
|
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("node:fs")),m=f(require("node: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":"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,kBAsD5B;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
|
|
37
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
38
|
+
var import_node_path = __toESM(require("node:path"));
|
|
38
39
|
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,8 +47,11 @@ async function handler() {
|
|
|
47
47
|
{
|
|
48
48
|
title: "Creating the dataMigrations directory...",
|
|
49
49
|
task() {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
import_node_fs.default.mkdirSync(redwoodProjectPaths.api.dataMigrations, {
|
|
51
|
+
recursive: true
|
|
52
|
+
});
|
|
53
|
+
import_node_fs.default.writeFileSync(
|
|
54
|
+
import_node_path.default.join(redwoodProjectPaths.api.dataMigrations, ".keep"),
|
|
52
55
|
""
|
|
53
56
|
);
|
|
54
57
|
}
|
|
@@ -57,8 +60,8 @@ async function handler() {
|
|
|
57
60
|
title: "Adding the RW_DataMigration model to schema.prisma...",
|
|
58
61
|
task() {
|
|
59
62
|
const dbSchemaFilePath = redwoodProjectPaths.api.dbSchema;
|
|
60
|
-
const dbSchemaFileContent =
|
|
61
|
-
|
|
63
|
+
const dbSchemaFileContent = import_node_fs.default.readFileSync(dbSchemaFilePath, "utf-8");
|
|
64
|
+
import_node_fs.default.writeFileSync(
|
|
62
65
|
dbSchemaFilePath,
|
|
63
66
|
[dbSchemaFileContent.trim(), "", RW_DATA_MIGRATION_MODEL, ""].join(
|
|
64
67
|
"\n"
|
|
@@ -32,8 +32,8 @@ __export(upHandler_exports, {
|
|
|
32
32
|
handler: () => handler
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(upHandler_exports);
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
36
|
+
var import_node_path = __toESM(require("node:path"));
|
|
37
37
|
var import_listr2 = require("listr2");
|
|
38
38
|
var import_babel_config = require("@cedarjs/babel-config");
|
|
39
39
|
var import_project_config = require("@cedarjs/project-config");
|
|
@@ -45,16 +45,16 @@ async function handler({
|
|
|
45
45
|
let db;
|
|
46
46
|
let requireHookRegistered = false;
|
|
47
47
|
if (importDbClientFromDist) {
|
|
48
|
-
if (!
|
|
48
|
+
if (!import_node_fs.default.existsSync(distPath)) {
|
|
49
49
|
console.warn(
|
|
50
50
|
`Can't find api dist at ${distPath}. You may need to build first: yarn rw build api`
|
|
51
51
|
);
|
|
52
52
|
process.exitCode = 1;
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
const distLibPath =
|
|
56
|
-
const distLibDbPath =
|
|
57
|
-
if (!
|
|
55
|
+
const distLibPath = import_node_path.default.join(distPath, "lib");
|
|
56
|
+
const distLibDbPath = import_node_path.default.join(distLibPath, "db.js");
|
|
57
|
+
if (!import_node_fs.default.existsSync(distLibDbPath)) {
|
|
58
58
|
console.error(
|
|
59
59
|
`Can't find db.js at ${distLibDbPath}. CedarJS expects the db.js file to be in the ${distLibPath} directory`
|
|
60
60
|
);
|
|
@@ -65,7 +65,7 @@ async function handler({
|
|
|
65
65
|
} else {
|
|
66
66
|
(0, import_babel_config.registerApiSideBabelHook)();
|
|
67
67
|
requireHookRegistered = true;
|
|
68
|
-
db = require(
|
|
68
|
+
db = require(import_node_path.default.join((0, import_project_config.getPaths)().api.lib, "db")).db;
|
|
69
69
|
}
|
|
70
70
|
const pendingDataMigrations = await getPendingDataMigrations(db);
|
|
71
71
|
if (!pendingDataMigrations.length) {
|
|
@@ -77,7 +77,7 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
|
77
77
|
}
|
|
78
78
|
const counters = { run: 0, skipped: 0, error: 0 };
|
|
79
79
|
const dataMigrationTasks = pendingDataMigrations.map((dataMigration) => {
|
|
80
|
-
const dataMigrationName =
|
|
80
|
+
const dataMigrationName = import_node_path.default.basename(dataMigration.path, ".js");
|
|
81
81
|
return {
|
|
82
82
|
title: dataMigrationName,
|
|
83
83
|
skip() {
|
|
@@ -135,10 +135,10 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
|
135
135
|
}
|
|
136
136
|
async function getPendingDataMigrations(db) {
|
|
137
137
|
const dataMigrationsPath = (0, import_project_config.getPaths)().api.dataMigrations;
|
|
138
|
-
if (!
|
|
138
|
+
if (!import_node_fs.default.existsSync(dataMigrationsPath)) {
|
|
139
139
|
return [];
|
|
140
140
|
}
|
|
141
|
-
const dataMigrations =
|
|
141
|
+
const dataMigrations = import_node_fs.default.readdirSync(dataMigrationsPath).filter(
|
|
142
142
|
(dataMigrationFileName) => ["js", ".ts"].some(
|
|
143
143
|
(extension) => dataMigrationFileName.endsWith(extension)
|
|
144
144
|
)
|
|
@@ -146,7 +146,7 @@ async function getPendingDataMigrations(db) {
|
|
|
146
146
|
const [version] = dataMigrationFileName.split("-");
|
|
147
147
|
return {
|
|
148
148
|
version,
|
|
149
|
-
path:
|
|
149
|
+
path: import_node_path.default.join(dataMigrationsPath, dataMigrationFileName)
|
|
150
150
|
};
|
|
151
151
|
});
|
|
152
152
|
const ranDataMigrations = await db.rW_DataMigration.findMany(
|
|
@@ -32,8 +32,8 @@ __export(upHandlerEsm_exports, {
|
|
|
32
32
|
handler: () => handler
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(upHandlerEsm_exports);
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
36
|
+
var import_node_path = __toESM(require("node:path"));
|
|
37
37
|
var import_bundle_require = require("bundle-require");
|
|
38
38
|
var import_listr2 = require("listr2");
|
|
39
39
|
var import_project_config = require("@cedarjs/project-config");
|
|
@@ -44,16 +44,16 @@ async function handler({
|
|
|
44
44
|
}) {
|
|
45
45
|
let db;
|
|
46
46
|
if (importDbClientFromDist) {
|
|
47
|
-
if (!
|
|
47
|
+
if (!import_node_fs.default.existsSync(distPath)) {
|
|
48
48
|
console.warn(
|
|
49
49
|
`Can't find api dist at ${distPath}. You may need to build first: yarn rw build api`
|
|
50
50
|
);
|
|
51
51
|
process.exitCode = 1;
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
const distLibPath =
|
|
55
|
-
const distLibDbPath =
|
|
56
|
-
if (!
|
|
54
|
+
const distLibPath = import_node_path.default.join(distPath, "lib");
|
|
55
|
+
const distLibDbPath = import_node_path.default.join(distLibPath, "db.js");
|
|
56
|
+
if (!import_node_fs.default.existsSync(distLibDbPath)) {
|
|
57
57
|
console.error(
|
|
58
58
|
`Can't find db.js at ${distLibDbPath}. CedarJS expects the db.js file to be in the ${distLibPath} directory`
|
|
59
59
|
);
|
|
@@ -62,7 +62,7 @@ async function handler({
|
|
|
62
62
|
}
|
|
63
63
|
db = (await import(distLibDbPath)).db;
|
|
64
64
|
} else {
|
|
65
|
-
const dbPath = (0, import_project_config.resolveFile)(
|
|
65
|
+
const dbPath = (0, import_project_config.resolveFile)(import_node_path.default.join((0, import_project_config.getPaths)().api.lib, "db"));
|
|
66
66
|
if (!dbPath) {
|
|
67
67
|
console.error(`Can't find your db file in ${(0, import_project_config.getPaths)().api.lib}`);
|
|
68
68
|
process.exitCode = 1;
|
|
@@ -84,7 +84,7 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
|
84
84
|
}
|
|
85
85
|
const counters = { run: 0, skipped: 0, error: 0 };
|
|
86
86
|
const dataMigrationTasks = pendingDataMigrations.map((dataMigration) => {
|
|
87
|
-
const dataMigrationName =
|
|
87
|
+
const dataMigrationName = import_node_path.default.basename(dataMigration.path, ".js");
|
|
88
88
|
return {
|
|
89
89
|
title: dataMigrationName,
|
|
90
90
|
skip() {
|
|
@@ -139,10 +139,10 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
|
|
|
139
139
|
}
|
|
140
140
|
async function getPendingDataMigrations(db) {
|
|
141
141
|
const dataMigrationsPath = (0, import_project_config.getPaths)().api.dataMigrations;
|
|
142
|
-
if (!
|
|
142
|
+
if (!import_node_fs.default.existsSync(dataMigrationsPath)) {
|
|
143
143
|
return [];
|
|
144
144
|
}
|
|
145
|
-
const dataMigrations =
|
|
145
|
+
const dataMigrations = import_node_fs.default.readdirSync(dataMigrationsPath).filter(
|
|
146
146
|
(dataMigrationFileName) => ["js", ".ts"].some(
|
|
147
147
|
(extension) => dataMigrationFileName.endsWith(extension)
|
|
148
148
|
)
|
|
@@ -150,7 +150,7 @@ async function getPendingDataMigrations(db) {
|
|
|
150
150
|
const [version] = dataMigrationFileName.split("-");
|
|
151
151
|
return {
|
|
152
152
|
version,
|
|
153
|
-
path:
|
|
153
|
+
path: import_node_path.default.join(dataMigrationsPath, dataMigrationFileName)
|
|
154
154
|
};
|
|
155
155
|
});
|
|
156
156
|
const ranDataMigrations = await db.rW_DataMigration.findMany(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli-data-migrate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-next.30+c50602506",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -21,33 +21,31 @@
|
|
|
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": "
|
|
25
|
-
"test:unit": "
|
|
24
|
+
"test:dist": "vitest run ./dist.test.ts",
|
|
25
|
+
"test:unit": "vitest run src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@cedarjs/babel-config": "1.0.
|
|
29
|
-
"@cedarjs/project-config": "1.0.
|
|
28
|
+
"@cedarjs/babel-config": "1.0.1-next.30+c50602506",
|
|
29
|
+
"@cedarjs/project-config": "1.0.1-next.30+c50602506",
|
|
30
30
|
"ansis": "4.1.0",
|
|
31
31
|
"bundle-require": "^5.1.0",
|
|
32
32
|
"dotenv-defaults": "5.0.2",
|
|
33
33
|
"execa": "5.1.1",
|
|
34
|
-
"fs-extra": "11.2.0",
|
|
35
34
|
"listr2": "7.0.2",
|
|
36
35
|
"termi-link": "1.1.0",
|
|
37
36
|
"yargs": "17.7.2"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@cedarjs/framework-tools": "1.0.
|
|
39
|
+
"@cedarjs/framework-tools": "1.0.1-next.30",
|
|
41
40
|
"@prisma/client": "5.20.0",
|
|
42
|
-
"@types/fs-extra": "11.0.4",
|
|
43
41
|
"@types/yargs": "17.0.33",
|
|
44
|
-
"jest": "29.7.0",
|
|
45
42
|
"memfs": "4.17.2",
|
|
46
43
|
"tsx": "4.20.5",
|
|
47
|
-
"typescript": "5.9.2"
|
|
44
|
+
"typescript": "5.9.2",
|
|
45
|
+
"vitest": "3.2.4"
|
|
48
46
|
},
|
|
49
47
|
"publishConfig": {
|
|
50
48
|
"access": "public"
|
|
51
49
|
},
|
|
52
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "c50602506f5c30e6a31561bed1dadd87569fbd45"
|
|
53
51
|
}
|