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U,CAAC,YAAY,EAAE,EAAA;;wBAA/B,SAA+B,CAAC;wBAChC,qBAAM,UAAU,CAAC,KAAK,EAAE,EAAA;;wBAAxB,SAAwB,CAAC;wBAEzB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC,CAAC;;;;6BAGvE,UAAU,EAAV,wBAAU;wBAAE,qBAAO,UAAyB,CAAC,KAAK,EAAE,EAAA;;wBAAxC,SAAwC,CAAC;;;wBAEzD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC;wBAC5D,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IACL,wBAAC;AAAD,CAjDA,AAiDC,IAAA;AAjDY,8CAAiB","file":"SchemaDropCommand.js","sourcesContent":["import {createConnection} from \"../index\";\nimport {Connection} from \"../connection/Connection\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport * as yargs from \"yargs\";\nconst chalk = require(\"chalk\");\n\n/**\n * Drops all tables of the database from the given connection.\n */\nexport class SchemaDropCommand implements yargs.CommandModule {\n    command = \"schema:drop\";\n    describe = \"Drops all tables in the database on your default connection. \" +\n        \"To drop table of a concrete connection's database 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 on which to drop all tables.\"\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: [\"query\", \"schema\"]\n            });\n            connection = await createConnection(connectionOptions);\n            await connection.dropDatabase();\n            await connection.close();\n\n            console.log(chalk.green(\"Database schema has been successfully dropped.\"));\n\n        } catch (err) {\n            if (connection) await (connection as Connection).close();\n\n            console.log(chalk.black.bgRed(\"Error during schema drop:\"));\n            console.error(err);\n            process.exit(1);\n        }\n    }\n}\n"],"sourceRoot":".."}