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A;;wBAAxB,SAAwB,CAAC;;;;wBAGzB,IAAI,UAAU;4BAEd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;wBACvE,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IACL,uBAAC;AAAD,CAhEA,AAgEC,IAAA;AAhEY,4CAAgB","file":"SchemaLogCommand.js","sourcesContent":["import {createConnection} from \"../index\";\nimport {Connection} from \"../connection/Connection\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {highlight} from \"cli-highlight\";\nimport * as yargs from \"yargs\";\n\nconst chalk = require(\"chalk\");\n\n/**\n * Shows sql to be executed by schema:sync command.\n */\nexport class SchemaLogCommand implements yargs.CommandModule {\n\n    command = \"schema:log\";\n    describe = \"Shows sql to be executed by schema:sync command. It shows sql log only for your default connection. \" +\n        \"To run update queries on a concrete connection use -c option.\";\n\n    builder(args: yargs.Argv) {\n        return args\n            .option(\"c\", {\n                alias: \"connection\",\n                default: \"default\",\n                describe: \"Name of the connection of which schema sync log should be shown.\"\n            })\n            .option(\"f\", {\n                alias: \"config\",\n                default: \"ormconfig\",\n                describe: \"Name of the file with connection configuration.\"\n            });\n    }\n\n    async handler(args: yargs.Arguments) {\n\n        let connection: Connection|undefined = undefined;\n        try {\n\n            const connectionOptionsReader = new ConnectionOptionsReader({\n                root: process.cwd(),\n                configName: args.config as any\n            });\n            const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n            Object.assign(connectionOptions, {\n                synchronize: false,\n                migrationsRun: false,\n                dropSchema: false,\n                logging: false\n            });\n            connection = await createConnection(connectionOptions);\n            const sqlInMemory = await connection.driver.createSchemaBuilder().log();\n            if (sqlInMemory.upQueries.length === 0) {\n                console.log(chalk.yellow(\"Your schema is up to date - there are no queries to be executed by schema syncronization.\"));\n\n            } else {\n                const lengthSeparators = String(sqlInMemory.upQueries.length).split(\"\").map(char => \"-\").join(\"\");\n                console.log(chalk.yellow(\"---------------------------------------------------------------\" + lengthSeparators));\n                console.log(chalk.yellow.bold(`-- Schema syncronization will execute following sql queries (${chalk.white(sqlInMemory.upQueries.length)}):`));\n                console.log(chalk.yellow(\"---------------------------------------------------------------\" + lengthSeparators));\n\n                sqlInMemory.upQueries.forEach(upQuery => {\n                    let sqlString = upQuery.query;\n                    sqlString = sqlString.trim();\n                    sqlString = sqlString.substr(-1) === \";\" ? sqlString : sqlString + \";\";\n                    console.log(highlight(sqlString));\n                });\n            }\n            await connection.close();\n\n        } catch (err) {\n            if (connection)\n\n            console.log(chalk.black.bgRed(\"Error during schema synchronization:\"));\n            console.error(err);\n            process.exit(1);\n        }\n    }\n}\n"],"sourceRoot":".."}