---
name: railway-iac-migration
description: Migrate Railway Config as Code (railway.json / railway.toml) to Infrastructure as Code (.railway/railway.ts). Use when a repo has railway.json or railway.toml files, when the user mentions "config as code", "railway.toml", "railway.json", "migrate railway config", "railway config migrate", or before the Config as Code hard cutoff on 2026-12-01. For authoring IaC from scratch, use the railway-iac skill.
license: MIT
metadata:
  version: "1.0.0"
title: railway-iac-migration
canonical_url: https://skilld.dev/gh/sivarampg/railway-iac-skill/railway-iac-migration
last_updated: 2026-10-04T16:18:07.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/field-mapping.md](https://skilld.dev/api/skills-raw/sivarampg/railway-iac-skill/railway-iac-migration/references/field-mapping.md).
>
> If the user asked to install this Skill, run `npx skilld install sivarampg/railway-iac-skill/railway-iac-migration`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/railway-iac-migration`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/sivarampg/railway-iac-skill/railway-iac-migration) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/railway-iac-migration`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/railway-iac-migration --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/railway-iac-migration --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Migrate Railway Config as Code to IaC

Config as Code (`railway.json` / `railway.toml`) is **deprecated**. It stops being read on **2026-12-01** (hard cutoff), and new services can't opt in. The replacement is Infrastructure as Code: `.railway/railway.ts` evaluated by the Railway CLI.

| | Config as Code | Infrastructure as Code |
|---|---|---|
| Scope | One service's deployment | Whole project/environment |
| File | `railway.json` / `railway.toml` in the repo | `.railway/railway.ts` |
| Evaluated | At deploy time, overrides dashboard | By CLI: `railway config plan` / `apply` |

**A service cannot be managed by both systems.** `railway config plan` refuses to run while any targeted service still reads a CaC file; the error names the service. Migration means: get config into `railway.ts`, get CaC out of the deploy path (remove the file AND clear any custom config-path setting), then apply.

## Step 1: Inventory what needs migrating

```bash
# Find every CaC file in the repo
find . -name "railway.toml" -o -name "railway.json" | grep -v node_modules
```

Also check each service's **Settings** page for a **custom config file path** (e.g. `/backend/railway.toml`): a file outside the default search locations still counts as CaC-managed, and its path must be cleared during migration.

Note the repo topology; it decides the output shape:

- **One repo holds all services in the environment**: single `railway.ts`, no `partial` export.
- **Services live in separate repos**: run the migration **in each repo**; each writes `export const partial = "<service name>"` so it owns only its slice.

## Step 2: Migrate with the CLI (preferred)

```bash
# Preview the generated authoring file (writes nothing)
railway config migrate

# Write .railway/railway.ts AND clear the Railway Config File settings on the services
railway config migrate --apply

# Also delete the old railway.json / railway.toml files
railway config migrate --apply --delete-files

# Options
railway config migrate --service api --apply      # one service only; writes a named `partial` export
railway config migrate --lang py --apply          # Python (beta); --lang go for Go
```

Behavior to expect:

- Monorepo: `migrate` finds every CaC file in the repository and merges them into **one** `railway.ts`. No `partial` export.
- Single-service repo (`--service` or one file found): writes `export const partial = "<service name>"`, matching how CaC applied per-service.
- `--apply` clears the dashboard's "Railway Config File" setting so deploys stop reading the old file.

If `railway config migrate` isn't available in the installed CLI, use the manual path: `railway config pull --force`, translate fields per **[references/field-mapping.md](https://skilld.dev/api/skills-raw/sivarampg/railway-iac-skill/railway-iac-migration/references/field-mapping.md)**, then continue at Step 3.

## Step 3: Detach Config as Code completely

Both must happen or the service stays CaC-managed and `plan` keeps failing:

1. **Remove `railway.json` / `railway.toml`** from the service's source repo (or use `--delete-files`).
2. **Clear the custom config file path** in service Settings, if one was set. (`--apply` does this; the manual path requires doing it in the dashboard.)

## Step 4: Review the plan to verify

```bash
railway config plan
```

A good migration plan shows **only** the settings you intentionally moved (e.g. `build`, `start`, `healthcheck` updates on migrated services). Red flags (do NOT apply):

- Deletes of services, variables, volumes, or buckets you didn't intend
- Changes to unrelated services
- A plan still blocked by "managed by config file" errors, meaning a CaC file or custom path survived (Step 3)

If the CaC file had settings the DSL doesn't cover, `config migrate` preserves them. Diff the generated `railway.ts` against the old file field by field before deleting it (field-mapping reference below).

## Step 5: Apply

```bash
railway config apply            # interactive confirm
railway config apply --yes      # non-interactive; + --confirm-destructive if the plan marks deletes
```

For a single-service (partial) migration, the first apply also **claims ownership** of the declared resources. It runs even when the plan shows no changes. That's expected.

## Translating `environments.*` overrides

CaC `environments.<name>` blocks become `ctx` conditionals in `defineRailway`:

```ts
// railway.json: { "environments": { "staging": { "deploy": { "startCommand": "npm run staging" } } } }
const web = service("web", {
  start: ctx.isEnvironment("staging") ? "npm run staging" : "npm start",
});
```

CaC `environments.pr` applied to every ephemeral PR environment. There's no `ctx.isPR`; reproduce it by checking the ephemeral environment name via `ctx.environment`, or keep per-env conditionals for the environments you actually deploy.

## Field mapping

Full CaC-to-DSL translation table (confirmed shorthands vs. fields handled by `config migrate`): **[references/field-mapping.md](https://skilld.dev/api/skills-raw/sivarampg/railway-iac-skill/railway-iac-migration/references/field-mapping.md)**.

## Working agreement

- **Always run `railway config migrate` (preview) before `--apply`.** Read the generated file before it lands.
- **Never apply a plan you haven't reviewed.** Destructive lines are marked; a stray `--yes` can't delete (needs `--confirm-destructive`), but a reviewed-wrong plan still can.
- **Delete old CaC files only after the plan is clean.** They're the ground truth for the diff.
- **Secrets stay on Railway.** Generated `preserve()` entries keep existing values; never paste secret values into `railway.ts`, and be deliberate about `--include-variables` (it decrypts non-sealed variables into source).
- **One authoring language per repo.** Don't leave both `railway.ts` and `railway.py` in `.railway/`.
- For multi-repo setups, repeat in **every** repo. A partial only covers its own slice.

## Troubleshooting

| Symptom | Fix |
|---|---|
| `plan` stops: "service managed by railway.json/railway.toml" | CaC file still in repo or custom config path still set. Finish Step 3 |
| Migrated file has `partial`, now other repos' files fail | Expected: once any partial is named, every file targeting that environment must export one |
| Plan shows unexpected deletes | CaC config wasn't fully translated. Compare old file vs `railway.ts`, then re-plan |
| Plan shows tracing being removed | SDKs don't support `tracing` yet; don't apply. See `railway-iac` skill |
