Skip to content

Commit 012bd3a

Browse files
authored
Merge pull request #104 from TomMaSS/feature/ready-tasks
Admini initialization
2 parents 3c5a841 + 514572e commit 012bd3a

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

db/07_multi_user.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ DO $$ BEGIN
5757
END $$;
5858

5959
DO $$ BEGIN
60-
IF NOT EXISTS (
60+
IF EXISTS (
61+
SELECT 1 FROM information_schema.tables
62+
WHERE table_schema = 'public' AND table_name = 'mcp_activity'
63+
) AND NOT EXISTS (
6164
SELECT 1 FROM information_schema.columns
6265
WHERE table_name = 'mcp_activity' AND column_name = 'user_id'
6366
) THEN

db/08_mcp_activity.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS mcp_activity (
44
project_id UUID REFERENCES projects(id) ON DELETE CASCADE,
55
tool_name TEXT NOT NULL,
66
detail JSONB DEFAULT '{}',
7+
user_id TEXT,
78
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
89
);
910

frontend/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

install.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,53 @@ else
278278
ok "Docker services running"
279279
fi
280280

281+
# ─── Create admin account (first-time only) ─────────────────────────
282+
FRONTEND_URL="http://localhost:3000"
283+
SETUP_URL="$FRONTEND_URL/api/auth/setup"
284+
285+
# Check if bootstrap was already done (query DB directly, no side-effects)
286+
setup_needed=true
287+
bootstrap_done=$(docker compose -f "$COMPOSE_FILE" exec -T postgres \
288+
psql -U "${POSTGRES_USER:-prdforge}" -d "${POSTGRES_DB:-prdforge}" -tAc \
289+
"SELECT EXISTS(SELECT 1 FROM prdforge_bootstrap WHERE setup_type='first_user' AND completed=true)" 2>/dev/null || echo "f")
290+
291+
if [ "$bootstrap_done" = "t" ]; then
292+
ok "Admin account already exists — skipping"
293+
setup_needed=false
294+
fi
295+
296+
if [ "$setup_needed" = true ]; then
297+
echo ""
298+
info "Create your admin account:"
299+
read -rp " Name: " ADMIN_NAME
300+
read -rp " Email: " ADMIN_EMAIL
301+
while true; do
302+
read -rsp " Password: " ADMIN_PASSWORD
303+
echo ""
304+
read -rsp " Confirm password: " ADMIN_PASSWORD2
305+
echo ""
306+
if [ "$ADMIN_PASSWORD" = "$ADMIN_PASSWORD2" ]; then
307+
break
308+
fi
309+
warn "Passwords don't match. Try again."
310+
done
311+
312+
# Escape JSON values
313+
SETUP_JSON=$(python3 -c "import json,sys; print(json.dumps({'name':sys.argv[1],'email':sys.argv[2],'password':sys.argv[3]}))" "$ADMIN_NAME" "$ADMIN_EMAIL" "$ADMIN_PASSWORD")
314+
315+
response=$(curl -sf -X POST "$SETUP_URL" \
316+
-H "Content-Type: application/json" \
317+
-d "$SETUP_JSON" 2>&1) || true
318+
319+
if echo "$response" | python3 -c "import sys,json; d=json.load(sys.stdin); sys.exit(0 if d.get('success') else 1)" 2>/dev/null; then
320+
ok "Admin account created ($ADMIN_EMAIL)"
321+
else
322+
error_msg=$(echo "$response" | python3 -c "import sys,json; print(json.load(sys.stdin).get('error','unknown error'))" 2>/dev/null || echo "$response")
323+
warn "Could not create admin account: $error_msg"
324+
warn "You can create it manually at $FRONTEND_URL"
325+
fi
326+
fi
327+
281328
# ─── Configure MCP ──────────────────────────────────────────────────
282329
echo ""
283330
if [ "$MODE" = "code" ]; then

0 commit comments

Comments
 (0)