Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Add official Railway database services (Postgres, Redis, MySQL, MongoDB). Use when user wants to add a database, says "add postgres", "add redis", "add database", "connect to database", or "wire up the database". For other templates (Ghost, Strapi, n8n), use the railway-templates skill.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 32% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 60% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 37% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 178% | 0% |
| case-21 | ✓→✗ | ▼ Worse | 6% | 0% |
Add official Railway database services. These are maintained templates with pre-configured volumes, networking, and connection variables.
For non-database templates, see the railway-templates skill.
ALWAYS check for existing databases FIRST before creating.
User mentions database
│
Check existing DBs first
(query env config for source.image)
│
┌────┴────┐
Exists Doesn't exist
│ │
│ Create database
│ (CLI or API)
│ │
│ Wait for deployment
│ │
└─────┬─────┘
│
User wants to
connect service?
│
┌─────┴─────┐
Yes No
│ │
Wire vars Done +
via env suggest wiring
skillBefore creating a database, check if one already exists.
For full environment config structure, see environment-config.md.
bashrailway status --json
Then query environment config and check source.image for each service:
graphqlquery environmentConfig($environmentId: String!) { environment(id: $environmentId) { config(decryptVariables: false) } }
The config.services object contains each service's configuration. Check source.image for:
ghcr.io/railway/postgres* or postgres:* → Postgresghcr.io/railway/redis* or redis:* → Redisghcr.io/railway/mysql* or mysql:* → MySQLghcr.io/railway/mongo* or mongo:* → MongoDB| Database | Template Code | |----------|---------------| | PostgreSQL | postgres | | Redis | redis | | MySQL | mysql | | MongoDB | mongodb |
Get project context:
bashrailway status --json
Extract:
id - project IDenvironments.edges[0].node.id - environment IDGet workspace ID (not in status output):
bashbash <<'SCRIPT' ${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \ 'query getWorkspace($projectId: String!) { project(id: $projectId) { workspaceId } }' \ '{"projectId": "PROJECT_ID"}' SCRIPT
bashbash <<'SCRIPT' ${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \ 'query template($code: String!) { template(code: $code) { id name serializedConfig } }' \ '{"code": "postgres"}' SCRIPT
This returns the template's id and serializedConfig needed for deployment.
bashbash <<'SCRIPT' ${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \ 'mutation deployTemplate($input: TemplateDeployV2Input!) { templateDeployV2(input: $input) { projectId workflowId } }' \ '{ "input": { "templateId": "TEMPLATE_ID", "serializedConfig": SERIALIZED_CONFIG, "projectId": "PROJECT_ID", "environmentId": "ENVIRONMENT_ID", "workspaceId": "WORKSPACE_ID" } }' SCRIPT
Important: serializedConfig is the exact object from the template query, not a string.
After deployment, other services connect using reference variables.
For complete variable reference syntax and wiring patterns, see variables.md.
Use the private/internal URL for server-to-server communication:
| Database | Variable Reference | |----------|-------------------| | PostgreSQL | ${{Postgres.DATABASE_URL}} | | Redis | ${{Redis.REDIS_URL}} | | MySQL | ${{MySQL.MYSQL_URL}} | | MongoDB | ${{MongoDB.MONGO_URL}} |
Important: Frontends run in the user's browser and cannot access Railway's private network. They must use public URLs or go through a backend API.
For direct database access from frontend (not recommended):
${{MongoDB.MONGO_PUBLIC_URL}})Better pattern: Frontend → Backend API → Database
bashbash <<'SCRIPT' # 1. Get context railway status --json # Extract project.id and environment.id # 2. Get workspace ID ${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \ 'query { project(id: "proj-id") { workspaceId } }' '{}' # 3. Fetch Postgres template ${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \ 'query { template(code: "postgres") { id serializedConfig } }' '{}' # 4. Deploy template ${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \ 'mutation deploy($input: TemplateDeployV2Input!) { templateDeployV2(input: $input) { projectId workflowId } }' \ '{"input": {"templateId": "...", "serializedConfig": {...}, "projectId": "...", "environmentId": "...", "workspaceId": "..."}}' SCRIPT
Use railway-environment skill to add the variable reference:
json{ "services": { "<backend-service-id>": { "variables": { "DATABASE_URL": { "value": "${{Postgres.DATABASE_URL}}" } } } } }
Successful deployment returns:
json{ "data": { "templateDeployV2": { "projectId": "e63baedb-e308-49e9-8c06-c25336f861c7", "workflowId": "deployTemplate/project/e63baedb-e308-49e9-8c06-c25336f861c7/xxx" } } }
Each database template creates:
| Error | Cause | Solution | |-------|-------|----------| | Template not found | Invalid template code | Use: postgres, redis, mysql, mongodb | | Permission denied | User lacks access | Need DEVELOPER role or higher | | Project not found | Invalid project ID | Run railway status --json for correct ID |
railway-environment skill to stage: DATABASE_URL: { "value": "${{Postgres.DATABASE_URL}}" }DATABASE_URL=${{Postgres.DATABASE_URL}}"railway-environment skill to add variable referencesrailway-service skillrailway-deployment skillOther measured skills in the registry, with their headline benchmark lift.