README.md

 1# Zed Server
 2
 3This crate is what we run at https://collab.zed.dev.
 4
 5It contains our back-end logic for collaboration, to which we connect from the Zed client via a websocket after authenticating via https://zed.dev, which is a separate repo running on Vercel.
 6
 7# Local Development
 8
 9## Database setup
10
11Before you can run the collab server locally, you'll need to set up a zed Postgres database. Follow the steps sequentially:
12
131. Ensure you have postgres installed. If not, install with `brew install postgresql@15`.
142. Follow the steps on Brew's formula and verify your `$PATH` contains `/opt/homebrew/opt/postgresql@15/bin`.
153. If you hadn't done it before, create the `postgres` user with `createuser -s postgres`.
164. You are now ready to run the `bootstrap` script:
17
18```sh
19script/bootstrap
20```
21
22This script will set up the `zed` Postgres database, and populate it with some users. It requires internet access, because it fetches some users from the GitHub API.
23
24The script will create several _admin_ users, who you'll sign in as by default when developing locally. The GitHub logins for the default users are specified in the `seed.default.json` file.
25
26To use a different set of admin users, create `crates/collab/seed.json`.
27
28```json
29{
30  "admins": ["yourgithubhere"],
31  "channels": ["zed"]
32}
33```
34
35## Testing collaborative features locally
36
37In one terminal, run Zed's collaboration server and the livekit dev server:
38
39```sh
40foreman start
41```
42
43In a second terminal, run two or more instances of Zed.
44
45```sh
46script/zed-local -2
47```
48
49This script starts one to four instances of Zed, depending on the `-2`, `-3` or `-4` flags. Each instance will be connected to the local `collab` server, signed in as a different user from `seed.json` or `seed.default.json`.
50
51# Deployment
52
53We run two instances of collab:
54
55- Staging (https://staging-collab.zed.dev)
56- Production (https://collab.zed.dev)
57
58Both of these run on the Kubernetes cluster hosted in Digital Ocean.
59
60Deployment is triggered by pushing to the `collab-staging` (or `collab-production`) tag in GitHub. The best way to do this is:
61
62- `./script/deploy-collab staging`
63- `./script/deploy-collab production`
64
65You can tell what is currently deployed with `./script/what-is-deployed`.
66
67# Database Migrations
68
69To create a new migration:
70
71```sh
72./script/create-migration <name>
73```
74
75Migrations are run automatically on service start, so run `foreman start` again. The service will crash if the migrations fail.
76
77When you create a new migration, you also need to update the [SQLite schema](./migrations.sqlite/20221109000000_test_schema.sql) that is used for testing.