|
1 | 1 | # Configuration |
2 | 2 |
|
3 | | -## CLI (no server) |
| 3 | +- [Config Files](#config-files) |
| 4 | +- [Local](#local) |
| 5 | +- [Server Deployment](#server-deployment) |
| 6 | +- [Profiles](#profiles) |
| 7 | +- [Secret Resolution](#secret-resolution) |
4 | 8 |
|
5 | | -The fastest way to get started. The CLI auto-starts a lightweight background server on your machine and connects directly to your database — no separate server deployment needed. |
| 9 | +## Config Files |
| 10 | + |
| 11 | +SchemaBot uses different config files depending on how you run it: |
| 12 | + |
| 13 | +| File | Location | Purpose | Used by | |
| 14 | +|------|----------|---------|---------| |
| 15 | +| `schemabot.yaml` | In your schema directory | Declares the database name and type | CLI (plan, apply, pull) | |
| 16 | +| `~/.schemabot/config.yaml` | Home directory | CLI profiles and local database connections | CLI (all commands) | |
| 17 | +| Server config (`SCHEMABOT_CONFIG_FILE`) | Anywhere | Storage DSN, database configs, Tern endpoints | `schemabot serve` | |
| 18 | + |
| 19 | +`schemabot.yaml` — declares which database your schema files belong to: |
| 20 | + |
| 21 | +```yaml |
| 22 | +database: mydb |
| 23 | +type: mysql |
| 24 | +``` |
| 25 | +
|
| 26 | +`~/.schemabot/config.yaml` — tells the CLI how to connect: |
| 27 | + |
| 28 | +```yaml |
| 29 | +default_profile: local |
| 30 | +
|
| 31 | +profiles: |
| 32 | + staging: |
| 33 | + endpoint: http://localhost:8080 |
| 34 | +
|
| 35 | +local: |
| 36 | + mydb: |
| 37 | + type: mysql |
| 38 | + environments: |
| 39 | + staging: |
| 40 | + dsn: "root@tcp(localhost:3306)/mydb" |
| 41 | +``` |
| 42 | + |
| 43 | +Server config (`SCHEMABOT_CONFIG_FILE`) — only used when deploying SchemaBot as a server: |
| 44 | + |
| 45 | +```yaml |
| 46 | +storage: |
| 47 | + dsn: "env:SCHEMABOT_DSN" |
| 48 | +databases: |
| 49 | + mydb: |
| 50 | + type: mysql |
| 51 | + environments: |
| 52 | + staging: |
| 53 | + dsn: "env:STAGING_DSN" |
| 54 | +``` |
| 55 | + |
| 56 | +The first two are for CLI usage. The server config is separate — see [Server Deployment](#server-deployment) for details. |
| 57 | + |
| 58 | +## Local |
| 59 | + |
| 60 | +When using SchemaBot without a server deployment, the CLI auto-starts a lightweight background server on your machine. Database connection details are stored in the `local` section of the config. The `pull` command sets this up automatically. |
| 61 | + |
| 62 | +```yaml |
| 63 | +# ~/.schemabot/config.yaml |
| 64 | +local: |
| 65 | + mydb: |
| 66 | + type: mysql |
| 67 | + environments: |
| 68 | + staging: |
| 69 | + dsn: "root@tcp(localhost:3306)/mydb" |
| 70 | + production: |
| 71 | + dsn: "env:PRODUCTION_DSN" |
| 72 | + mypsdb: |
| 73 | + type: vitess |
| 74 | + environments: |
| 75 | + production: |
| 76 | + organization: myorg |
| 77 | + token: "env:PLANETSCALE_SERVICE_TOKEN" |
| 78 | +``` |
| 79 | + |
| 80 | +### Adding a database |
6 | 81 |
|
7 | 82 | ```bash |
| 83 | +# Pull creates the local config entry automatically |
8 | 84 | schemabot pull --dsn "root@tcp(localhost:3306)/mydb" -e staging -o ./schema |
9 | | -schemabot plan -s ./schema -e staging |
10 | | -schemabot apply -s ./schema -e staging |
11 | 85 | ``` |
12 | 86 |
|
13 | | -Connection details are stored in `~/.schemabot/config.yaml` under the `local` section. The `pull` command sets this up automatically. A background server process auto-starts on first use and stores state in a `_schemabot` database on your local MySQL. |
| 87 | +This writes the schema files and adds `mydb/staging` to `~/.schemabot/config.yaml`. |
14 | 88 |
|
15 | | -See the [README quickstart](../README.md#cli) for full setup instructions. |
| 89 | +### Managing the background server |
| 90 | + |
| 91 | +```bash |
| 92 | +schemabot local status # show server state, PID, port |
| 93 | +schemabot local stop # stop the background server |
| 94 | +schemabot local reset # stop server and drop _schemabot database |
| 95 | +``` |
16 | 96 |
|
17 | 97 | ## Server Deployment |
18 | 98 |
|
19 | | -For GitHub PR integration, team coordination, or managing many databases, deploy SchemaBot as a server. The server loads config from the `SCHEMABOT_CONFIG_FILE` environment variable. |
| 99 | +For GitHub PR integration, team coordination, or managing many databases, deploy SchemaBot as a server. |
| 100 | + |
| 101 | +The server loads config from a YAML file. Set `SCHEMABOT_CONFIG_FILE` to the path: |
| 102 | + |
| 103 | +```bash |
| 104 | +export SCHEMABOT_CONFIG_FILE=/etc/schemabot/config.yaml |
| 105 | +schemabot serve |
| 106 | +``` |
20 | 107 |
|
21 | 108 | ### Single-process (recommended for most deployments) |
22 | 109 |
|
@@ -52,6 +139,33 @@ tern_deployments: |
52 | 139 | production: "tern1-production:9090" |
53 | 140 | ``` |
54 | 141 |
|
| 142 | +## Profiles |
| 143 | + |
| 144 | +CLI profiles let you switch between local mode and server deployments. Use `--profile` to select one, or set a default. |
| 145 | + |
| 146 | +```yaml |
| 147 | +# ~/.schemabot/config.yaml |
| 148 | +default_profile: local |
| 149 | +
|
| 150 | +profiles: |
| 151 | + staging: |
| 152 | + endpoint: http://localhost:8080 |
| 153 | + production: |
| 154 | + endpoint: https://schemabot.example.com |
| 155 | +``` |
| 156 | + |
| 157 | +```bash |
| 158 | +schemabot plan -s ./schema -e staging # uses default profile |
| 159 | +schemabot plan -s ./schema -e staging --profile staging # explicit server profile |
| 160 | +schemabot plan -s ./schema -e staging --profile local # force local mode |
| 161 | +``` |
| 162 | + |
| 163 | +`local` is a reserved profile name that triggers local mode. Set `default_profile: local` to make it the default. |
| 164 | + |
| 165 | +```bash |
| 166 | +schemabot configure # interactive profile setup |
| 167 | +``` |
| 168 | + |
55 | 169 | ## Secret Resolution |
56 | 170 |
|
57 | 171 | DSN and credential values support secret resolution prefixes: |
|
0 commit comments