Skip to content

Commit a302d72

Browse files
committed
Improve local dev docs
1 parent fa8711f commit a302d72

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

docs/ce/local-development/statesman.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ title: Statesman local setup
44

55
Statesman serves state storage + Terraform Cloud-compatible APIs. The UI uses its internal endpoints, so enable webhook auth and sync your org/user.
66

7+
## First-time setup (SQLite migrations)
8+
9+
If using SQLite with persistence, run migrations before starting:
10+
11+
```bash
12+
cd taco
13+
14+
# If you get checksum errors, regenerate the hash first:
15+
atlas migrate hash --dir file://migrations/sqlite
16+
17+
# Apply migrations (adjust path to match your OPENTACO_SQLITE_DB_PATH)
18+
atlas migrate apply --dir file://migrations/sqlite --url "sqlite://cmd/statesman/data/taco.db"
19+
```
20+
21+
If you don't have Atlas installed: `make atlas-install`
22+
723
## Quick start
824

925
1. Set env vars:
@@ -24,6 +40,15 @@ Statesman serves state storage + Terraform Cloud-compatible APIs. The UI uses it
2440

2541
Statesman resolves orgs by `external_org_id` (your WorkOS org id). If it cannot resolve, `/internal/api/units` will 500.
2642

43+
A helper script is available at `taco/cmd/statesman/sync-org.sh` - edit the values before running:
44+
45+
```bash
46+
chmod +x taco/cmd/statesman/sync-org.sh
47+
./taco/cmd/statesman/sync-org.sh
48+
```
49+
50+
Or run manually:
51+
2752
```bash
2853
SECRET=$OPENTACO_ENABLE_INTERNAL_ENDPOINTS
2954
ORG_ID=org_xxx # WorkOS org id
@@ -49,6 +74,8 @@ curl -s -X POST http://localhost:8080/internal/api/users \
4974

5075
## Troubleshooting
5176

77+
- **"no such table: organizations"**: Run migrations first (see First-time setup above).
78+
- **Atlas checksum mismatch**: Run `atlas migrate hash --dir file://migrations/sqlite` then retry apply.
5279
- **403**: webhook secret mismatch (`OPENTACO_ENABLE_INTERNAL_ENDPOINTS` vs UI `STATESMAN_BACKEND_WEBHOOK_SECRET`).
53-
- **404/500 resolving org**: org not synced; rerun the `orgs/sync` call above.
80+
- **404/500 resolving org**: org not synced; rerun the sync script or `orgs/sync` call above.
5481
- **SQLite quirks**: defaults to SQLite in-process; no config needed for local. For Postgres/MySQL, set `TACO_QUERY_BACKEND` and related envs (see `docs/ce/state-management/query-backend`).

taco/cmd/statesman/sync-org.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
SECRET=topsecret # must match OPENTACO_ENABLE_INTERNAL_ENDPOINTS
4+
ORG_ID=org_xxx # your WorkOS org id
5+
ORG_NAME=my-org # internal org name/slug
6+
ORG_DISPLAY="My Org" # display name
7+
USER_ID=user_xxx # your WorkOS user id
8+
USER_EMAIL=you@example.com # your email
9+
10+
# create/sync org
11+
curl -s -X POST http://localhost:8080/internal/api/orgs/sync \
12+
-H "Authorization: Bearer $SECRET" \
13+
-H "X-User-ID: $USER_ID" -H "X-Email: $USER_EMAIL" \
14+
-H "Content-Type: application/json" \
15+
-d '{"name":"'"$ORG_NAME"'","display_name":"'"$ORG_DISPLAY"'","external_org_id":"'"$ORG_ID"'"}'
16+
17+
echo ""
18+
echo "Org synced. Now syncing user..."
19+
20+
# ensure user exists in that org
21+
curl -s -X POST http://localhost:8080/internal/api/users \
22+
-H "Authorization: Bearer $SECRET" \
23+
-H "X-Org-ID: $ORG_ID" -H "X-User-ID: $USER_ID" -H "X-Email: $USER_EMAIL" \
24+
-H "Content-Type: application/json" \
25+
-d '{"subject":"'"$USER_ID"'","email":"'"$USER_EMAIL"'"}'
26+
27+
echo ""
28+
echo "Done!"

0 commit comments

Comments
 (0)