"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var chunk_WVAPMHNT_exports = {};
__export(chunk_WVAPMHNT_exports, {
  MigrateReset: () => MigrateReset
});
module.exports = __toCommonJS(chunk_WVAPMHNT_exports);
var import_chunk_KRQEFTDT = require("./chunk-KRQEFTDT.js");
var import_chunk_FBDQVK4W = require("./chunk-FBDQVK4W.js");
var import_chunk_ZUHJASAP = require("./chunk-ZUHJASAP.js");
var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
var import_chunk_BRPS327A = require("./chunk-BRPS327A.js");
var import_chunk_RGXJYLMD = require("./chunk-RGXJYLMD.js");
var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
var import_internals = require("@prisma/internals");
var import_prompts = __toESM(require("prompts"));
var MigrateReset = class _MigrateReset {
  static new() {
    return new _MigrateReset();
  }
  static help = (0, import_internals.format)(`
Reset your database and apply all migrations, all data will be lost

${(0, import_chunk_SKRR5WT4.bold)("Usage")}

  ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset [options]

  The datasource URL configuration is read from the Prisma config file (e.g., ${(0, import_chunk_SKRR5WT4.italic)("prisma.config.ts")}).

${(0, import_chunk_SKRR5WT4.bold)("Options")}

       -h, --help   Display this help message
         --config   Custom path to your Prisma config file
         --schema   Custom path to your Prisma schema
      -f, --force   Skip the confirmation prompt

${(0, import_chunk_SKRR5WT4.bold)("Examples")}

  Reset your database and apply all migrations, all data will be lost
  ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset

  Specify a schema
  ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset --schema=./schema.prisma

  Use --force to skip the confirmation prompt
  ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset --force
  `);
  async parse(argv, config, baseDir) {
    const args = (0, import_internals.arg)(argv, {
      "--help": Boolean,
      "-h": "--help",
      "--force": Boolean,
      "-f": "--force",
      "--schema": String,
      "--config": String,
      "--telemetry-information": String
    });
    if ((0, import_internals.isError)(args)) {
      return this.help(args.message);
    }
    if (args["--help"]) {
      return this.help();
    }
    const schemaContext = await (0, import_internals.loadSchemaContext)({
      schemaPath: (0, import_internals.createSchemaPathInput)({
        schemaPathFromArgs: args["--schema"],
        schemaPathFromConfig: config.schema,
        baseDir
      })
    });
    const cmd = "migrate reset";
    const validatedConfig = (0, import_internals.validatePrismaConfigWithDatasource)({ config, cmd });
    const { migrationsDirPath } = (0, import_internals.inferDirectoryConfig)(schemaContext, config);
    const datasourceInfo = (0, import_chunk_BRPS327A.parseDatasourceInfo)(schemaContext.primaryDatasource, validatedConfig);
    (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo });
    (0, import_internals.checkUnsupportedDataProxy)({ cmd, validatedConfig });
    const successMessage = await (0, import_chunk_BRPS327A.ensureDatabaseExists)(
      baseDir,
      (0, import_internals.getSchemaDatasourceProvider)(schemaContext),
      validatedConfig
    );
    if (successMessage) {
      process.stdout.write("\n" + successMessage + "\n");
    }
    process.stdout.write("\n");
    if (!args["--force"]) {
      if (!(0, import_internals.canPrompt)()) {
        throw new import_chunk_ZUHJASAP.MigrateResetEnvNonInteractiveError();
      }
      const confirmation = await (0, import_prompts.default)({
        type: "confirm",
        name: "value",
        message: `Are you sure you want to reset your database? ${(0, import_chunk_SKRR5WT4.red)("All data will be lost")}.`
      });
      process.stdout.write("\n");
      if (!confirmation.value) {
        process.stdout.write("Reset cancelled.\n");
        process.exit(130);
      }
    }
    (0, import_chunk_FBDQVK4W.aiAgentConfirmationCheckpoint)();
    const schemaFilter = {
      externalTables: config.tables?.external ?? [],
      externalEnums: config.enums?.external ?? []
    };
    const migrate = await import_chunk_RGXJYLMD.Migrate.setup({
      schemaEngineConfig: config,
      baseDir,
      migrationsDirPath,
      schemaContext,
      schemaFilter,
      extensions: config["extensions"]
    });
    let migrationIds;
    try {
      await migrate.reset();
      const { appliedMigrationNames } = await migrate.applyMigrations();
      migrationIds = appliedMigrationNames;
    } finally {
      await migrate.stop();
    }
    if (migrationIds.length === 0) {
      process.stdout.write(`${(0, import_chunk_SKRR5WT4.green)("Database reset successful\n")}
`);
    } else {
      process.stdout.write("\n");
      process.stdout.write(
        `${(0, import_chunk_SKRR5WT4.green)("Database reset successful")}

The following migration(s) have been applied:

${(0, import_chunk_KRQEFTDT.printFilesFromMigrationIds)("migrations", migrationIds, {
          "migration.sql": ""
        })}
`
      );
    }
    return ``;
  }
  help(error) {
    if (error) {
      return new import_internals.HelpError(`
${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
${_MigrateReset.help}`);
    }
    return _MigrateReset.help;
  }
};
