77 lines
2.2 KiB
Bash
77 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
echo "================================================"
|
|
echo "🚀 Property Image Tagging API - Quick Setup"
|
|
echo "================================================"
|
|
echo ""
|
|
|
|
# Check if .env exists
|
|
if [ ! -f .env ]; then
|
|
echo "❌ .env file not found!"
|
|
echo ""
|
|
echo "Please create a .env file by copying .env.example:"
|
|
echo " cp .env.example .env"
|
|
echo ""
|
|
echo "Then edit .env and add:"
|
|
echo " 1. Your MySQL password (DB_PASSWORD)"
|
|
echo " 2. Your Anthropic API key (ANTHROPIC_API_KEY)"
|
|
echo ""
|
|
echo "Get your Anthropic API key from: https://console.anthropic.com/"
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ .env file found"
|
|
echo ""
|
|
|
|
# Load environment variables
|
|
export $(grep -v '^#' .env | xargs)
|
|
|
|
# Check if database exists
|
|
echo "🔍 Checking database connection..."
|
|
mysql -h"${DB_HOST}" -u"${DB_USER}" -p"${DB_PASSWORD}" -e "SHOW DATABASES LIKE '${DB_NAME}';" 2>/dev/null | grep -q "${DB_NAME}"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "❌ Database '${DB_NAME}' not found!"
|
|
echo ""
|
|
echo "Creating database and tables..."
|
|
|
|
# Create database
|
|
mysql -h"${DB_HOST}" -u"${DB_USER}" -p"${DB_PASSWORD}" -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME};" 2>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "❌ Failed to create database. Please check your MySQL credentials in .env"
|
|
exit 1
|
|
fi
|
|
|
|
# Import schema
|
|
mysql -h"${DB_HOST}" -u"${DB_USER}" -p"${DB_PASSWORD}" "${DB_NAME}" < 001_initial_schema.sql 2>/dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ Database created and schema imported successfully!"
|
|
else
|
|
echo "❌ Failed to import schema. Please check 001_initial_schema.sql"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "✅ Database '${DB_NAME}' exists"
|
|
fi
|
|
|
|
echo ""
|
|
echo "🔑 Creating a test API key..."
|
|
npm run apikey:create
|
|
|
|
echo ""
|
|
echo "================================================"
|
|
echo "✅ Setup Complete!"
|
|
echo "================================================"
|
|
echo ""
|
|
echo "You can now:"
|
|
echo " • Start the server: npm start"
|
|
echo " • Development mode: npm run dev"
|
|
echo " • List API keys: npm run apikey:list"
|
|
echo ""
|
|
echo "The API will be available at: http://localhost:${PORT:-3000}"
|
|
echo ""
|
|
|