| 1 | # Railway configuration |
| 2 | |
| 3 | This project defines its Railway infrastructure in code. |
| 4 | |
| 5 | ```txt |
| 6 | .railway/railway.ts |
| 7 | ``` |
| 8 | |
| 9 | Use this file to describe the Railway project you want: services, databases, buckets, custom domains, replicas, groups, and environment variables. |
| 10 | |
| 11 | The TypeScript file imports `railway/iac`. Install the SDK from the repository root: |
| 12 | |
| 13 | ```bash |
| 14 | npm install railway |
| 15 | ``` |
| 16 | |
| 17 | ## Common commands |
| 18 | |
| 19 | Create the configuration files: |
| 20 | |
| 21 | ```bash |
| 22 | railway config init |
| 23 | ``` |
| 24 | |
| 25 | Import an existing Railway project into code: |
| 26 | |
| 27 | ```bash |
| 28 | railway config pull |
| 29 | ``` |
| 30 | |
| 31 | Preview what Railway would change: |
| 32 | |
| 33 | ```bash |
| 34 | railway config plan |
| 35 | ``` |
| 36 | |
| 37 | Apply the planned changes: |
| 38 | |
| 39 | ```bash |
| 40 | railway config apply |
| 41 | ``` |
| 42 | |
| 43 | ## Notes |
| 44 | |
| 45 | - `railway config plan` is safe and does not change Railway. |
| 46 | - `railway config apply` previews changes and asks before applying unless you pass `--yes`. |
| 47 | - Destructive changes in non-interactive or agent sessions require `railway config apply --confirm-destructive` after reviewing the plan. |
| 48 | - CI should pin a plan (`railway config plan --out railway-plan.json`) and apply that file on merge (`railway config apply --plan railway-plan.json --yes --confirm-destructive` |
| 49 | - Services already managed by `railway.json` must be migrated before `.railway/railway.ts` can manage them. |
| 50 | - Keep one `.railway` file for the whole project. A named `export const partial` (or |
| 51 | - Use `replicas` for scaling; advanced placement can still specify region names. |
| 52 | - Use `group("Name", [resources])` to keep large projects organized on the Railway canvas. |
| 53 | - Secrets imported from Railway are rendered as `preserve()` so existing values are retained without writing secret values to source. Use `railway config pull --omit-preserved-variables` |
| 54 | - `railway config migrate` finds every `railway.json` / |