The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(setup-script): add database schema initialization to setup script (#20063)
Ratish jainc5c8cf137932
diff --git a/CLAUDE.md b/CLAUDE.mdindex 1dd0dbc3e60..e6d4f897990 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -208,7 +208,7 @@ All dev environments (Claude Code web, Cursor, local) use one script:bash packages/twenty-utils/setup-dev-env.sh```-This handles everything: starts Postgres + Redis (auto-detects local services vs Docker), creates databases, and copies `.env` files. Idempotent — safe to run multiple times.+This handles everything: starts Postgres + Redis (auto-detects local services vs Docker), creates databases, copies `.env` files, and initializes the database schema (runs migrations) on a fresh database. Idempotent — safe to run multiple times.- `--docker` — force Docker mode (uses `packages/twenty-docker/docker-compose.dev.yml`)- `--down` — stop servicesdiff --git a/packages/twenty-utils/setup-dev-env.sh b/packages/twenty-utils/setup-dev-env.shindex 817a00d661d..99f9763447e 100755--- a/packages/twenty-utils/setup-dev-env.sh+++ b/packages/twenty-utils/setup-dev-env.sh@@ -8,6 +8,7 @@# 1. Starts Postgres + Redis (local services or Docker, auto-detected)# 2. Creates 'default' and 'test' databases# 3. Copies .env.example -> .env for front and server+# 4. Initializes database schema (runs migrations) when not already present## Usage (from repo root):# bash packages/twenty-utils/setup-dev-env.sh # start + configure@@ -79,6 +80,16 @@ wait_for_redis() {done}+schema_exists() {+ if command -v psql &>/dev/null; then+ PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d default -t -c "SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = 'core'" 2>/dev/null | grep -q 1+ elif can_use_docker && docker compose -f "$COMPOSE_FILE" ps --quiet db 2>/dev/null | grep -q .; then+ docker compose -f "$COMPOSE_FILE" exec -T db psql -U postgres -d default -t -c "SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = 'core'" 2>/dev/null | grep -q 1+ else+ return 1+ fi+}+# --------------- parse flags ---------------USE_DOCKER=falseACTION="up"@@ -241,6 +252,25 @@ elsedonefi+# =============================================================================+# 4. Initialize database schema+# =============================================================================+if command -v npx &>/dev/null && [ -d node_modules ]; then+ if schema_exists; then+ ok "Database schema already initialized"+ else+ info "Initializing database schema (running migrations)..."+ if npx nx database:init twenty-server; then+ ok "Database schema initialized"+ else+ fail "Database schema initialization failed"+ exit 1+ fi+ fi+else+ info "Run 'npx nx database:init twenty-server' to initialize the schema"+fi+# =============================================================================echo ""echo "Dev environment ready."