feat: add MySqlOperationService for archive extraction, query execution, and database management

This commit is contained in:
Ümit Tunç
2026-03-30 08:35:10 +03:00
parent ca566576ed
commit 57f85fe2a2
@@ -2,6 +2,7 @@ import fs from 'fs'
import path from 'path' import path from 'path'
import { spawn } from 'child_process' import { spawn } from 'child_process'
import decompress from 'decompress' import decompress from 'decompress'
import zlib from 'zlib'
export interface MySqlConfig { export interface MySqlConfig {
binPath: string binPath: string
@@ -17,6 +18,26 @@ export class MySqlOperationService {
fs.mkdirSync(targetDir, { recursive: true }) fs.mkdirSync(targetDir, { recursive: true })
} }
const lowerPath = archivePath.toLowerCase()
if (lowerPath.endsWith('.gz') && !lowerPath.endsWith('.tar.gz')) {
// Handle single-file gzip compression like .sql.gz
const baseName = path.basename(archivePath, '.gz')
const outPath = path.join(targetDir, baseName.endsWith('.sql') ? baseName : `${baseName}.sql`)
const source = fs.createReadStream(archivePath)
const destination = fs.createWriteStream(outPath)
const unzip = zlib.createUnzip()
await new Promise((resolve, reject) => {
source.pipe(unzip).pipe(destination)
.on('finish', () => resolve(true))
.on('error', reject)
})
return [outPath]
}
// Process standard archives (tar, zip, tar.gz)
await decompress(archivePath, targetDir) await decompress(archivePath, targetDir)
// Find all .sql files in the extracted directory // Find all .sql files in the extracted directory