@mikro-orm/mssql 7.1.0-dev.20 → 7.1.0-dev.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,8 +21,29 @@ export class MsSqlSchemaHelper extends SchemaHelper {
21
21
  return 'master';
22
22
  }
23
23
  getDropDatabaseSQL(name) {
24
+ // `set offline` rejects all connections including the issuing session, so there is no
25
+ // single-user race window where a torn-down pool connection can reconnect between the
26
+ // mode switch and the drop (SQL Server error 3702 "currently in use"). Dropping an
27
+ // offline database leaves the underlying `.mdf`/`.ldf` files behind though, which
28
+ // makes a subsequent `create database` with the same name fail with error 5170
29
+ // ("file already exists"). Capture the physical paths up front and call
30
+ // `master.sys.xp_delete_files` after the drop to clean them up.
24
31
  const quoted = this.quote(name);
25
- return `if db_id(${this.platform.quoteValue(name)}) is not null begin alter database ${quoted} set single_user with rollback immediate; drop database ${quoted}; end`;
32
+ const literal = this.platform.quoteValue(name);
33
+ return (`if db_id(${literal}) is not null begin ` +
34
+ `declare @drop_files table (path nvarchar(260)); ` +
35
+ `insert into @drop_files (path) select physical_name from sys.master_files where database_id = db_id(${literal}); ` +
36
+ `alter database ${quoted} set offline with rollback immediate; ` +
37
+ `drop database ${quoted}; ` +
38
+ `declare @drop_path nvarchar(260); ` +
39
+ `declare drop_files_cursor cursor local fast_forward for select path from @drop_files; ` +
40
+ `open drop_files_cursor; fetch next from drop_files_cursor into @drop_path; ` +
41
+ `while @@fetch_status = 0 begin ` +
42
+ `begin try exec master.sys.xp_delete_files @drop_path; end try begin catch end catch; ` +
43
+ `fetch next from drop_files_cursor into @drop_path; ` +
44
+ `end ` +
45
+ `close drop_files_cursor; deallocate drop_files_cursor; ` +
46
+ `end`);
26
47
  }
27
48
  disableForeignKeysSQL() {
28
49
  return `exec sp_MSforeachtable 'alter table ? nocheck constraint all';`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mssql",
3
- "version": "7.1.0-dev.20",
3
+ "version": "7.1.0-dev.21",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -47,7 +47,7 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.1.0-dev.20",
50
+ "@mikro-orm/sql": "7.1.0-dev.21",
51
51
  "kysely": "0.28.16",
52
52
  "tarn": "3.0.2",
53
53
  "tedious": "19.2.1",
@@ -57,7 +57,7 @@
57
57
  "@mikro-orm/core": "^7.0.12"
58
58
  },
59
59
  "peerDependencies": {
60
- "@mikro-orm/core": "7.1.0-dev.20"
60
+ "@mikro-orm/core": "7.1.0-dev.21"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">= 22.17.0"