Let me look into the recommended approach for resetting the database in a self-hosted Docker setup.Based on the documentation, here is the recommended approach for resetting the database on a self-hosted Docker setup:
The documented method for self-hosted environments involves using docker exec to run commands inside the container. The troubleshooting docs note that the reset command will completely erase your database and recreate it from scratch.
The general steps are:
- Back up your database first (if you have any data you want to preserve):
docker exec -it {db_container_name_or_id} pg_dumpall -U {postgres_user} > backup.sql
- Run the database reset inside the Twenty server container:
docker exec -it {server_container_name_or_id} npx ts-node ./scripts/setup-db.ts
If that specific script path doesn't exist in the latest image, you can take a more manual approach by resetting at the Postgres level:
- Drop and recreate the database directly:
docker stop {server_container_name_or_id}
docker exec -it {db_container_name_or_id} psql -U {postgres_user} -c "DROP DATABASE IF EXISTS \"default\";"
docker exec -it {db_container_name_or_id} psql -U {postgres_user} -c "DROP DATABASE IF EXISTS \"twenty\";"
docker exec -it {db_container_name_or_id} psql -U {postgres_user} -c "CREATE DATABASE \"default\";"
docker exec -it {db_container_name_or_id} psql -U {postgres_user} -c "CREATE DATABASE \"twenty\";"
docker start {server_container_name_or_id}
Replace the database names with whatever your PG_DATABASE_URL points to (commonly default or twenty).