mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 23:01:09 +02:00
New Hono+Bun service at services/mana-events on port 3065 with two schemas in mana_platform: events_published (snapshots) and public_rsvps (unauthenticated responses), plus a per-token hourly rate-limit bucket. - Host endpoints (JWT) for publish/update/unpublish/list-rsvps - Public endpoints for snapshot fetch + RSVP upsert with rate limiting - New /rsvp/[token] page outside the auth gate, SSR-loads the snapshot - Client store wires publishEvent/unpublishEvent to the server, syncs snapshot updates after edits, and deletes the snapshot on event delete - DetailView polls GET /events/:id/rsvps every 30s while open and lets hosts import a public response into their local guest list - generate-env, setup-databases.sh, .env.development, hooks.server.ts, package.json wired for local dev
161 lines
4.8 KiB
Bash
Executable file
161 lines
4.8 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Setup script for creating databases and pushing schemas
|
|
# Usage: ./scripts/setup-databases.sh [service]
|
|
# Examples:
|
|
# ./scripts/setup-databases.sh # Setup all
|
|
# ./scripts/setup-databases.sh auth # Setup only auth schema
|
|
#
|
|
# Architecture: 2 databases (mana_platform + mana_sync)
|
|
# All service schemas live in mana_platform as separate PostgreSQL schemas.
|
|
|
|
set -e
|
|
|
|
# Database connection details (from .env.development)
|
|
DB_HOST="${DB_HOST:-localhost}"
|
|
DB_PORT="${DB_PORT:-5432}"
|
|
DB_USER="${POSTGRES_USER:-mana}"
|
|
DB_PASSWORD="${POSTGRES_PASSWORD:-devpassword}"
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${GREEN}Database Setup Script${NC}"
|
|
echo "======================================"
|
|
|
|
# Function to create database if it doesn't exist
|
|
create_db_if_not_exists() {
|
|
local db_name=$1
|
|
echo -e "${YELLOW}Checking database: ${db_name}${NC}"
|
|
|
|
if PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d postgres -tc \
|
|
"SELECT 1 FROM pg_database WHERE datname = '$db_name'" | grep -q 1; then
|
|
echo -e " ${GREEN}✓ Exists${NC}"
|
|
else
|
|
echo -e " Creating database ${db_name}..."
|
|
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d postgres -c "CREATE DATABASE $db_name;" > /dev/null
|
|
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE $db_name TO $DB_USER;" > /dev/null
|
|
echo -e " ${GREEN}✓ Created${NC}"
|
|
fi
|
|
}
|
|
|
|
# Function to create schema within a database
|
|
create_schema_if_not_exists() {
|
|
local db_name=$1
|
|
local schema_name=$2
|
|
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $db_name -c \
|
|
"CREATE SCHEMA IF NOT EXISTS $schema_name;" > /dev/null 2>&1
|
|
}
|
|
|
|
# Function to push schema for a service
|
|
push_schema() {
|
|
local filter=$1
|
|
local name=$2
|
|
echo -e "${YELLOW}Pushing schema for ${name}...${NC}"
|
|
if pnpm --filter "$filter" db:push --force 2>/dev/null; then
|
|
echo -e " ${GREEN}✓ Schema pushed${NC}"
|
|
else
|
|
echo -e " ${RED}✗ Failed (may not have db:push script)${NC}"
|
|
fi
|
|
}
|
|
|
|
# All schemas in mana_platform
|
|
PLATFORM_SCHEMAS=(
|
|
"auth"
|
|
"credits"
|
|
"gifts"
|
|
"subscriptions"
|
|
"feedback"
|
|
"usr"
|
|
"media"
|
|
"todo"
|
|
"traces"
|
|
"presi"
|
|
"uload"
|
|
"cards"
|
|
"events"
|
|
)
|
|
|
|
# Check if specific service requested
|
|
SERVICE_FILTER=${1:-""}
|
|
|
|
setup_service() {
|
|
local service=$1
|
|
|
|
case $service in
|
|
auth|mana-auth)
|
|
push_schema "@mana/auth" "mana-auth"
|
|
;;
|
|
credits|mana-credits)
|
|
push_schema "@mana/credits" "mana-credits"
|
|
;;
|
|
user|mana-user)
|
|
push_schema "@mana/user" "mana-user"
|
|
;;
|
|
subscriptions|mana-subscriptions)
|
|
push_schema "@mana/subscriptions" "mana-subscriptions"
|
|
;;
|
|
analytics|mana-analytics)
|
|
push_schema "@mana/analytics" "mana-analytics"
|
|
;;
|
|
media|mana-media)
|
|
push_schema "@mana/media" "mana-media"
|
|
;;
|
|
todo)
|
|
push_schema "@todo/server" "todo"
|
|
;;
|
|
traces)
|
|
push_schema "@traces/server" "traces"
|
|
;;
|
|
presi)
|
|
push_schema "@presi/server" "presi"
|
|
;;
|
|
uload)
|
|
push_schema "@mana/uload-database" "uload"
|
|
;;
|
|
cards)
|
|
push_schema "@mana/cards-database" "cards"
|
|
;;
|
|
events|mana-events)
|
|
push_schema "@mana/events" "mana-events"
|
|
;;
|
|
*)
|
|
echo -e "${RED}Unknown service: $service${NC}"
|
|
echo "Available services: auth, credits, user, subscriptions, analytics, media, todo, traces, presi, uload, cards, events"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
if [ -n "$SERVICE_FILTER" ]; then
|
|
echo -e "Setting up for service: ${SERVICE_FILTER}"
|
|
setup_service "$SERVICE_FILTER"
|
|
echo -e "\n${GREEN}✓ Setup complete!${NC}"
|
|
exit 0
|
|
fi
|
|
|
|
# Setup all databases
|
|
echo -e "\n${GREEN}Step 1: Creating databases${NC}"
|
|
echo "--------------------------------------"
|
|
create_db_if_not_exists "mana_platform"
|
|
create_db_if_not_exists "mana_sync"
|
|
|
|
echo -e "\n${GREEN}Step 2: Creating schemas in mana_platform${NC}"
|
|
echo "--------------------------------------"
|
|
for schema in "${PLATFORM_SCHEMAS[@]}"; do
|
|
echo -e " ${YELLOW}Creating schema: ${schema}${NC}"
|
|
create_schema_if_not_exists "mana_platform" "$schema"
|
|
echo -e " ${GREEN}✓ ${schema}${NC}"
|
|
done
|
|
|
|
echo -e "\n${GREEN}Step 3: Pushing schemas${NC}"
|
|
echo "--------------------------------------"
|
|
|
|
for service in auth credits user subscriptions analytics media todo traces presi uload cards events; do
|
|
setup_service "$service" 2>/dev/null || true
|
|
done
|
|
|
|
echo -e "\n${GREEN}✓ Database setup complete!${NC}"
|