typeorm 0.3.2-dev.b53a481 → 0.3.2-dev.edf27d9

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.
Files changed (41) hide show
  1. package/README.md +1 -0
  2. package/browser/cli-ts-node-commonjs.d.ts +2 -0
  3. package/browser/cli-ts-node-commonjs.js +4 -0
  4. package/browser/cli-ts-node-commonjs.js.map +1 -0
  5. package/browser/cli-ts-node-esm.d.ts +2 -0
  6. package/browser/cli-ts-node-esm.js +4 -0
  7. package/browser/cli-ts-node-esm.js.map +1 -0
  8. package/browser/driver/postgres/PostgresDriver.js +1 -1
  9. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  10. package/cli-ts-node-commonjs.d.ts +2 -0
  11. package/cli-ts-node-commonjs.js +6 -0
  12. package/cli-ts-node-commonjs.js.map +1 -0
  13. package/cli-ts-node-esm.d.ts +2 -0
  14. package/cli-ts-node-esm.js +6 -0
  15. package/cli-ts-node-esm.js.map +1 -0
  16. package/commands/CacheClearCommand.js +1 -1
  17. package/commands/CacheClearCommand.js.map +1 -1
  18. package/commands/CommandUtils.d.ts +1 -1
  19. package/commands/CommandUtils.js +4 -2
  20. package/commands/CommandUtils.js.map +1 -1
  21. package/commands/InitCommand.js +2 -2
  22. package/commands/InitCommand.js.map +1 -1
  23. package/commands/MigrationGenerateCommand.js +1 -1
  24. package/commands/MigrationGenerateCommand.js.map +1 -1
  25. package/commands/MigrationRevertCommand.js +1 -1
  26. package/commands/MigrationRevertCommand.js.map +1 -1
  27. package/commands/MigrationRunCommand.js +1 -1
  28. package/commands/MigrationRunCommand.js.map +1 -1
  29. package/commands/MigrationShowCommand.js +1 -1
  30. package/commands/MigrationShowCommand.js.map +1 -1
  31. package/commands/QueryCommand.js +1 -1
  32. package/commands/QueryCommand.js.map +1 -1
  33. package/commands/SchemaDropCommand.js +1 -1
  34. package/commands/SchemaDropCommand.js.map +1 -1
  35. package/commands/SchemaLogCommand.js +1 -1
  36. package/commands/SchemaLogCommand.js.map +1 -1
  37. package/commands/SchemaSyncCommand.js +1 -1
  38. package/commands/SchemaSyncCommand.js.map +1 -1
  39. package/driver/postgres/PostgresDriver.js +1 -1
  40. package/driver/postgres/PostgresDriver.js.map +1 -1
  41. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/CommandUtils.ts"],"names":[],"mappings":";;;;AAAA,+CAAwB;AACxB,mDAA4B;AAC5B,4DAA2B;AAC3B,oCAAuC;AAEvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,YAAY;IACrB,MAAM,CAAC,cAAc,CAAC,kBAA0B;QAC5C,IAAI,qBAAqB,CAAA;QACzB,IAAI;YACA,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;SACtD;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,IAAI,KAAK,CACX,6BAA6B,kBAAkB,uFAAuF,CACzI,CAAA;SACJ;QAED,IACI,CAAC,qBAAqB;YACtB,OAAO,qBAAqB,KAAK,QAAQ,EAC3C;YACE,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAA;SACJ;QAED,MAAM,iBAAiB,GAAG,EAAE,CAAA;QAC5B,KAAK,IAAI,UAAU,IAAI,qBAAqB,EAAE;YAC1C,IACI,iCAAe,CAAC,YAAY,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,EACjE;gBACE,iBAAiB,CAAC,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAA;aAC5D;SACJ;QAED,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAA;SACJ;QACD,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CACX,4EAA4E,CAC/E,CAAA;SACJ;QACD,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAA;IAC/B,CAAC;IAED;;OAEG;IACH,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CAAC,KAAK,CAAC,uBAAuB,CAAC,IAAI,uBAAuB,GAAG,CAAC,CAAC,EACjE;YACE,MAAM,IAAI,oBAAY,CAClB,+DAA+D,uBAAuB,EAAE,CAC3F,CAAA;SACJ;QACD,OAAO,uBAAuB;YAC1B,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC,OAAO,EAAE;YACrD,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACpB,CAAC;CACJ;AAhGD,oCAgGC","file":"CommandUtils.js","sourcesContent":["import * as fs from \"fs\"\nimport * as path from \"path\"\nimport mkdirp from \"mkdirp\"\nimport { TypeORMError } from \"../error\"\nimport { DataSource } from \"../data-source\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Command line utils functions.\n */\nexport class CommandUtils {\n static loadDataSource(dataSourceFilePath: string): DataSource {\n let dataSourceFileExports\n try {\n dataSourceFileExports = require(dataSourceFilePath)\n } catch (err) {\n throw new Error(\n `Invalid file path given: \"${dataSourceFilePath}\". File must contain a TypeScript / JavaScript code and export a DataSource instance.`,\n )\n }\n\n if (\n !dataSourceFileExports ||\n typeof dataSourceFileExports !== \"object\"\n ) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n\n const dataSourceExports = []\n for (let fileExport in dataSourceFileExports) {\n if (\n InstanceChecker.isDataSource(dataSourceFileExports[fileExport])\n ) {\n dataSourceExports.push(dataSourceFileExports[fileExport])\n }\n }\n\n if (dataSourceExports.length === 0) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n if (dataSourceExports.length > 1) {\n throw new Error(\n `Given data source file must contain only one export of DataSource instance`,\n )\n }\n return dataSourceExports[0]\n }\n\n /**\n * Creates directories recursively.\n */\n static createDirectories(directory: string) {\n return mkdirp(directory)\n }\n\n /**\n * Creates a file with the given content in the given path.\n */\n static async createFile(\n filePath: string,\n content: string,\n override: boolean = true,\n ): Promise<void> {\n await CommandUtils.createDirectories(path.dirname(filePath))\n return new Promise<void>((ok, fail) => {\n if (override === false && fs.existsSync(filePath)) return ok()\n\n fs.writeFile(filePath, content, (err) => (err ? fail(err) : ok()))\n })\n }\n\n /**\n * Reads everything from a given file and returns its content as a string.\n */\n static async readFile(filePath: string): Promise<string> {\n return new Promise<string>((ok, fail) => {\n fs.readFile(filePath, (err, data) =>\n err ? fail(err) : ok(data.toString()),\n )\n })\n }\n\n static async fileExists(filePath: string) {\n return fs.existsSync(filePath)\n }\n\n /**\n * Gets migration timestamp and validates argument (if sent)\n */\n static getTimestamp(timestampOptionArgument: any): number {\n if (\n timestampOptionArgument &&\n (isNaN(timestampOptionArgument) || timestampOptionArgument < 0)\n ) {\n throw new TypeORMError(\n `timestamp option should be a non-negative number. received: ${timestampOptionArgument}`,\n )\n }\n return timestampOptionArgument\n ? new Date(Number(timestampOptionArgument)).getTime()\n : Date.now()\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/CommandUtils.ts"],"names":[],"mappings":";;;;AAAA,+CAAwB;AACxB,mDAA4B;AAC5B,4DAA2B;AAC3B,oCAAuC;AAEvC,6DAAyD;AACzD,qDAAyD;AAEzD;;GAEG;AACH,MAAa,YAAY;IACrB,MAAM,CAAC,KAAK,CAAC,cAAc,CACvB,kBAA0B;QAE1B,IAAI,qBAAqB,CAAA;QACzB,IAAI;YACA,CAAC;YAAA,CAAC,qBAAqB,CAAC,GAAG,MAAM,IAAA,iCAAmB,EAChD,kBAAkB,CACrB,CAAA;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,IAAI,KAAK,CACX,6BAA6B,kBAAkB,uFAAuF,CACzI,CAAA;SACJ;QAED,IACI,CAAC,qBAAqB;YACtB,OAAO,qBAAqB,KAAK,QAAQ,EAC3C;YACE,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAA;SACJ;QAED,MAAM,iBAAiB,GAAG,EAAE,CAAA;QAC5B,KAAK,IAAI,UAAU,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C,EAAE,EAAE,IAAI,EAAE,EAAE;YACpC,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAChC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CACxC,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAgB;QACpC,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,uBAA4B;QAC5C,IACI,uBAAuB;YACvB,CAAC,KAAK,CAAC,uBAAuB,CAAC,IAAI,uBAAuB,GAAG,CAAC,CAAC,EACjE;YACE,MAAM,IAAI,oBAAY,CAClB,+DAA+D,uBAAuB,EAAE,CAC3F,CAAA;SACJ;QACD,OAAO,uBAAuB;YAC1B,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC,OAAO,EAAE;YACrD,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACpB,CAAC;CACJ;AApGD,oCAoGC","file":"CommandUtils.js","sourcesContent":["import * as fs from \"fs\"\nimport * as path from \"path\"\nimport mkdirp from \"mkdirp\"\nimport { TypeORMError } from \"../error\"\nimport { DataSource } from \"../data-source\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Command line utils functions.\n */\nexport class CommandUtils {\n static async loadDataSource(\n dataSourceFilePath: string,\n ): Promise<DataSource> {\n let dataSourceFileExports\n try {\n ;[dataSourceFileExports] = await importOrRequireFile(\n dataSourceFilePath,\n )\n } catch (err) {\n throw new Error(\n `Invalid file path given: \"${dataSourceFilePath}\". File must contain a TypeScript / JavaScript code and export a DataSource instance.`,\n )\n }\n\n if (\n !dataSourceFileExports ||\n typeof dataSourceFileExports !== \"object\"\n ) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n\n const dataSourceExports = []\n for (let fileExport in dataSourceFileExports) {\n if (\n InstanceChecker.isDataSource(dataSourceFileExports[fileExport])\n ) {\n dataSourceExports.push(dataSourceFileExports[fileExport])\n }\n }\n\n if (dataSourceExports.length === 0) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n if (dataSourceExports.length > 1) {\n throw new Error(\n `Given data source file must contain only one export of DataSource instance`,\n )\n }\n return dataSourceExports[0]\n }\n\n /**\n * Creates directories recursively.\n */\n static createDirectories(directory: string) {\n return mkdirp(directory)\n }\n\n /**\n * Creates a file with the given content in the given path.\n */\n static async createFile(\n filePath: string,\n content: string,\n override: boolean = true,\n ): Promise<void> {\n await CommandUtils.createDirectories(path.dirname(filePath))\n return new Promise<void>((ok, fail) => {\n if (override === false && fs.existsSync(filePath)) return ok()\n\n fs.writeFile(filePath, content, (err) => (err ? fail(err) : ok()))\n })\n }\n\n /**\n * Reads everything from a given file and returns its content as a string.\n */\n static async readFile(filePath: string): Promise<string> {\n return new Promise<string>((ok, fail) => {\n fs.readFile(filePath, (err, data) =>\n err ? fail(err) : ok(data.toString()),\n )\n })\n }\n\n static async fileExists(filePath: string) {\n return fs.existsSync(filePath)\n }\n\n /**\n * Gets migration timestamp and validates argument (if sent)\n */\n static getTimestamp(timestampOptionArgument: any): number {\n if (\n timestampOptionArgument &&\n (isNaN(timestampOptionArgument) || timestampOptionArgument < 0)\n ) {\n throw new TypeORMError(\n `timestamp option should be a non-negative number. received: ${timestampOptionArgument}`,\n )\n }\n return timestampOptionArgument\n ? new Date(Number(timestampOptionArgument)).getTime()\n : Date.now()\n }\n}\n"],"sourceRoot":".."}
@@ -586,12 +586,12 @@ Steps to run this project:
586
586
  if (projectIsEsm)
587
587
  Object.assign(packageJson.scripts, {
588
588
  start: /*(docker ? "docker-compose up && " : "") + */ "node --loader ts-node/esm src/index.ts",
589
- typeorm: "node --loader ts-node/esm ./node_modules/typeorm/cli.js",
589
+ typeorm: "typeorm-ts-node-esm",
590
590
  });
591
591
  else
592
592
  Object.assign(packageJson.scripts, {
593
593
  start: /*(docker ? "docker-compose up && " : "") + */ "ts-node src/index.ts",
594
- typeorm: "node --require ts-node/register ./node_modules/typeorm/cli.js",
594
+ typeorm: "typeorm-ts-node-commonjs",
595
595
  });
596
596
  return JSON.stringify(packageJson, undefined, 3);
597
597
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IAirB3E,CAAC;IA/qBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACf,QAAQ,EACJ,8FAA8F;SACrG,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EACJ,4EAA4E;SACnF,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;YACxB,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,oDAAoD;SACjE,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,CAAC,UAAU,E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C9F,OAAO,EACH,yDAAyD;aAChE,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EACH,+DAA+D;aACtE,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAtrBD,kCAsrBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\ndatabase: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { getRepository } from \"typeorm\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id)\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOneBy({ id: request.params.id })\n await this.userRepository.remove(userToRemove)\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n dataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.4.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^4.0.3\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^1.13.1\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^4.0.4\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm:\n \"node --loader ts-node/esm ./node_modules/typeorm/cli.js\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm:\n \"node --require ts-node/register ./node_modules/typeorm/cli.js\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"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esContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\ndatabase: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { getRepository } from \"typeorm\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id)\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOneBy({ id: request.params.id })\n await this.userRepository.remove(userToRemove)\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n dataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.4.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^4.0.3\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^1.13.1\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^4.0.4\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
@@ -65,7 +65,7 @@ class MigrationGenerateCommand {
65
65
  const filename = timestamp + "-" + path.basename(fullPath) + extension;
66
66
  let dataSource = undefined;
67
67
  try {
68
- dataSource = CommandUtils_1.CommandUtils.loadDataSource(path.resolve(process_1.default.cwd(), args.dataSource));
68
+ dataSource = await CommandUtils_1.CommandUtils.loadDataSource(path.resolve(process_1.default.cwd(), args.dataSource));
69
69
  dataSource.setOptions({
70
70
  synchronize: false,
71
71
  migrationsRun: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationG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C,CAAA;QACxD,OAAO,CACH,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CACtE,CAAA;IACL,CAAC;CACJ;AApRD,4DAoRC","file":"MigrationGenerateCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport { camelCase } from \"../util/StringUtils\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { format } from \"@sqltools/formatter/lib/sqlFormatter\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport * as path from \"path\"\nimport process from \"process\"\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n command = \"migration:generate <path>\"\n describe =\n \"Generates a new migration file with sql needs to be executed to update schema.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n type: \"string\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe:\n \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe:\n \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const extension = args.outputJs ? \".js\" : \".ts\"\n const fullPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = timestamp + \"-\" + path.basename(fullPath) + extension\n\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const upSqls: string[] = [],\n downSqls: string[] = []\n\n try {\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach((upQuery) => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(\n upQuery.query,\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downQuery.query =\n MigrationGenerateCommand.prettifyQuery(\n downQuery.query,\n )\n })\n }\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n upSqls.push(\n \" await queryRunner.query(`\" +\n upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n upQuery.parameters,\n ) +\n \");\",\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downSqls.push(\n \" await queryRunner.query(`\" +\n downQuery.query.replace(\n new RegExp(\"`\", \"g\"),\n \"\\\\`\",\n ) +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n downQuery.parameters,\n ) +\n \");\",\n )\n })\n } finally {\n await dataSource.destroy()\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(\n chalk.green(`No changes in database schema were found`),\n )\n process.exit(0)\n } else {\n console.log(\n chalk.yellow(\n `No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`,\n ),\n )\n process.exit(1)\n }\n } else if (!args.path) {\n console.log(chalk.yellow(\"Please specify a migration path\"))\n process.exit(1)\n }\n\n const fileContent = args.outputJs\n ? MigrationGenerateCommand.getJavascriptTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n : MigrationGenerateCommand.getTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n\n if (args.check) {\n console.log(\n chalk.yellow(\n `Unexpected changes in database schema were found in check mode:\\n\\n${chalk.white(\n fileContent,\n )}`,\n ),\n )\n process.exit(1)\n }\n\n if (args.dryrun) {\n console.log(\n chalk.green(\n `Migration ${chalk.blue(\n fullPath + extension,\n )} has content:\\n\\n${chalk.white(fileContent)}`,\n ),\n )\n } else {\n await CommandUtils.createFile(\n path.dirname(fullPath) + \"/\" + filename,\n fileContent,\n )\n\n console.log(\n chalk.green(\n `Migration ${chalk.blue(\n fullPath + extension,\n )} has been generated successfully.`,\n ),\n )\n }\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration generation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\"\n }\n\n return `, ${JSON.stringify(parameters)}`\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `import { MigrationInterface, QueryRunner } from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" })\n return (\n \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \"\n )\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,qDAA+C;AAE/C,0DAAyB;AACzB,uEAA6D;AAC7D,6DAAyD;AAEzD,mDAA4B;AAC5B,8DAA6B;AAE7B;;GAEG;AACH,MAAa,wBAAwB;IAArC;QACI,YAAO,GAAG,2BAA2B,CAAA;QACrC,aAAQ,GACJ,gFAAgF,CAAA;IAiRxF,CAAC;IA/QG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,QAAQ;YACd,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,4BAA4B;SACzC,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,+DAA+D;SACtE,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,0EAA0E;SACjF,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,OAAO;YACd,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,kHAAkH;SACzH,CAAC;aACD,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GzB,MAAM,CAAC,IAAI,CAAC;CACb,CAAC;;;;EAIA,QAAQ,CAAC,IAAI,CAAC;CACf,CAAC;;;CAGD,CAAA;IACG,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,aAAa,CAAC,KAAa;QACxC,MAAM,cAAc,GAAG,IAAA,qBAAM,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QACxD,OAAO,CACH,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CACtE,CAAA;IACL,CAAC;CACJ;AApRD,4DAoRC","file":"MigrationGenerateCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport { camelCase } from \"../util/StringUtils\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { format } from \"@sqltools/formatter/lib/sqlFormatter\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport * as path from \"path\"\nimport process from \"process\"\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n command = \"migration:generate <path>\"\n describe =\n \"Generates a new migration file with sql needs to be executed to update schema.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n type: \"string\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe:\n \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe:\n \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const extension = args.outputJs ? \".js\" : \".ts\"\n const fullPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = timestamp + \"-\" + path.basename(fullPath) + extension\n\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 synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const upSqls: string[] = [],\n downSqls: string[] = []\n\n try {\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach((upQuery) => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(\n upQuery.query,\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downQuery.query =\n MigrationGenerateCommand.prettifyQuery(\n downQuery.query,\n )\n })\n }\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n upSqls.push(\n \" await queryRunner.query(`\" +\n upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n upQuery.parameters,\n ) +\n \");\",\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downSqls.push(\n \" await queryRunner.query(`\" +\n downQuery.query.replace(\n new RegExp(\"`\", \"g\"),\n \"\\\\`\",\n ) +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n downQuery.parameters,\n ) +\n \");\",\n )\n })\n } finally {\n await dataSource.destroy()\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(\n chalk.green(`No changes in database schema were found`),\n )\n process.exit(0)\n } else {\n console.log(\n chalk.yellow(\n `No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`,\n ),\n )\n process.exit(1)\n }\n } else if (!args.path) {\n console.log(chalk.yellow(\"Please specify a migration path\"))\n process.exit(1)\n }\n\n const fileContent = args.outputJs\n ? MigrationGenerateCommand.getJavascriptTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n : MigrationGenerateCommand.getTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n\n if (args.check) {\n console.log(\n chalk.yellow(\n `Unexpected changes in database schema were found in check mode:\\n\\n${chalk.white(\n fileContent,\n )}`,\n ),\n )\n process.exit(1)\n }\n\n if (args.dryrun) {\n console.log(\n chalk.green(\n `Migration ${chalk.blue(\n fullPath + extension,\n )} has content:\\n\\n${chalk.white(fileContent)}`,\n ),\n )\n } else {\n await CommandUtils.createFile(\n path.dirname(fullPath) + \"/\" + filename,\n fileContent,\n )\n\n console.log(\n chalk.green(\n `Migration ${chalk.blue(\n fullPath + extension,\n )} has been generated successfully.`,\n ),\n )\n }\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration generation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\"\n }\n\n return `, ${JSON.stringify(parameters)}`\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `import { MigrationInterface, QueryRunner } from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" })\n return (\n \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \"\n )\n }\n}\n"],"sourceRoot":".."}
@@ -31,7 +31,7 @@ class MigrationRevertCommand {
31
31
  var _a;
32
32
  let dataSource = undefined;
33
33
  try {
34
- dataSource = CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
34
+ dataSource = await CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
35
35
  dataSource.setOptions({
36
36
  subscribers: [],
37
37
  synchronize: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,sBAAsB;IAAnC;QACI,YAAO,GAAG,kBAAkB,CAAA;QAC5B,aAAQ,GAAG,kCAAkC,CAAA;IA+DjD,CAAC;IA7DG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,aAAa,EAAE;YACnB,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,SAAS;YAClB,QAAQ,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AC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAjED,wDAiEC","file":"MigrationRevertCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n command = \"migration:revert\"\n describe = \"Reverts last executed migration.\"\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 revert. Enabled by default.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = 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 }\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.undoLastMigration(options)\n await dataSource.destroy()\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during migration revert:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,sBAAsB;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AM,CAAA;oBAC5B,MAAK;gBACT,QAAQ;gBACR,OAAO;aACV;YAED,MAAM,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;YAC3C,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1C,6BAAa,CAAC,SAAS,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;YAC9D,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAjED,wDAiEC","file":"MigrationRevertCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n command = \"migration:revert\"\n describe = \"Reverts last executed migration.\"\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 revert. Enabled by default.\",\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 }\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.undoLastMigration(options)\n await dataSource.destroy()\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during migration revert:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -31,7 +31,7 @@ class MigrationRunCommand {
31
31
  var _a;
32
32
  let dataSource = undefined;
33
33
  try {
34
- dataSource = CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process.cwd(), args.dataSource));
34
+ dataSource = await CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process.cwd(), args.dataSource));
35
35
  dataSource.setOptions({
36
36
  subscribers: [],
37
37
  synchronize: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationRunCommand.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,yDAAkC;AAElC,6DAAyD;AAEzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,mBAAmB;IAAhC;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GAAG,8BAA8B,CAAA;IAkE7C,CAAC;IAhEG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,aAAa,EAAE;YACnB,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,SAAS;YAClB,QAAQ,EACJ,uFAAuF;SAC9F,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,2BAAY,CAAC,cAAc,CACpC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,EAAE;gBACf,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;aACxC,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAE7B,MAAM,OAAO,GAAG;gBACZ,WAAW,EACP,MAAA,UAAU,CAAC,OAAO,CAAC,yBAAyB,mCAC3C,KAAiC;aACzC,CAAA;YAED,QAAQ,IAAI,CAAC,CAAC,EAAE;gBACZ,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;aACV;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;SAClB;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1C,6BAAa,CAAC,SAAS,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;YAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AApED,kDAoEC","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 }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = 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 }\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 if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during migration run:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationRunCommand.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,yDAAkC;AAElC,6DAAyD;AAEzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,mBAAmB;IAAhC;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GAAG,8BAA8B,CAAA;IAkE7C,CAAC;IAhEG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACj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AClB;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1C,6BAAa,CAAC,SAAS,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;YAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AApED,kDAoEC","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 }\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 }\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 if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during migration run:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -24,7 +24,7 @@ class MigrationShowCommand {
24
24
  async handler(args) {
25
25
  let dataSource = undefined;
26
26
  try {
27
- dataSource = CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process.cwd(), args.dataSource));
27
+ dataSource = await CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process.cwd(), args.dataSource));
28
28
  dataSource.setOptions({
29
29
  subscribers: [],
30
30
  synchronize: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationShowCommand.ts"],"names":[],"mappings":";;;;AACA,yDAAkC;AAElC,6DAAyD;AACzD,wDAAuB;AACvB,iDAA6C;AAE7C;;GAEG;AACH,MAAa,oBAAoB;IAAjC;QACI,YAAO,GAAG,gBAAgB,CAAA;QAC1B,aAAQ,GAAG,2DAA2D,CAAA;IAmC1E,CAAC;IAjCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,2BAAY,CAAC,cAAc,CACpC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,EAAE;gBACf,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,QAAQ,CAAC;aACtB,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,cAAc,EAAE,CAAA;YACjC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAC1C,6BAAa,CAAC,SAAS,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAA;YAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AArCD,oDAqCC","file":"MigrationShowCommand.js","sourcesContent":["import { DataSource } from \"../data-source\"\nimport * as process from \"process\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Shows all migrations and whether they have been run or not.\n */\nexport class MigrationShowCommand implements yargs.CommandModule {\n command = \"migration:show\"\n describe = \"Show all migrations and whether they have been run or not\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = 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: [\"schema\"],\n })\n await dataSource.initialize()\n await dataSource.showMigrations()\n await dataSource.destroy()\n\n process.exit(0)\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n PlatformTools.logCmdErr(\"Error during migration show:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationShowCommand.ts"],"names":[],"mappings":";;;;AACA,yDAAkC;AAElC,6DAAyD;AACzD,wDAAuB;AACvB,iDAA6C;AAE7C;;GAEG;AACH,MAAa,oBAAoB;IAAjC;QACI,YAAO,GAAG,gBAAgB,CAAA;QAC1B,aAAQ,GAAG,2DAA2D,CAAA;IAmC1E,CAAC;IAjCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,EAAE;gBACf,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,QAAQ,CAAC;aACtB,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,cAAc,EAAE,CAAA;YACjC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAC1C,6BAAa,CAAC,SAAS,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAA;YAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AArCD,oDAqCC","file":"MigrationShowCommand.js","sourcesContent":["import { DataSource } from \"../data-source\"\nimport * as process from \"process\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Shows all migrations and whether they have been run or not.\n */\nexport class MigrationShowCommand implements yargs.CommandModule {\n command = \"migration:show\"\n describe = \"Show all migrations and whether they have been run or not\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\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: [\"schema\"],\n })\n await dataSource.initialize()\n await dataSource.showMigrations()\n await dataSource.destroy()\n\n process.exit(0)\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n PlatformTools.logCmdErr(\"Error during migration show:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -31,7 +31,7 @@ class QueryCommand {
31
31
  let queryRunner = undefined;
32
32
  let dataSource = undefined;
33
33
  try {
34
- dataSource = CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
34
+ dataSource = await CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
35
35
  dataSource.setOptions({
36
36
  synchronize: false,
37
37
  migrationsRun: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/QueryCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AAEzD,0DAAyB;AACzB,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,YAAY;IAAzB;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GACJ,kHAAkH,CAAA;IAiE1H,CAAC;IA/DG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,OAAO,EAAE;YACjB,QAAQ,EAAE,sBAAsB;YAChC,IAAI,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AAE,CAAC,CAAC,CAC5C,CACJ,CAAA;aACJ;YAED,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;YAC3B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,WAAW;gBAAE,MAAO,WAA2B,CAAC,OAAO,EAAE,CAAA;YAC7D,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1C,6BAAa,CAAC,SAAS,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAA;YAC7D,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AApED,oCAoEC","file":"QueryCommand.js","sourcesContent":["import { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Executes an SQL query on the given dataSource.\n */\nexport class QueryCommand implements yargs.CommandModule {\n command = \"query [query]\"\n describe =\n \"Executes given SQL query on a default dataSource. Specify connection name to run query on a specific dataSource.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"query\", {\n describe: \"The SQL Query to run\",\n type: \"string\",\n })\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let queryRunner: QueryRunner | undefined = undefined\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n // create a query runner and execute query using it\n queryRunner = dataSource.createQueryRunner()\n const query = args.query as string\n console.log(\n chalk.green(\"Running query: \") +\n PlatformTools.highlightSql(query),\n )\n const queryResult = await queryRunner.query(query)\n\n if (typeof queryResult === \"undefined\") {\n console.log(\n chalk.green(\n \"Query has been executed. No result was returned.\",\n ),\n )\n } else {\n console.log(chalk.green(\"Query has been executed. Result: \"))\n console.log(\n PlatformTools.highlightJson(\n JSON.stringify(queryResult, undefined, 2),\n ),\n )\n }\n\n await queryRunner.release()\n await dataSource.destroy()\n } catch (err) {\n if (queryRunner) await (queryRunner as QueryRunner).release()\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during query execution:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/QueryCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AAEzD,0DAAyB;AACzB,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,YAAY;IAAzB;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GACJ,kHAAkH,CAAA;IAiE1H,CAAC;IA/DG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,OAAO,EAAE;YACjB,QAAQ,EAAE,sBAAsB;YAChC,IAAI,EAAE,QAAQ;SACjB,CAAC;aACD,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,WAAW,GAA4B,SAAS,CAAA;QACpD,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,KAAK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\"../query-runner/QueryRunner\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Executes an SQL query on the given dataSource.\n */\nexport class QueryCommand implements yargs.CommandModule {\n command = \"query [query]\"\n describe =\n \"Executes given SQL query on a default dataSource. Specify connection name to run query on a specific dataSource.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"query\", {\n describe: \"The SQL Query to run\",\n type: \"string\",\n })\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let queryRunner: QueryRunner | undefined = undefined\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 synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n // create a query runner and execute query using it\n queryRunner = dataSource.createQueryRunner()\n const query = args.query as string\n console.log(\n chalk.green(\"Running query: \") +\n PlatformTools.highlightSql(query),\n )\n const queryResult = await queryRunner.query(query)\n\n if (typeof queryResult === \"undefined\") {\n console.log(\n chalk.green(\n \"Query has been executed. No result was returned.\",\n ),\n )\n } else {\n console.log(chalk.green(\"Query has been executed. Result: \"))\n console.log(\n PlatformTools.highlightJson(\n JSON.stringify(queryResult, undefined, 2),\n ),\n )\n }\n\n await queryRunner.release()\n await dataSource.destroy()\n } catch (err) {\n if (queryRunner) await (queryRunner as QueryRunner).release()\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during query execution:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -26,7 +26,7 @@ class SchemaDropCommand {
26
26
  async handler(args) {
27
27
  let dataSource = undefined;
28
28
  try {
29
- dataSource = CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
29
+ dataSource = await CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
30
30
  dataSource.setOptions({
31
31
  synchronize: false,
32
32
  migrationsRun: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/SchemaDropCommand.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,iBAAiB;IAA9B;QACI,YAAO,GAAG,aAAa,CAAA;QACvB,aAAQ,GACJ,+DAA+D;YAC/D,kEAAkE,CAAA;IAoC1E,CAAC;IAlCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,2BAAY,CAAC,cAAc,CACpC,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;aAC/B,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,YAAY,EAAE,CAAA;YAC/B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAChE,CAAA;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAC1C,6BAAa,CAAC,SAAS,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAA;YACzD,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAxCD,8CAwCC","file":"SchemaDropCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Drops all tables of the database from the given dataSource.\n */\nexport class SchemaDropCommand implements yargs.CommandModule {\n command = \"schema:drop\"\n describe =\n \"Drops all tables in the database on your default dataSource. \" +\n \"To drop table of a concrete connection's database use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"schema\"],\n })\n await dataSource.initialize()\n await dataSource.dropDatabase()\n await dataSource.destroy()\n\n console.log(\n chalk.green(\"Database schema has been successfully dropped.\"),\n )\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n PlatformTools.logCmdErr(\"Error during schema drop:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/SchemaDropCommand.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;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\"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Drops all tables of the database from the given dataSource.\n */\nexport class SchemaDropCommand implements yargs.CommandModule {\n command = \"schema:drop\"\n describe =\n \"Drops all tables in the database on your default dataSource. \" +\n \"To drop table of a concrete connection's database use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\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 synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"schema\"],\n })\n await dataSource.initialize()\n await dataSource.dropDatabase()\n await dataSource.destroy()\n\n console.log(\n chalk.green(\"Database schema has been successfully dropped.\"),\n )\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n PlatformTools.logCmdErr(\"Error during schema drop:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -27,7 +27,7 @@ class SchemaLogCommand {
27
27
  async handler(args) {
28
28
  let dataSource = undefined;
29
29
  try {
30
- dataSource = CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
30
+ dataSource = await CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
31
31
  dataSource.setOptions({
32
32
  synchronize: false,
33
33
  migrationsRun: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/SchemaLogCommand.ts"],"names":[],"mappings":";;;;AACA,iDAAyC;AAEzC,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,gBAAgB;IAA7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gBACD,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,MAAM,CAAC,IAAI,CACb,iEAAiE,eAAK,CAAC,KAAK,CACxE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,CAC1C,IAAI,CACR,CACJ,CAAA;gBACD,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,MAAM,CACR,iEAAiE;oBAC7D,gBAAgB,CACvB,CACJ,CAAA;gBAED,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;oBACtC,IAAI,SAAS,GAAG,OAAO,CAAC,KAAK,CAAA;oBAC7B,SAAS,GAAG,SAAS,CAAC,IAAI,EAAE,CAAA;oBAC5B,SAAS;wBACL,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;4BACxB,CAAC,CAAC,SAAS;4BACX,CAAC,CAAC,SAAS,GAAG,GAAG,CAAA;oBACzB,OAAO,CAAC,GAAG,CAAC,IAAA,yBAAS,EAAC,SAAS,CAAC,CAAC,CAAA;gBACrC,CAAC,CAAC,CAAA;aACL;YACD,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBACV,6BAAa,CAAC,SAAS,CACnB,sCAAsC,EACtC,GAAG,CACN,CAAA;YACL,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AApFD,4CAoFC","file":"SchemaLogCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport { highlight } from \"cli-highlight\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Shows sql to be executed by schema:sync command.\n */\nexport class SchemaLogCommand implements yargs.CommandModule {\n command = \"schema:log\"\n describe =\n \"Shows sql to be executed by schema:sync command. It shows sql log only for your default dataSource. \" +\n \"To run update queries on a concrete connection use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (sqlInMemory.upQueries.length === 0) {\n console.log(\n chalk.yellow(\n \"Your schema is up to date - there are no queries to be executed by schema synchronization.\",\n ),\n )\n } else {\n const lengthSeparators = String(sqlInMemory.upQueries.length)\n .split(\"\")\n .map((char) => \"-\")\n .join(\"\")\n console.log(\n chalk.yellow(\n \"---------------------------------------------------------------\" +\n lengthSeparators,\n ),\n )\n console.log(\n chalk.yellow.bold(\n `-- Schema synchronization will execute following sql queries (${chalk.white(\n sqlInMemory.upQueries.length.toString(),\n )}):`,\n ),\n )\n console.log(\n chalk.yellow(\n \"---------------------------------------------------------------\" +\n lengthSeparators,\n ),\n )\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n let sqlString = upQuery.query\n sqlString = sqlString.trim()\n sqlString =\n sqlString.substr(-1) === \";\"\n ? sqlString\n : sqlString + \";\"\n console.log(highlight(sqlString))\n })\n }\n await dataSource.destroy()\n } catch (err) {\n if (dataSource)\n PlatformTools.logCmdErr(\n \"Error during schema synchronization:\",\n err,\n )\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/SchemaLogCommand.ts"],"names":[],"mappings":";;;;AACA,iDAAyC;AAEzC,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,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B,CACvB,CACJ,CAAA;gBACD,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,MAAM,CAAC,IAAI,CACb,iEAAiE,eAAK,CAAC,KAAK,CACxE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,CAC1C,IAAI,CACR,CACJ,CAAA;gBACD,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,MAAM,CACR,iEAAiE;oBAC7D,gBAAgB,CACvB,CACJ,CAAA;gBAED,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;oBACtC,IAAI,SAAS,GAAG,OAAO,CAAC,KAAK,CAAA;oBAC7B,SAAS,GAAG,SAAS,CAAC,IAAI,EAAE,CAAA;oBAC5B,SAAS;wBACL,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;4BACxB,CAAC,CAAC,SAAS;4BACX,CAAC,CAAC,SAAS,GAAG,GAAG,CAAA;oBACzB,OAAO,CAAC,GAAG,CAAC,IAAA,yBAAS,EAAC,SAAS,CAAC,CAAC,CAAA;gBACrC,CAAC,CAAC,CAAA;aACL;YACD,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBACV,6BAAa,CAAC,SAAS,CACnB,sCAAsC,EACtC,GAAG,CACN,CAAA;YACL,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AApFD,4CAoFC","file":"SchemaLogCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport { highlight } from \"cli-highlight\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Shows sql to be executed by schema:sync command.\n */\nexport class SchemaLogCommand implements yargs.CommandModule {\n command = \"schema:log\"\n describe =\n \"Shows sql to be executed by schema:sync command. It shows sql log only for your default dataSource. \" +\n \"To run update queries on a concrete connection use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\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 synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (sqlInMemory.upQueries.length === 0) {\n console.log(\n chalk.yellow(\n \"Your schema is up to date - there are no queries to be executed by schema synchronization.\",\n ),\n )\n } else {\n const lengthSeparators = String(sqlInMemory.upQueries.length)\n .split(\"\")\n .map((char) => \"-\")\n .join(\"\")\n console.log(\n chalk.yellow(\n \"---------------------------------------------------------------\" +\n lengthSeparators,\n ),\n )\n console.log(\n chalk.yellow.bold(\n `-- Schema synchronization will execute following sql queries (${chalk.white(\n sqlInMemory.upQueries.length.toString(),\n )}):`,\n ),\n )\n console.log(\n chalk.yellow(\n \"---------------------------------------------------------------\" +\n lengthSeparators,\n ),\n )\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n let sqlString = upQuery.query\n sqlString = sqlString.trim()\n sqlString =\n sqlString.substr(-1) === \";\"\n ? sqlString\n : sqlString + \";\"\n console.log(highlight(sqlString))\n })\n }\n await dataSource.destroy()\n } catch (err) {\n if (dataSource)\n PlatformTools.logCmdErr(\n \"Error during schema synchronization:\",\n err,\n )\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -26,7 +26,7 @@ class SchemaSyncCommand {
26
26
  async handler(args) {
27
27
  let dataSource = undefined;
28
28
  try {
29
- dataSource = CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
29
+ dataSource = await CommandUtils_1.CommandUtils.loadDataSource(path_1.default.resolve(process_1.default.cwd(), args.dataSource));
30
30
  dataSource.setOptions({
31
31
  synchronize: false,
32
32
  migrationsRun: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/SchemaSyncCommand.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,iBAAiB;IAA9B;QACI,YAAO,GAAG,aAAa,CAAA;QACvB,aAAQ,GACJ,8GAA8G;YAC9G,+DAA+D,CAAA;IAqCvE,CAAC;IAnCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,2BAAY,CAAC,cAAc,CACpC,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;aAC/B,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,WAAW,EAAE,CAAA;YAC9B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAC/D,CAAA;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1C,6BAAa,CAAC,SAAS,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAA;YACpE,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAzCD,8CAyCC","file":"SchemaSyncCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Synchronizes database schema with entities.\n */\nexport class SchemaSyncCommand implements yargs.CommandModule {\n command = \"schema:sync\"\n describe =\n \"Synchronizes your entities with database schema. It runs schema update queries on all connections you have. \" +\n \"To run update queries on a concrete connection use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"schema\"],\n })\n await dataSource.initialize()\n await dataSource.synchronize()\n await dataSource.destroy()\n\n console.log(\n chalk.green(\"Schema synchronization finished successfully.\"),\n )\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during schema synchronization:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/SchemaSyncCommand.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,iBAAiB;IAA9B;QACI,YAAO,GAAG,aAAa,CAAA;QACvB,aAAQ,GACJ,8GAA8G;YAC9G,+DAA+D,CAAA;IAqCvE,CAAC;IAnCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;aAC/B,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,WAAW,EAAE,CAAA;YAC9B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAC/D,CAAA;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1C,6BAAa,CAAC,SAAS,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAA;YACpE,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAzCD,8CAyCC","file":"SchemaSyncCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Synchronizes database schema with entities.\n */\nexport class SchemaSyncCommand implements yargs.CommandModule {\n command = \"schema:sync\"\n describe =\n \"Synchronizes your entities with database schema. It runs schema update queries on all connections you have. \" +\n \"To run update queries on a concrete connection use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\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 synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"schema\"],\n })\n await dataSource.initialize()\n await dataSource.synchronize()\n await dataSource.destroy()\n\n console.log(\n chalk.green(\"Schema synchronization finished successfully.\"),\n )\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during schema synchronization:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -415,7 +415,7 @@ class PostgresDriver {
415
415
  return DateUtils_1.DateUtils.mixedDateToDate(value);
416
416
  }
417
417
  else if (["json", "jsonb", ...this.spatialTypes].indexOf(columnMetadata.type) >= 0) {
418
- return value; // JSON.stringify()
418
+ return JSON.stringify(value);
419
419
  }
420
420
  else if (columnMetadata.type === "hstore") {
421
421
  if (typeof value === "string") {