@cedarjs/cli-data-migrate 1.1.1-next.18 → 1.1.1-rc.3

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 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(`
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(){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();
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":"AAcA,wBAAsB,OAAO,kBAmD5B;AAED,eAAO,MAAM,uBAAuB,8HAMlC,CAAA;AAEF,eAAO,MAAM,8BAA8B,2EAC+B,CAAA;AAE1E,eAAO,MAAM,KAAK,QAMN,CAAA"}
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"}
@@ -41,22 +41,25 @@ 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 cedarProjectPaths = (0, import_project_config.getPaths)();
45
- const prismaConfigPath = cedarProjectPaths.api.prismaConfig;
46
- const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(prismaConfigPath);
44
+ const redwoodProjectPaths = (0, import_project_config.getPaths)();
47
45
  const tasks = new import_listr2.Listr(
48
46
  [
49
47
  {
50
48
  title: "Creating the dataMigrations directory...",
51
49
  task() {
52
- import_node_fs.default.mkdirSync(dataMigrationsPath, { recursive: true });
53
- import_node_fs.default.writeFileSync(import_node_path.default.join(dataMigrationsPath, ".keep"), "");
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"),
55
+ ""
56
+ );
54
57
  }
55
58
  },
56
59
  {
57
60
  title: "Adding the RW_DataMigration model to schema.prisma...",
58
- async task() {
59
- const dbSchemaFilePath = await (0, import_project_config.getSchemaPath)(prismaConfigPath);
61
+ task() {
62
+ const dbSchemaFilePath = redwoodProjectPaths.api.dbSchema;
60
63
  const dbSchemaFileContent = import_node_fs.default.readFileSync(dbSchemaFilePath, "utf-8");
61
64
  import_node_fs.default.writeFileSync(
62
65
  dbSchemaFilePath,
@@ -70,7 +73,7 @@ async function handler() {
70
73
  title: "Creating the database migration...",
71
74
  task() {
72
75
  return import_execa.default.command(createDatabaseMigrationCommand, {
73
- cwd: cedarProjectPaths.base
76
+ cwd: redwoodProjectPaths.base
74
77
  }).stdout;
75
78
  }
76
79
  }
@@ -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;AA8ED,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
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"}
@@ -134,9 +134,7 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
134
134
  }
135
135
  }
136
136
  async function getPendingDataMigrations(db) {
137
- const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(
138
- (0, import_project_config.getPaths)().api.prismaConfig
139
- );
137
+ const dataMigrationsPath = (0, import_project_config.getPaths)().api.dataMigrations;
140
138
  if (!import_node_fs.default.existsSync(dataMigrationsPath)) {
141
139
  return [];
142
140
  }
@@ -1 +1 @@
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"}
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"}
@@ -138,9 +138,7 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
138
138
  }
139
139
  }
140
140
  async function getPendingDataMigrations(db) {
141
- const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(
142
- (0, import_project_config.getPaths)().api.prismaConfig
143
- );
141
+ const dataMigrationsPath = (0, import_project_config.getPaths)().api.dataMigrations;
144
142
  if (!import_node_fs.default.existsSync(dataMigrationsPath)) {
145
143
  return [];
146
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli-data-migrate",
3
- "version": "1.1.1-next.18+5ffd3124d",
3
+ "version": "1.1.1-rc.3",
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.1-next.18+5ffd3124d",
29
- "@cedarjs/project-config": "1.1.1-next.18+5ffd3124d",
28
+ "@cedarjs/babel-config": "1.1.1-rc.3",
29
+ "@cedarjs/project-config": "1.1.1-rc.3",
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.1-next.18",
40
- "@prisma/client": "6.19.0",
39
+ "@cedarjs/framework-tools": "1.1.1-rc.3",
40
+ "@prisma/client": "5.20.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": "5ffd3124d3d4ceb7843408264c96ecceff8542f5"
50
+ "gitHead": "1332c50070b0ab7f2cfc0d7bc802c60cd8a664a9"
51
51
  }