"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_YV75LI45_exports = {};
__export(chunk_YV75LI45_exports, {
  MigrateReset: () => MigrateReset,
  init_MigrateReset: () => init_MigrateReset
});
module.exports = __toCommonJS(chunk_YV75LI45_exports);
var import_chunk_VHXQHY5M = require("./chunk-VHXQHY5M.js");
var import_chunk_YUDCPOWB = require("./chunk-YUDCPOWB.js");
var import_chunk_BOP7PHOB = require("./chunk-BOP7PHOB.js");
var import_chunk_KCMQOXUX = require("./chunk-KCMQOXUX.js");
var import_chunk_FFLD75KX = require("./chunk-FFLD75KX.js");
var import_chunk_PZ4BRULM = require("./chunk-PZ4BRULM.js");
var import_chunk_2CL32XWS = require("./chunk-2CL32XWS.js");
var import_chunk_F7KSWWYN = require("./chunk-F7KSWWYN.js");
var import_chunk_FVJ3R4NJ = require("./chunk-FVJ3R4NJ.js");
var import_internals = require("@prisma/internals");
var import_prompts = __toESM(require("prompts"));
var _MigrateReset, MigrateReset;
var init_MigrateReset = (0, import_chunk_FVJ3R4NJ.__esm)({
  "src/commands/MigrateReset.ts"() {
    (0, import_chunk_F7KSWWYN.init_colors)();
    (0, import_chunk_BOP7PHOB.init_Migrate)();
    (0, import_chunk_PZ4BRULM.init_ensureDatabaseExists)();
    (0, import_chunk_2CL32XWS.init_errors)();
    (0, import_chunk_KCMQOXUX.init_getSchemaPathAndPrint)();
    (0, import_chunk_FFLD75KX.init_printDatasource)();
    (0, import_chunk_YUDCPOWB.init_printFiles)();
    (0, import_chunk_VHXQHY5M.init_seed)();
    _MigrateReset = class _MigrateReset2 {
      static new() {
        return new _MigrateReset2();
      }
      async parse(argv) {
        const args = (0, import_internals.arg)(argv, {
          "--help": Boolean,
          "-h": "--help",
          "--force": Boolean,
          "-f": "--force",
          "--skip-generate": Boolean,
          "--skip-seed": Boolean,
          "--schema": String,
          "--telemetry-information": String
        });
        if ((0, import_internals.isError)(args)) {
          return this.help(args.message);
        }
        await (0, import_internals.checkUnsupportedDataProxy)("migrate reset", args, true);
        if (args["--help"]) {
          return this.help();
        }
        (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true });
        const schemaPath = await (0, import_chunk_KCMQOXUX.getSchemaPathAndPrint)(args["--schema"]);
        (0, import_chunk_FFLD75KX.printDatasource)({ datasourceInfo: await (0, import_chunk_PZ4BRULM.getDatasourceInfo)({ schemaPath }) });
        const wasDbCreated = await (0, import_chunk_PZ4BRULM.ensureDatabaseExists)("create", schemaPath);
        if (wasDbCreated) {
          console.info();
          console.info(wasDbCreated);
        }
        console.info();
        if (!args["--force"]) {
          if (!(0, import_internals.canPrompt)()) {
            throw new import_chunk_2CL32XWS.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_F7KSWWYN.red)("All data will be lost")}.`
          });
          console.info();
          if (!confirmation.value) {
            console.info("Reset cancelled.");
            process.exit(130);
          }
        }
        const migrate = new import_chunk_BOP7PHOB.Migrate(schemaPath);
        let migrationIds;
        try {
          await migrate.reset();
          const { appliedMigrationNames } = await migrate.applyMigrations();
          migrationIds = appliedMigrationNames;
        } finally {
          migrate.stop();
        }
        if (migrationIds.length === 0) {
          console.info(`${(0, import_chunk_F7KSWWYN.green)("Database reset successful\n")}`);
        } else {
          console.info();
          console.info(
            `${(0, import_chunk_F7KSWWYN.green)("Database reset successful")}

The following migration(s) have been applied:

${(0, import_chunk_YUDCPOWB.printFilesFromMigrationIds)("migrations", migrationIds, {
              "migration.sql": ""
            })}`
          );
        }
        if (!process.env.PRISMA_MIGRATE_SKIP_GENERATE && !args["--skip-generate"]) {
          await migrate.tryToRunGenerate();
        }
        if (!process.env.PRISMA_MIGRATE_SKIP_SEED && !args["--skip-seed"]) {
          const seedCommandFromPkgJson = await (0, import_chunk_VHXQHY5M.getSeedCommandFromPackageJson)(process.cwd());
          if (seedCommandFromPkgJson) {
            console.info();
            const successfulSeeding = await (0, import_chunk_VHXQHY5M.executeSeedCommand)({ commandFromConfig: seedCommandFromPkgJson });
            if (successfulSeeding) {
              console.info(`
${process.platform === "win32" ? "" : "\u{1F331}  "}The seed command has been executed.`);
            } else {
              process.exit(1);
            }
          } else {
            const schemaPath2 = await (0, import_internals.getSchemaPath)(args["--schema"]);
            await (0, import_chunk_VHXQHY5M.verifySeedConfigAndReturnMessage)(schemaPath2);
          }
        }
        return ``;
      }
      help(error) {
        if (error) {
          return new import_internals.HelpError(`
${(0, import_chunk_F7KSWWYN.bold)((0, import_chunk_F7KSWWYN.red)(`!`))} ${error}
${_MigrateReset2.help}`);
        }
        return _MigrateReset2.help;
      }
    };
    _MigrateReset.help = (0, import_internals.format)(`
Reset your database and apply all migrations, all data will be lost

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

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

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

       -h, --help   Display this help message
         --schema   Custom path to your Prisma schema
  --skip-generate   Skip triggering generators (e.g. Prisma Client)
      --skip-seed   Skip triggering seed
      -f, --force   Skip the confirmation prompt

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

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

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

  Use --force to skip the confirmation prompt
  ${(0, import_chunk_F7KSWWYN.dim)("$")} prisma migrate reset --force
  `);
    MigrateReset = _MigrateReset;
  }
});
