@echo off
:: export_migration_data.bat
:: Script to export database tables and product images into a template for easy migration on Windows.

echo Starting Migration Data Export...

set TEMPLATE_DIR=database\seeders\template_data
set SQL_FILE=%TEMPLATE_DIR%\migration_data.sql
set IMAGES_DIR=%TEMPLATE_DIR%\images

if not exist "%TEMPLATE_DIR%" mkdir "%TEMPLATE_DIR%"

echo 1/2: Exporting database tables from gembira-db container...
set TABLES=users suppliers warehouses categories products warehouse_stock

:: Using --replace so it safely overwrites on import
docker exec gembira-db mysqldump -ugembira_user -pchangeme --replace --no-create-info --skip-triggers --compact gembira_ims %TABLES% > "%SQL_FILE%"

if %errorlevel% equ 0 (
    echo Database tables exported successfully to %SQL_FILE%
) else (
    echo Error exporting database tables.
)

echo 2/2: Copying product images from gembira-backend container...
if not exist "%IMAGES_DIR%" mkdir "%IMAGES_DIR%"
docker cp gembira-backend:/app/storage/app/public/products/. "%IMAGES_DIR%"
echo Product images copied to %IMAGES_DIR%

echo Export Completed! You can commit the '%TEMPLATE_DIR%' folder to git to migrate to a new server.
pause
