File size: 1,383 Bytes
5a81b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
# WidgeTDC Codespace Setup Script
# Runs once when the container is created

set -e

echo "=== WidgeTDC Codespace Setup ==="

# Copy Codespace env if .env doesn't exist
if [ ! -f apps/backend/.env ]; then
    echo "Creating .env from .env.codespace..."
    cp apps/backend/.env.codespace apps/backend/.env
fi

# Install dependencies
echo "Installing dependencies..."
npm install

# Generate Prisma client
echo "Generating Prisma client..."
npx prisma generate --schema=./apps/backend/prisma/schema.prisma

# Wait for PostgreSQL to be ready (using Node.js since pg_isready isn't installed)
echo "Waiting for PostgreSQL..."
until node -e "const net = require('net'); const client = new net.Socket(); client.setTimeout(3000); client.connect(5432, 'postgres', () => { client.destroy(); process.exit(0); }); client.on('error', () => process.exit(1)); client.on('timeout', () => { client.destroy(); process.exit(1); });" 2>/dev/null; do
    sleep 2
done
echo "PostgreSQL is ready!"

# Push schema to database
echo "Syncing database schema..."
cd apps/backend
npx prisma db push --accept-data-loss
cd ../..

# Build shared packages
echo "Building shared packages..."
npm run build:shared || true

# Build backend
echo "Building backend..."
cd apps/backend
npm run build || true
cd ../..

echo "=== Setup Complete ==="
echo "Run 'npm run dev' to start both frontend and backend"