meraproject/scripts/import-tracker-to-mysql.ps1
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

54 lines
1.8 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Imports tracker SQL into Docker MySQL (meraproject-mysqldb).
# 1) docker compose up -d db (data/db пустая или уже есть сервер)
# 2) .\scripts\import-tracker-to-mysql.ps1
#
# SQL: data/mysql-init/01-j7508239_tracker.sql — собрать extract-tracker-db.ps1 (или свой кусок j7508239_tracker без системной mysql.*)
param(
[string]$SqlFile = "",
[string]$ContainerName = "meraproject-mysqldb",
[string]$RootPassword = ""
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $PSScriptRoot
if (-not $SqlFile) {
$SqlFile = Join-Path $root "data\mysql-init\01-j7508239_tracker.sql"
}
if (-not (Test-Path -LiteralPath $SqlFile)) {
Write-Error "SQL not found: $SqlFile. Run extract-tracker-db.ps1 first."
exit 1
}
if (-not $RootPassword) {
$RootPassword = $env:MERAPROJECT_MYSQL_ROOT_PASSWORD
}
if (-not $RootPassword) {
$RootPassword = "Q#Y34KsmCfy*"
}
$running = docker inspect -f "{{.State.Running}}" $ContainerName 2>$null
if ($running -ne "true") {
Write-Error "Container not running: $ContainerName. Run: docker compose up -d db"
exit 1
}
Write-Host "Importing into $ContainerName from:"
Write-Host $SqlFile
Write-Host "(may take a few minutes)"
# MYSQL_PWD передаём внутрь контейнера (клиент mysql в образе его читает)
$env:MYSQL_PWD = $null
$sqlPath = (Resolve-Path -LiteralPath $SqlFile).Path
Get-Content -LiteralPath $sqlPath -Encoding UTF8 |
docker exec -i -e "MYSQL_PWD=$RootPassword" $ContainerName mysql -uroot --max_allowed_packet=512M
if ($LASTEXITCODE -ne 0) {
Write-Error "Import failed, exit code $LASTEXITCODE"
exit $LASTEXITCODE
}
Write-Host "OK. Example: docker exec -it $ContainerName mysql -uroot -p -e ""USE j7508239_tracker; SHOW TABLES LIKE 'tmerakomisemp';"""