Skip to content
Skillpedia
Deploy & cloud (DevOps)33k Β· #8903

railway-database

What it does

This skill adds maintained database services to a Railway project. It is for developers hosting apps on Railway who need a database and want it connected correctly.

When to use it

  • βœ“When you ask to add Postgres, Redis, MySQL or MongoDB to your Railway project.
  • βœ“When you want to connect your app to a database that is already on Railway.
  • βœ“When you need a database created with its volumes and connection settings in place.

Skill link

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/railway/database/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/railway/database/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œAdd Postgres to my Railway project and connect it to my API service.”

5 new skills a week. 1 minute to read.

How it works

The agent first checks whether a database already exists in your environment, creates the one you need if not, waits for it to deploy, and can wire its connection variables to your service.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Railway Database

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.

When to Use

  • User asks to "add a database", "add Postgres", "add Redis", etc.
  • User needs a database for their application
  • User asks about connecting to a database
  • User says "add postgres and connect to my server"
  • User says "wire up the database"

Decision Flow

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
skill

Check for Existing Databases

Before creating a database, check if one already exists.

For full environment config structure, see environment-config.md.

railway status --json

Then query environment config and check source.image for each service:

query 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:* β†’ Postgres
  • ghcr.io/railway/redis* or redis:* β†’ Redis
  • ghcr.io/railway/mysql* or mysql:* β†’ MySQL
  • ghcr.io/railway/mongo* or mongo:* β†’ MongoDB

Available Databases

Database Template Code
PostgreSQL postgres
Redis redis
MySQL mysql
MongoDB mongodb

Prerequisites

Get project context:

railway status --json

Extract:

  • id - project ID
  • environments.edges[0].node.id - environment ID

Get workspace ID (not in status output):

bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
  'query getWorkspace($projectId: String!) {
    project(id: $projectId) { workspaceId }
  }' \
  '{"projectId": "PROJECT_ID"}'
SCRIPT

Adding a Database

Step 1: Fetch Template

bash <<'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.

Step 2: Deploy Template

bash <<'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.

Connecting to the Database

After deployment, other services connect using reference variables.

For complete variable reference syntax and wiring patterns, see variables.md.

Backend Services (Server-side)

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}}

Frontend Applications

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):

  • Use the public URL variables (e.g., ${{MongoDB.MONGO_PUBLIC_URL}})
  • Requires TCP proxy to be enabled

Better pattern: Frontend β†’ Backend API β†’ Database

Example: Add PostgreSQL

bash <<'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 } 
FAQ

Does it create a duplicate database?

No. It checks for existing databases before creating anything.

Which databases are supported?

Postgres, Redis, MySQL and MongoDB, using official Railway templates.

What about other templates?

The skill says non-database templates, such as Ghost or n8n, belong to a separate Railway templates skill.

Details

Original description by the author

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.

repo: davila7/claude-code-templates

Popularity

GitHub stars
33k
Ranking position
#8903
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills