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BAAyB;oBAC3C,KAAiC;gBACtC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;aACjB,CAAA;YAED,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC;gBACb,KAAK,KAAK;oBACN,OAAO,CAAC,WAAW,GAAG,KAAK,CAAA;oBAC3B,MAAK;gBACT,KAAK,MAAM,CAAC;gBACZ,KAAK,OAAO;oBACR,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,KAAK,MAAM;oBACP,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,QAAQ;gBACR,OAAO;YACX,CAAC;YAED,MAAM,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;YACvC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,4BAA4B;YAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,6BAAa,CAAC,SAAS,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;YAE3D,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;CACJ;AA/ED,kDA+EC","file":"MigrationRunCommand.js","sourcesContent":["import path from \"path\"\nimport * as process from \"process\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Runs migration command.\n */\nexport class MigrationRunCommand implements yargs.CommandModule {\n command = \"migration:run\"\n describe = \"Runs all pending migrations.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration run. Enabled by default.\",\n })\n .option(\"fake\", {\n alias: \"f\",\n type: \"boolean\",\n default: false,\n describe:\n \"Fakes running the migrations if table schema has already been changed manually or externally \" +\n \"(e.g. through another project)\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n fake: !!args.f,\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.runMigrations(options)\n await dataSource.destroy()\n\n // exit process if no errors\n process.exit(0)\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration run:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}