Skip to content

Driver gaps surfaced by the integration suite: checkDatabase (cockroachdb, mongodb) and oracle create/drop #1423

Description

@tada5hi

Three pre-existing gaps that the driver suite added in #1422 ran into. None of them are regressions, and none are related to the schema-drift work — they are skipped there through capability predicates in test/data/typeorm/integration.ts, so each fix comes with a predicate to widen and the assertions turn on by themselves.

Filing them together because they were all found in one pass; happy to split.

1. checkDatabase throws on cockroachdb instead of reporting exists: false

checkDatabase derives exists from DataSource.initialize() failing:

// src/database/methods/check/module.ts
try {
    if (!dataSource.isInitialized) {
        await dataSource.initialize();
    }
} catch {
    result.exists = false;

    return result;
}

CockroachDB accepts a connection to a database which does not exist — the error only surfaces on the first query, so the schema probe a few lines further down throws instead:

QueryFailedError: database "typeorm_extension_integration" does not exist
    at CockroachQueryRunner.hasTable
    at checkDatabase (src/database/methods/check/module.ts:94)

A caller using checkDatabase to decide whether to create the database gets an exception rather than { exists: false }.

Reproduce: dropDatabase(...), then checkDatabase({ options }) against cockroachdb.

  • fix
  • widen supportsDatabaseExistenceCheck in test/data/typeorm/integration.ts

2. checkDatabase throws on mongodb

Same entry point, different cause — the mongo query runner does not implement the schema probe at all:

TypeORMError: Check schema queries are not supported by MongoDB driver.

Needs a decision on what schema: true should even mean for mongodb (collections are created lazily; MongoSchemaBuilder.build() only creates indices), which is why it is a gap rather than an oversight.

  • decide the semantics, then fix
  • widen supportsSchemaMetadata / supportsDatabaseExistenceCheck

3. oracle createDatabase emits invalid SQL, dropDatabase is a no-op

// src/database/core/oracle/statements.ts
export function buildOracleCreateDatabaseQuery(database: string): string {
    return `CREATE DATABASE IF NOT EXISTS ${database}`;
}

IF NOT EXISTS is not valid Oracle SQL — the existing code comment already flags this and preserves the statement byte-for-byte from the pre-refactor implementation, since changing it is a semantic decision rather than a refactor side effect. OracleDialect.drop() is a documented Promise.resolve().

Oracle also has no CREATE DATABASE in the sense the other drivers use it: what a consumer wants here is almost certainly a user/schema (CREATE USER … / DROP USER … CASCADE), which makes this an API-shape question, not just a broken statement.

  • decide what create/drop should mean for oracle
  • widen supportsDatabaseDrop

Note on coverage

src/database/adapters/** is excluded from the coverage gate, so none of this was visible before the driver suite existed. The suite now runs against postgres, cockroachdb, mysql, mariadb, mssql, mongodb and oracle in CI, which is where a fix for any of the above gets verified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions