UNPKG

@authup/server-api

Version:

This is a standalone application.

69 lines 2.77 kB
"use strict"; /* * Copyright (c) 2022. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MigrationGenerateCommand = void 0; const node_path_1 = __importDefault(require("node:path")); const typeorm_extension_1 = require("typeorm-extension"); const typeorm_1 = require("typeorm"); const config_1 = require("../../config"); const database_1 = require("../../database"); class MigrationGenerateCommand { constructor() { this.command = 'migration:generate'; this.describe = 'Generate database migrations.'; } async handler(args) { const config = await (0, config_1.setupConfig)(); const connections = [ { type: 'postgres', database: 'migrations', host: 'localhost', port: 5432, username: 'postgres', password: 'start123', }, { type: 'mysql', database: 'migrations', host: 'localhost', port: 3306, username: 'root', password: 'start123', }, { type: 'better-sqlite3', database: node_path_1.default.join(config.get('writableDirectoryPath'), 'migrations.sql'), }, ]; const baseDirectory = node_path_1.default.join(__dirname, '..', '..', 'database', 'migrations'); const timestamp = Date.now(); for (let i = 0; i < connections.length; i++) { const dataSourceOptions = await (0, database_1.extendDataSourceOptions)(connections[i]); const directoryPath = node_path_1.default.join(baseDirectory, dataSourceOptions.type); await (0, typeorm_extension_1.dropDatabase)({ options: dataSourceOptions }); await (0, typeorm_extension_1.createDatabase)({ options: dataSourceOptions, synchronize: false }); const dataSource = new typeorm_1.DataSource(dataSourceOptions); await dataSource.initialize(); await dataSource.runMigrations(); await (0, typeorm_extension_1.generateMigration)({ dataSource, name: 'Default', directoryPath, timestamp, prettify: true, }); } process.exit(0); } } exports.MigrationGenerateCommand = MigrationGenerateCommand; //# sourceMappingURL=migration-generate.js.map