فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(a02): preflight SQL Express data-file size limits for 10GB legacy and 50GB SQL 2025 editions
davoodmehraban89 committed
Oct 30, 2026 at 20:49 UTC
ab43ab0660a0ef92646b896f68dce8a07fcc48c6
1 file changed
+69
-1
scripts/a02-isolated-sql-restore.ps1
+69
-1
@@ -94,6 +94,8 @@ function New-LocalRestorePlan(
94
$data = 0
95
$logs = 0
96
$totalBytes = [long]0
97
+ $dataBytes = [long]0
98
+ $logBytes = [long]0
99
foreach ($file in $Files) {
100
$logical = [string]$file.LogicalName
101
$type = [string]$file.Type
@@ -117,6 +119,7 @@ function New-LocalRestorePlan(
119
throw 'A02_FILELIST_SIZE_OVERFLOW'
120
}
121
$totalBytes += $size
122
+ if ($type -eq 'D') { $dataBytes += $size } else { $logBytes += $size }
123
$filename = $DatabaseName + '_file' + ($moves.Count + 1).ToString('00') + $ext
124
$target = [System.IO.Path]::Combine($directory, $filename)
125
$null = Assert-LocalPathShape $target
@@ -142,6 +145,8 @@ function New-LocalRestorePlan(
145
DatabaseName = $DatabaseName
146
Moves = @($moves)
147
TotalBytes = $totalBytes
148
+ DataBytes = $dataBytes
149
+ LogBytes = $logBytes
150
VerifySql = $verify
151
RestoreSql = $restore
152
RestoreExecuted = $false
@@ -219,6 +224,21 @@ function Assert-DestinationDiskSpace($Plan) {
224
}
225
}
226
227
+function Get-ExpressDataLimitBytes([int]$Major,[int]$EngineEdition) {
228
+ if ($EngineEdition -ne 4) { return [long]0 }
229
+ if ($Major -ge 11 -and $Major -le 16) { return [long]10GB }
230
+ if ($Major -eq 17) { return [long]50GB }
231
+ throw 'A02_EXPRESS_LIMIT_VERSION_UNSUPPORTED'
232
+}
233
+
234
+function Assert-ExpressDatabaseSizeLimit($Plan,[int]$Major,[int]$EngineEdition) {
235
+ $limit = Get-ExpressDataLimitBytes $Major $EngineEdition
236
+ if ($limit -gt 0 -and [long]$Plan.DataBytes -gt $limit) {
237
+ throw 'A02_EXPRESS_DATABASE_SIZE_LIMIT_EXCEEDED'
238
+ }
239
+ return [long]$limit
240
+}
241
+
242
function Invoke-SelfTest {
243
$name = 'FinoraHoloo_0123456789abcdef0123456789abcdef'
244
$files = @(
@@ -230,7 +250,43 @@ function Invoke-SelfTest {
250
-not $p.RestoreSql.Contains("Data'';DROP DATABASE master;--") -or
251
$p.RestoreSql -match '(?i)\bWITH\s+REPLACE\b' -or
252
($p.RestoreSql.Split([string[]]@('RESTORE DATABASE'), [System.StringSplitOptions]::None)).Count -ne 2 -or
233
- $p.Moves.Count -ne 2) { throw 'A02_SELFTEST_SQL_PLAN' }
253
+ $p.Moves.Count -ne 2 -or $p.DataBytes -ne 1024 -or $p.LogBytes -ne 2048) {
254
+ throw 'A02_SELFTEST_SQL_PLAN'
255
+ }
256
+ if ((Get-ExpressDataLimitBytes 16 4) -ne 10GB -or
257
+ (Get-ExpressDataLimitBytes 17 4) -ne 50GB -or
258
+ (Get-ExpressDataLimitBytes 16 2) -ne 0) {
259
+ throw 'A02_SELFTEST_EXPRESS_LIMIT_MAPPING'
260
+ }
261
+ $null = Assert-ExpressDatabaseSizeLimit $p 16 4
262
+ $limitFiles = @(
263
+ [pscustomobject]@{ LogicalName = 'Data'; Type = 'D'; Size = 10GB },
264
+ [pscustomobject]@{ LogicalName = 'Log'; Type = 'L'; Size = 2048 }
265
+ )
266
+ $atLimit = New-LocalRestorePlan 'D:\copy.bak' 'C:\Data' 'C:\Log' $name $limitFiles
267
+ $null = Assert-ExpressDatabaseSizeLimit $atLimit 16 4
268
+ $tooLargeFiles = @(
269
+ [pscustomobject]@{ LogicalName = 'Data'; Type = 'D'; Size = (10GB + 1) },
270
+ [pscustomobject]@{ LogicalName = 'Log'; Type = 'L'; Size = 2048 }
271
+ )
272
+ $tooLarge = New-LocalRestorePlan 'D:\copy.bak' 'C:\Data' 'C:\Log' $name $tooLargeFiles
273
+ $rejected = $false
274
+ try { $null = Assert-ExpressDatabaseSizeLimit $tooLarge 16 4 }
275
+ catch { $rejected = $true }
276
+ if (-not $rejected) { throw 'A02_SELFTEST_EXPRESS_10GB_LIMIT' }
277
+ $tooLarge2025Files = @(
278
+ [pscustomobject]@{ LogicalName = 'Data'; Type = 'D'; Size = (50GB + 1) },
279
+ [pscustomobject]@{ LogicalName = 'Log'; Type = 'L'; Size = 2048 }
280
+ )
281
+ $tooLarge2025 = New-LocalRestorePlan 'D:\copy.bak' 'C:\Data' 'C:\Log' $name $tooLarge2025Files
282
+ $rejected = $false
283
+ try { $null = Assert-ExpressDatabaseSizeLimit $tooLarge2025 17 4 }
284
+ catch { $rejected = $true }
285
+ if (-not $rejected) { throw 'A02_SELFTEST_EXPRESS_50GB_LIMIT' }
286
+ $unknownVersionRejected = $false
287
+ try { $null = Get-ExpressDataLimitBytes 18 4 }
288
+ catch { $unknownVersionRejected = $true }
289
+ if (-not $unknownVersionRejected) { throw 'A02_SELFTEST_UNKNOWN_EXPRESS_VERSION' }
290
foreach ($bad in @('relative\file.bak', '\\server\share\a.bak',
291
'C:\Private\..\file.bak', 'C:\Private\file.bak:ads', 'C:/Private/file.bak')) {
292
$rejected = $false
@@ -281,6 +337,8 @@ try {
337
$connection.Open()
338
$version = Invoke-SqlRows $connection @"
339
SELECT TRY_CAST(SERVERPROPERTY('ProductMajorVersion') AS int) AS Major,
340
+ CAST(SERVERPROPERTY('EngineEdition') AS int) AS EngineEdition,
341
+ CAST(SERVERPROPERTY('Edition') AS nvarchar(128)) AS Edition,
342
CAST(SERVERPROPERTY('InstanceName') AS nvarchar(128)) AS InstanceName,
343
CAST(SERVERPROPERTY('InstanceDefaultDataPath') AS nvarchar(4000)) AS DataDir,
344
CAST(SERVERPROPERTY('InstanceDefaultLogPath') AS nvarchar(4000)) AS LogDir;
@@ -290,7 +348,10 @@ SELECT TRY_CAST(SERVERPROPERTY('ProductMajorVersion') AS int) AS Major,
348
throw 'A02_SQL_INSTANCE_NOT_DEDICATED'
349
}
350
[int]$serverMajor = $version.Rows[0]['Major']
351
+ [int]$engineEdition = $version.Rows[0]['EngineEdition']
352
+ [string]$engineEditionName = [string]$version.Rows[0]['Edition']
353
if ($serverMajor -lt 11) { throw 'A02_SQL_INSTANCE_TOO_OLD' }
354
+ if ($engineEdition -le 0 -or [string]::IsNullOrWhiteSpace($engineEditionName)) { throw 'A02_SQL_ENGINE_EDITION_UNKNOWN' }
355
$dataPath = [string]$version.Rows[0]['DataDir']
356
$logPath = [string]$version.Rows[0]['LogDir']
357
if ($dataPath.EndsWith('\')) { $dataPath = $dataPath.TrimEnd('\') }
@@ -322,6 +383,7 @@ SELECT TRY_CAST(SERVERPROPERTY('ProductMajorVersion') AS int) AS Major,
383
$plan = New-LocalRestorePlan $localBackup $dataPath $logPath (
384
New-RandomDatabaseName
385
) @($files.Rows)
386
+ $expressLimitBytes = Assert-ExpressDatabaseSizeLimit $plan $serverMajor $engineEdition
387
Assert-DestinationDiskSpace $plan
388
Assert-PlanCollisionFree $connection $plan
389
Invoke-SqlCommand $connection $plan.VerifySql 1800
@@ -332,6 +394,10 @@ SELECT TRY_CAST(SERVERPROPERTY('ProductMajorVersion') AS int) AS Major,
394
[pscustomobject]@{
395
status = 'backup-verifyonly-passed'
396
sourceSqlMajor = $sourceMajor; engineSqlMajor = $serverMajor
397
+ engineEdition = $engineEditionName; engineEditionCode = $engineEdition
398
+ dataFileBytes = $plan.DataBytes; logFileBytes = $plan.LogBytes
399
+ expressDataLimitBytes = if ($expressLimitBytes -gt 0) { $expressLimitBytes } else { $null }
400
+ expressSizeLimitCheck = if ($expressLimitBytes -gt 0) { 'passed' } else { 'not-applicable' }
401
fileCount = $plan.Moves.Count; canImport = $false
402
restoreExecuted = $false; financialReconciled = $false
403
} | ConvertTo-Json -Compress
@@ -359,6 +425,8 @@ SELECT TRY_CAST(SERVERPROPERTY('ProductMajorVersion') AS int) AS Major,
425
[pscustomobject]@{
426
status = 'isolated-restore-completed-needs-mapping-and-reconciliation'
427
databaseName = $plan.DatabaseName
428
+ engineEdition = $engineEditionName
429
+ expressDataLimitBytes = if ($expressLimitBytes -gt 0) { $expressLimitBytes } else { $null }
430
tableCount = [int]$schema.Rows[0]['TableCount']
431
columnCount = [int]$schema.Rows[0]['ColumnCount']
432
canImport = $false; financialReconciled = $false