Complete initial setup: dependencies, Prisma fixes, and database setup guides
- Install backend and frontend dependencies - Fix Prisma schema BigInt default values - Generate Prisma client - Create database setup script and documentation - Add DATABASE_SETUP.md guide
This commit is contained in:
131
DATABASE_SETUP.md
Normal file
131
DATABASE_SETUP.md
Normal file
@@ -0,0 +1,131 @@
|
||||
# Database Setup Guide
|
||||
|
||||
This guide helps you set up the PostgreSQL database for ASLE backend.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- PostgreSQL 15+ installed and running
|
||||
- Access to create databases
|
||||
|
||||
## Quick Setup
|
||||
|
||||
### Option 1: Using Docker (Recommended)
|
||||
|
||||
```bash
|
||||
# Start PostgreSQL container
|
||||
docker-compose up -d postgres
|
||||
|
||||
# The database will be created automatically with:
|
||||
# - User: asle
|
||||
# - Password: asle_password
|
||||
# - Database: asle
|
||||
```
|
||||
|
||||
Update `backend/.env`:
|
||||
```env
|
||||
DATABASE_URL="postgresql://asle:asle_password@localhost:5432/asle?schema=public"
|
||||
```
|
||||
|
||||
### Option 2: Local PostgreSQL
|
||||
|
||||
1. **Create database:**
|
||||
```bash
|
||||
# As postgres superuser
|
||||
sudo -u postgres psql -c "CREATE DATABASE asle;"
|
||||
|
||||
# Or create a user first
|
||||
sudo -u postgres psql -c "CREATE USER asle WITH PASSWORD 'your_password';"
|
||||
sudo -u postgres psql -c "CREATE DATABASE asle OWNER asle;"
|
||||
```
|
||||
|
||||
2. **Update `backend/.env`:**
|
||||
```env
|
||||
DATABASE_URL="postgresql://asle:your_password@localhost:5432/asle?schema=public"
|
||||
```
|
||||
|
||||
### Option 3: Using Existing PostgreSQL
|
||||
|
||||
If you have PostgreSQL running with different credentials:
|
||||
|
||||
1. **Create database:**
|
||||
```bash
|
||||
psql -U your_user -c "CREATE DATABASE asle;"
|
||||
```
|
||||
|
||||
2. **Update `backend/.env`:**
|
||||
```env
|
||||
DATABASE_URL="postgresql://your_user:your_password@localhost:5432/asle?schema=public"
|
||||
```
|
||||
|
||||
## Running Migrations
|
||||
|
||||
After setting up the database:
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
|
||||
# Generate Prisma client
|
||||
npm run prisma:generate
|
||||
|
||||
# Run migrations
|
||||
npm run prisma:migrate
|
||||
|
||||
# Initialize database with default configs
|
||||
npm run setup:db
|
||||
|
||||
# Create admin user
|
||||
npm run setup:admin
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Authentication Failed
|
||||
|
||||
If you see `Authentication failed`:
|
||||
|
||||
1. Check PostgreSQL is running:
|
||||
```bash
|
||||
pg_isready -h localhost -p 5432
|
||||
```
|
||||
|
||||
2. Verify credentials in `backend/.env`
|
||||
|
||||
3. Test connection:
|
||||
```bash
|
||||
psql $DATABASE_URL -c "SELECT version();"
|
||||
```
|
||||
|
||||
### Database Already Exists
|
||||
|
||||
If database already exists, migrations will still work:
|
||||
```bash
|
||||
npm run prisma:migrate
|
||||
```
|
||||
|
||||
### Permission Denied
|
||||
|
||||
If you get permission errors:
|
||||
```bash
|
||||
# Grant permissions
|
||||
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE asle TO your_user;"
|
||||
```
|
||||
|
||||
## Connection String Format
|
||||
|
||||
```
|
||||
postgresql://[user]:[password]@[host]:[port]/[database]?schema=public
|
||||
```
|
||||
|
||||
Examples:
|
||||
- `postgresql://postgres@localhost:5432/asle?schema=public` (no password)
|
||||
- `postgresql://asle:password@localhost:5432/asle?schema=public` (with password)
|
||||
- `postgresql://user:pass@db.example.com:5432/asle?schema=public` (remote)
|
||||
|
||||
## Next Steps
|
||||
|
||||
After database is set up:
|
||||
1. ✅ Run migrations
|
||||
2. ✅ Initialize database
|
||||
3. ✅ Create admin user
|
||||
4. ✅ Start backend: `npm run dev`
|
||||
|
||||
10617
backend/package-lock.json
generated
10617
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -187,8 +187,8 @@ model ChainConfig {
|
||||
name String
|
||||
nativeToken String?
|
||||
explorerUrl String
|
||||
gasLimit BigInt @default("3000000")
|
||||
messageTimeout BigInt @default("300") // seconds
|
||||
gasLimit BigInt @default(3000000)
|
||||
messageTimeout BigInt @default(300) // seconds
|
||||
active Boolean @default(true)
|
||||
ccipSelector BigInt?
|
||||
rpcUrl String?
|
||||
|
||||
55
backend/scripts/setup-database.sh
Executable file
55
backend/scripts/setup-database.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Database setup script for ASLE backend
|
||||
# This script helps set up PostgreSQL database for development
|
||||
|
||||
set -e
|
||||
|
||||
echo "=== ASLE Database Setup ==="
|
||||
echo ""
|
||||
|
||||
# Check if PostgreSQL is running
|
||||
if ! pg_isready -h localhost -p 5432 > /dev/null 2>&1; then
|
||||
echo "❌ PostgreSQL is not running on localhost:5432"
|
||||
echo ""
|
||||
echo "Please start PostgreSQL:"
|
||||
echo " - Using Docker: docker-compose up -d postgres"
|
||||
echo " - Using systemd: sudo systemctl start postgresql"
|
||||
echo " - Or install PostgreSQL: sudo apt install postgresql"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ PostgreSQL is running"
|
||||
echo ""
|
||||
|
||||
# Try to connect and create database
|
||||
echo "Attempting to create database 'asle'..."
|
||||
|
||||
# Try different connection methods
|
||||
if psql -U postgres -c "CREATE DATABASE asle;" 2>/dev/null; then
|
||||
echo "✅ Database 'asle' created using postgres user"
|
||||
DB_USER="postgres"
|
||||
elif psql -d postgres -c "CREATE DATABASE asle;" 2>/dev/null; then
|
||||
echo "✅ Database 'asle' created using peer authentication"
|
||||
DB_USER=$(whoami)
|
||||
else
|
||||
echo "⚠️ Could not create database automatically"
|
||||
echo ""
|
||||
echo "Please create the database manually:"
|
||||
echo " psql -U postgres -c \"CREATE DATABASE asle;\""
|
||||
echo ""
|
||||
echo "Or update backend/.env with correct DATABASE_URL:"
|
||||
echo " DATABASE_URL=\"postgresql://username:password@localhost:5432/asle?schema=public\""
|
||||
echo ""
|
||||
read -p "Press Enter after creating the database..."
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Database Setup Complete ==="
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " 1. Update backend/.env with correct DATABASE_URL"
|
||||
echo " 2. Run: cd backend && npm run prisma:migrate"
|
||||
echo " 3. Run: npm run setup:db"
|
||||
echo " 4. Run: npm run setup:admin"
|
||||
|
||||
Reference in New Issue
Block a user