typeorm / typeorm

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
http://typeorm.io
MIT License
33.78k stars 6.25k forks source link

getDatabases() is not implemented in MySQL or Postgres #4489

Open burkeallen opened 5 years ago

burkeallen commented 5 years ago

Issue type:

[ ] question [x ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [x ] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[ ] latest [ ] @next [x] 0.2.18

Steps to reproduce or a small repository showing the problem:

when attempting to use getDatabases() from inside a migration file, the method always returns an empty array []. Migrations against the default Database run fine.

our use case is needing to update 1-n databases for a multi-tenant scenario, we would like to grab all databases from the method and then iterate through each one applying the same migration up/down logic.

example code to reproduce the issue.

`import {MigrationInterface, QueryRunner} from 'typeorm';

export class MigrationOne1564078353345 implements MigrationInterface {

async up(queryRunner: QueryRunner): Promise { const schemas = await queryRunner.getDatabases(); console.log('#databases = ' + schemas.length); }

async down(queryRunner: QueryRunner): Promise { // do stuff here }

}`

ormconfig

{ name: this.config.get('aws').rdsDatabaseMasterSchema, type: 'mysql', host: this.config.get('aws').rdsDatabaseInstanceEndpoint, port: this.config.get('aws').rdsDatabaseInstancePort, username: this.config.get('aws').rdsDatabaseInstanceUser, password: this.config.get('aws').rdsDatabaseInstanceUserPassword, // TODO: Make this dynamic using roles database: this.config.get('aws').rdsDatabaseMasterSchema, entities: [__dirname + '/../entities/*{.ts,.js}'], synchronize: false, migrationsRun: true, migrationsTableName: 'database_migrations', migrations: [ __dirname + '/../migrations/*{.ts,.js}', ], cli: { entitiesDir: __dirname + '/../entities/', migrationsDir: __dirname + '/../migrations', } };

nikluwfy commented 4 years ago

https://github.com/typeorm/typeorm/blob/685d76b20464388c6f86c7d268770577452124b6/src/driver/mysql/MysqlQueryRunner.ts#L201

    /**
     * Returns all available database names including system databases.
     */
    async getDatabases(): Promise<string[]> {
        return Promise.resolve([]);
    }
abeebola commented 1 year ago

Still nothing?