@zenstackhq/cli 3.6.0 → 3.6.2

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/index.cjs CHANGED
@@ -40,6 +40,8 @@ node_path = __toESM(node_path, 1);
40
40
  let _zenstackhq_common_helpers = require("@zenstackhq/common-helpers");
41
41
  let _zenstackhq_sdk = require("@zenstackhq/sdk");
42
42
  let jiti = require("jiti");
43
+ let node_crypto = require("node:crypto");
44
+ node_crypto = __toESM(node_crypto, 1);
43
45
  let node_fs = require("node:fs");
44
46
  node_fs = __toESM(node_fs, 1);
45
47
  let node_module = require("node:module");
@@ -70,7 +72,6 @@ cors = __toESM(cors, 1);
70
72
  let express = require("express");
71
73
  express = __toESM(express, 1);
72
74
  let mixpanel = require("mixpanel");
73
- let node_crypto = require("node:crypto");
74
75
  let os = require("os");
75
76
  os = __toESM(os, 1);
76
77
  let node_process = require("node:process");
@@ -124,12 +125,14 @@ function handleSubProcessError$1(err) {
124
125
  if (err instanceof Error && "status" in err && typeof err.status === "number") process.exit(err.status);
125
126
  else process.exit(1);
126
127
  }
127
- async function generateTempPrismaSchema(zmodelPath, folder) {
128
+ async function generateTempPrismaSchema(zmodelPath, opts = {}) {
129
+ const { folder: folderOpt, randomName = false } = opts;
128
130
  const model = await loadSchemaDocument(zmodelPath);
129
131
  if (!model.declarations.some(_zenstackhq_language_ast.isDataSource)) throw new CliError("Schema must define a datasource");
130
132
  const prismaSchema = await new _zenstackhq_sdk.PrismaSchemaGenerator(model).generate();
131
- if (!folder) folder = node_path.default.dirname(zmodelPath);
132
- const prismaSchemaFile = node_path.default.resolve(folder, "~schema.prisma");
133
+ const folder = folderOpt ?? node_path.default.dirname(zmodelPath);
134
+ const fileName = randomName ? `~schema.${node_crypto.default.randomUUID()}.prisma` : "~schema.prisma";
135
+ const prismaSchemaFile = node_path.default.resolve(folder, fileName);
133
136
  node_fs.default.writeFileSync(prismaSchemaFile, prismaSchema);
134
137
  return prismaSchemaFile;
135
138
  }
@@ -2189,7 +2192,7 @@ async function run$7(command, options) {
2189
2192
  async function runPush(options) {
2190
2193
  const schemaFile = getSchemaFile(options.schema);
2191
2194
  await requireDataSourceUrl(schemaFile);
2192
- const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
2195
+ const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, { randomName: options.randomPrismaSchemaName });
2193
2196
  try {
2194
2197
  const cmd = [
2195
2198
  "db push",
@@ -2922,7 +2925,10 @@ async function run$2(options, args) {
2922
2925
  async function run$1(command, options) {
2923
2926
  const schemaFile = getSchemaFile(options.schema);
2924
2927
  await requireDataSourceUrl(schemaFile);
2925
- const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, options.migrations ? node_path.default.dirname(options.migrations) : void 0);
2928
+ const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, {
2929
+ folder: options.migrations ? node_path.default.dirname(options.migrations) : void 0,
2930
+ randomName: options.randomPrismaSchemaName
2931
+ });
2926
2932
  try {
2927
2933
  switch (command) {
2928
2934
  case "dev":
@@ -3412,16 +3418,17 @@ function createProgram() {
3412
3418
  const schemaOption = new commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "zenstack/schema.zmodel" unless specified in package.json.`);
3413
3419
  const noVersionCheckOption = new commander.Option("--no-version-check", "do not check for new version");
3414
3420
  const noTipsOption = new commander.Option("--no-tips", "do not show usage tips");
3421
+ const randomPrismaSchemaNameOption = new commander.Option("--random-prisma-schema-name", "append a random UUID to the temporary Prisma schema filename (e.g., ~schema.<uuid>.prisma) to avoid collisions between concurrent runs sharing a working directory").default(false);
3415
3422
  program.command("generate").description("Run code generation plugins").addOption(schemaOption).addOption(noVersionCheckOption).addOption(noTipsOption).addOption(new commander.Option("-o, --output <path>", "default output directory for code generation")).addOption(new commander.Option("-w, --watch", "enable watch mode").default(false)).addOption(triStateBooleanOption("--lite [boolean]", "also generate a lite version of schema without attributes, defaults to false")).addOption(triStateBooleanOption("--lite-only [boolean]", "only generate lite version of schema without attributes, defaults to false")).addOption(triStateBooleanOption("--generate-models [boolean]", "generate models.ts file, defaults to true")).addOption(triStateBooleanOption("--generate-input [boolean]", "generate input.ts file, defaults to true")).addOption(new commander.Option("--silent", "suppress all output except errors").default(false)).action(generateAction);
3416
3423
  const migrateCommand = program.command("migrate").description("Run database schema migration related tasks.");
3417
3424
  const migrationsOption = new commander.Option("--migrations <path>", "path that contains the \"migrations\" directory");
3418
- migrateCommand.command("dev").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new commander.Option("-n, --name <name>", "migration name")).addOption(new commander.Option("--create-only", "only create migration, do not apply")).addOption(migrationsOption).description("Create a migration from changes in schema and apply it to the database").action((options) => migrateAction("dev", options));
3419
- migrateCommand.command("reset").addOption(schemaOption).addOption(new commander.Option("--force", "skip the confirmation prompt")).addOption(migrationsOption).addOption(new commander.Option("--skip-seed", "skip seeding the database after reset")).addOption(noVersionCheckOption).description("Reset your database and apply all migrations, all data will be lost").addHelpText("after", "\nIf there is a seed script defined in package.json, it will be run after the reset. Use --skip-seed to skip it.").action((options) => migrateAction("reset", options));
3420
- migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database").action((options) => migrateAction("deploy", options));
3421
- migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations").action((options) => migrateAction("status", options));
3422
- migrateCommand.command("resolve").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).addOption(new commander.Option("--applied <migration>", "record a specific migration as applied")).addOption(new commander.Option("--rolled-back <migration>", "record a specific migration as rolled back")).description("Resolve issues with database migrations in deployment databases").action((options) => migrateAction("resolve", options));
3425
+ migrateCommand.command("dev").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new commander.Option("-n, --name <name>", "migration name")).addOption(new commander.Option("--create-only", "only create migration, do not apply")).addOption(migrationsOption).addOption(randomPrismaSchemaNameOption).description("Create a migration from changes in schema and apply it to the database").action((options) => migrateAction("dev", options));
3426
+ migrateCommand.command("reset").addOption(schemaOption).addOption(new commander.Option("--force", "skip the confirmation prompt")).addOption(migrationsOption).addOption(new commander.Option("--skip-seed", "skip seeding the database after reset")).addOption(noVersionCheckOption).addOption(randomPrismaSchemaNameOption).description("Reset your database and apply all migrations, all data will be lost").addHelpText("after", "\nIf there is a seed script defined in package.json, it will be run after the reset. Use --skip-seed to skip it.").action((options) => migrateAction("reset", options));
3427
+ migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).addOption(randomPrismaSchemaNameOption).description("Deploy your pending migrations to your production/staging database").action((options) => migrateAction("deploy", options));
3428
+ migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).addOption(randomPrismaSchemaNameOption).description("Check the status of your database migrations").action((options) => migrateAction("status", options));
3429
+ migrateCommand.command("resolve").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).addOption(randomPrismaSchemaNameOption).addOption(new commander.Option("--applied <migration>", "record a specific migration as applied")).addOption(new commander.Option("--rolled-back <migration>", "record a specific migration as rolled back")).description("Resolve issues with database migrations in deployment databases").action((options) => migrateAction("resolve", options));
3423
3430
  const dbCommand = program.command("db").description("Manage your database schema during development");
3424
- dbCommand.command("push").description("Push the state from your schema to your database").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new commander.Option("--accept-data-loss", "ignore data loss warnings")).addOption(new commander.Option("--force-reset", "force a reset of the database before push")).action((options) => dbAction("push", options));
3431
+ dbCommand.command("push").description("Push the state from your schema to your database").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new commander.Option("--accept-data-loss", "ignore data loss warnings")).addOption(new commander.Option("--force-reset", "force a reset of the database before push")).addOption(randomPrismaSchemaNameOption).action((options) => dbAction("push", options));
3425
3432
  dbCommand.command("pull").description("Introspect your database.").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new commander.Option("-o, --output <path>", "set custom output path for the introspected schema. If a file path is provided, all schemas are merged into that single file. If a directory path is provided, files are written to the directory and imports are kept.")).addOption(new commander.Option("--model-casing <pascal|camel|snake|none>", "set the casing of generated models").default("pascal")).addOption(new commander.Option("--field-casing <pascal|camel|snake|none>", "set the casing of generated fields").default("camel")).addOption(new commander.Option("--always-map", "always add @map and @@map attributes to models and fields").default(false)).addOption(new commander.Option("--quote <double|single>", "set the quote style of generated schema files").default("single")).addOption(new commander.Option("--indent <number>", "set the indentation of the generated schema files").default(4)).action((options) => dbAction("pull", options));
3426
3433
  dbCommand.command("seed").description("Seed the database").allowExcessArguments(true).addHelpText("after", `
3427
3434
  Seed script is configured under the "zenstack.seed" field in package.json.