84 lines
2.7 KiB
Bash
84 lines
2.7 KiB
Bash
#!/bin/sh
|
||
# startup.sh - Script to run migrations and start the bot
|
||
|
||
echo "🚀 Starting Telegram Tinder Bot..."
|
||
|
||
# Check for locales directory
|
||
if [ ! -d "dist/locales" ]; then
|
||
echo "⚠️ Locales directory not found in dist/locales"
|
||
echo "🔍 Checking source directory structure..."
|
||
ls -la dist/ || echo "Error listing dist directory"
|
||
|
||
# If src/locales exists, copy it to dist/locales
|
||
if [ -d "src/locales" ]; then
|
||
echo "📂 Found src/locales directory. Copying to dist/locales..."
|
||
mkdir -p dist/locales
|
||
cp -R src/locales/* dist/locales/
|
||
echo "✅ Locales copied successfully"
|
||
else
|
||
echo "❌ src/locales directory not found either. Creating empty locales directory..."
|
||
mkdir -p dist/locales
|
||
fi
|
||
fi
|
||
|
||
# Wait for database to be ready
|
||
echo "⏳ Waiting for database to be ready..."
|
||
sleep 5
|
||
|
||
# Run database migrations
|
||
echo "🔄 Running database migrations..."
|
||
|
||
# Create migrations directory structure
|
||
mkdir -p dist/database/migrations
|
||
|
||
# Copy any available migrations
|
||
if [ -d "src/database/migrations" ]; then
|
||
echo "<22> Found SQL migrations. Copying..."
|
||
cp -R src/database/migrations/* dist/database/migrations/ 2>/dev/null || echo "No SQL migrations to copy"
|
||
fi
|
||
|
||
# Copy JS migrations if available
|
||
if [ -d "migrations" ]; then
|
||
echo "📂 Found JS migrations. Copying..."
|
||
mkdir -p migrations-temp
|
||
cp migrations/*.js migrations-temp/ 2>/dev/null || echo "No JS migrations to copy"
|
||
# Move JS migrations to dist/database/migrations
|
||
cp migrations-temp/*.js dist/database/migrations/ 2>/dev/null || echo "No JS migrations to copy to dist"
|
||
fi
|
||
|
||
# Display environment variables for debugging (without passwords)
|
||
echo "🔍 Environment variables for database connection:"
|
||
echo "DB_HOST: $DB_HOST"
|
||
echo "DB_PORT: $DB_PORT"
|
||
echo "DB_NAME: $DB_NAME"
|
||
echo "DB_USERNAME: $DB_USERNAME"
|
||
|
||
# Run migrations using node-pg-migrate
|
||
echo "🔄 Running migrations with node-pg-migrate..."
|
||
DATABASE_URL="postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" npx node-pg-migrate up
|
||
|
||
# Verify connection to database
|
||
echo "🔍 Verifying database connection..."
|
||
node -e "
|
||
const { Pool } = require('pg');
|
||
const pool = new Pool({
|
||
host: process.env.DB_HOST,
|
||
port: process.env.DB_PORT,
|
||
database: process.env.DB_NAME,
|
||
user: process.env.DB_USERNAME,
|
||
password: process.env.DB_PASSWORD
|
||
});
|
||
pool.query('SELECT NOW()', (err, res) => {
|
||
if (err) {
|
||
console.error('❌ Database connection failed:', err.message);
|
||
process.exit(1);
|
||
} else {
|
||
console.log('✅ Database connection successful:', res.rows[0].now);
|
||
pool.end();
|
||
}
|
||
});" || echo "❌ Failed to verify database connection"
|
||
|
||
# Start the bot
|
||
echo "✅ Starting the bot..."
|
||
node dist/bot.js
|