Skip to content

Commit

Permalink
fix(schema): revert the dbName after dropping the database
Browse files Browse the repository at this point in the history
Closes #5583
  • Loading branch information
B4nan committed May 18, 2024
1 parent 567d65a commit 725f7e9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/knex/src/query/ObjectCriteriaNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export class ObjectCriteriaNode<T extends object> extends CriteriaNode<T> {
return;
}

/* istanbul ignore next */
if (key === '$and') {
o.$and.push({ [key]: value });
return;
Expand Down
1 change: 1 addition & 0 deletions packages/knex/src/schema/SqlSchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator<AbstractSqlDrive
this.config.set('dbName', this.helper.getManagementDbName());
await this.driver.reconnect();
await this.execute(this.helper.getDropDatabaseSQL(name));
this.config.set('dbName', name);
}

override async execute(sql: string, options: { wrap?: boolean; ctx?: Transaction } = {}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('SchemaGenerator', () => {
await orm.schema.ensureDatabase();
await orm.schema.dropDatabase(dbName);
await orm.close(true);
await expect(orm.schema.ensureDatabase()).rejects.toThrow('Unable to acquire a connection');
await orm.schema.ensureDatabase();
});

test('create schema also creates the database if not exists [mariadb]', async () => {
Expand All @@ -39,7 +39,6 @@ describe('SchemaGenerator', () => {
await orm.schema.createSchema();
await orm.schema.dropSchema({ wrap: false, dropMigrationsTable: false, dropDb: true });
await orm.close(true);
await expect(orm.schema.ensureDatabase()).rejects.toThrow('Unable to acquire a connection');
});

test('generate schema from metadata [mariadb]', async () => {
Expand Down

0 comments on commit 725f7e9

Please sign in to comment.