@echo off REM Script for updating the Telegram Tinder Bot on Windows REM This script updates the code from Git, applies migrations, and prepares the bot for running REM Usage: .\bin\update.bat [branch] REM If branch is not specified, 'main' is used setlocal enableextensions enabledelayedexpansion echo ======================================== echo Telegram Tinder Bot Updater echo ======================================== REM Get the branch name from the command line arguments set BRANCH=%1 if "%BRANCH%"=="" set BRANCH=main echo Updating from branch: %BRANCH% REM Store the current directory set CURRENT_DIR=%CD% set SCRIPT_DIR=%~dp0 set PROJECT_DIR=%SCRIPT_DIR%.. REM Navigate to the project directory cd /d %PROJECT_DIR% echo Working directory: %PROJECT_DIR% REM Check if we're in a git repository if not exist .git ( echo Error: Not a git repository exit /b 1 ) echo. echo Step 1: Pulling latest changes from Git repository... REM Save any local changes git stash save "Auto-stash before update: %DATE% %TIME%" REM Fetch all branches git fetch --all REM Check if the branch exists git rev-parse --verify %BRANCH% >nul 2>&1 if %ERRORLEVEL% NEQ 0 ( git rev-parse --verify origin/%BRANCH% >nul 2>&1 if %ERRORLEVEL% NEQ 0 ( echo Error: Branch '%BRANCH%' does not exist locally or remotely exit /b 1 ) ) REM Checkout the specified branch git checkout %BRANCH% REM Pull the latest changes git pull origin %BRANCH% echo ✓ Successfully pulled latest changes echo. echo Step 2: Installing dependencies... call npm ci echo ✓ Dependencies installed echo. echo Step 3: Running database migrations... REM Check if migrations directory exists if exist migrations ( echo Applying database migrations... call npm run migrate:up echo ✓ Migrations applied successfully ) else ( echo ⚠ No migrations directory found, running database initialization script... call npm run init:db echo ✓ Database initialized ) echo. echo Step 4: Building the project... call npm run build echo ✓ Project built successfully echo. echo Step 5: Checking for .env file... if exist .env ( echo ✓ .env file exists ) else ( echo ⚠ .env file not found if exist .env.example ( echo Creating .env from .env.example copy .env.example .env echo ⚠ Please update the .env file with your configuration! ) else ( echo Error: .env.example file not found exit /b 1 ) ) echo. echo Step 6: Checking for services... REM Check if Docker is being used if exist docker-compose.yml ( echo Docker Compose configuration found echo You might want to restart containers with: docker-compose down ^&^& docker-compose up -d ) echo. echo ======================================== echo Update completed successfully! echo ======================================== echo To start the bot, run: npm run start echo For development mode: npm run dev REM Return to the original directory cd /d %CURRENT_DIR%