-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·145 lines (126 loc) · 3.75 KB
/
dev.sh
File metadata and controls
executable file
·145 lines (126 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# Development helper script for Sensor API
set -e # Exit on any error
echo "🚀 Sensor API Development Setup"
echo "================================"
# Check if virtual environment exists
if [ ! -d ".venv" ]; then
echo "❌ Virtual environment not found. Please run setup.sh first."
exit 1
fi
# Activate virtual environment
source .venv/bin/activate
# Check if .env file exists
if [ ! -f ".env" ]; then
echo "❌ .env file not found. Please copy .env.example to .env and configure it."
exit 1
fi
# Check if DATABASE_URL is configured
if grep -q "replace_with_your" .env; then
echo "❌ Please configure your Aiven PostgreSQL connection in .env file"
echo " Edit .env and replace the DATABASE_URL with your actual connection string"
exit 1
fi
echo "✓ Environment setup complete"
# Function to run database migrations
run_migrations() {
echo "📦 Running database migrations..."
# Initialize Alembic if not already done
if [ ! -d "alembic/versions" ]; then
mkdir -p alembic/versions
fi
# Create initial migration if no migrations exist
if [ -z "$(ls -A alembic/versions 2>/dev/null)" ]; then
echo " Creating initial migration..."
alembic revision --autogenerate -m "Initial migration - sensor data schema"
fi
# Apply migrations
echo " Applying migrations..."
alembic upgrade head
echo "✓ Database migrations completed"
}
# Function to create sample data
create_sample_data() {
echo "🌱 Creating sample data..."
python scripts/create_sample_data.py
echo "✓ Sample data created"
}
# Function to start the API server
start_server() {
echo "🚀 Starting Sensor API server..."
echo " GraphQL Playground: http://localhost:8000/graphql"
echo " API Documentation: http://localhost:8000/docs"
echo " Health Check: http://localhost:8000/health"
echo ""
echo "Press Ctrl+C to stop the server"
python main.py
}
# Function to run tests
run_tests() {
echo "🧪 Running tests..."
pytest -v
echo "✓ Tests completed"
}
# Function to format code
format_code() {
echo "🎨 Formatting code..."
black .
isort .
echo "✓ Code formatted"
}
# Function to check code quality
check_code() {
echo "🔍 Checking code quality..."
black --check .
isort --check-only .
mypy .
echo "✓ Code quality check completed"
}
# Main menu
case "${1:-help}" in
"migrate")
run_migrations
;;
"sample-data")
run_migrations
create_sample_data
;;
"start"|"server")
run_migrations
start_server
;;
"test")
run_tests
;;
"format")
format_code
;;
"check")
check_code
;;
"dev")
# Full development setup
run_migrations
create_sample_data
start_server
;;
"help"|*)
echo "Usage: $0 {command}"
echo ""
echo "Commands:"
echo " migrate - Run database migrations"
echo " sample-data - Create sample data (includes migrate)"
echo " start|server - Start the API server (includes migrate)"
echo " test - Run tests"
echo " format - Format code with black and isort"
echo " check - Check code quality"
echo " dev - Full setup: migrate + sample-data + start server"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " ./dev.sh dev # Set up everything and start server"
echo " ./dev.sh migrate # Just run migrations"
echo " ./dev.sh start # Start server (with migrations)"
echo " ./dev.sh sample-data # Create sample data"
;;
esac