Repository navigation
Expand file tree
/
Copy pathsetup-sqlx.sh
More file actions
55 lines (44 loc) Β· 1.55 KB
/
Copy pathsetup-sqlx.sh
File metadata and controls
55 lines (44 loc) Β· 1.55 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
#!/bin/bash
# Setup script for SQLx compile-time verification
set -e
echo "π§ Setting up database for SQLx compile-time verification..."
# Check if Docker is available
if ! command -v docker &> /dev/null; then
echo "β Docker is not installed. Please install Docker first."
exit 1
fi
# Check if PostgreSQL container is already running
if docker ps | grep -q stellar-postgres; then
echo "β
PostgreSQL container is already running"
else
echo "π³ Starting PostgreSQL container..."
docker run --name stellar-postgres \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=stellar_analysis \
-p 5432:5432 -d postgres:14
echo "β³ Waiting for PostgreSQL to be ready..."
sleep 5
fi
# Set DATABASE_URL
export DATABASE_URL="postgresql://postgres:password@localhost:5432/stellar_analysis"
echo "DATABASE_URL=$DATABASE_URL" > .env
echo "β
Database URL set in .env file"
# Check if sqlx-cli is installed
if ! command -v sqlx &> /dev/null; then
echo "π¦ Installing sqlx-cli..."
cargo install sqlx-cli --no-default-features --features postgres,sqlite
fi
# Run migrations if they exist
if [ -d "migrations" ]; then
echo "π Running database migrations..."
sqlx migrate run
else
echo "β οΈ No migrations directory found. You may need to create the database schema manually."
fi
# Generate SQLx prepared data
echo "π Generating SQLx prepared data..."
cargo sqlx prepare
echo "β
Setup complete! You can now run:"
echo " cargo build"
echo " cargo clippy --all-targets --all-features"
echo " cargo test"