Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)33k · #8903

railway-database

Skill này làm gì

Skill này thêm các dịch vụ cơ sở dữ liệu được duy trì vào một dự án Railway. Skill dành cho lập trình viên lưu ứng dụng trên Railway, cần cơ sở dữ liệu và muốn nó được kết nối đúng cách.

Khi nào nên dùng

  • ✓Khi bạn yêu cầu thêm Postgres, Redis, MySQL hoặc MongoDB vào dự án Railway.
  • ✓Khi bạn muốn kết nối ứng dụng với một cơ sở dữ liệu đã có trên Railway.
  • ✓Khi bạn cần một cơ sở dữ liệu được tạo cùng các volume và thiết lập kết nối.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/railway/database/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thêm Postgres vào dự án Railway của tôi và kết nối nó với dịch vụ API của tôi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent kiểm tra trước xem đã có cơ sở dữ liệu trong môi trường của bạn chưa, tạo cái bạn cần nếu chưa có, chờ nó triển khai xong, và có thể nối các biến kết nối với dịch vụ của bạn.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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 } 
Câu hỏi thường gặp

Nó có tạo cơ sở dữ liệu trùng lặp không?

Không. Nó kiểm tra cơ sở dữ liệu đã có trước khi tạo bất cứ thứ gì.

Những cơ sở dữ liệu nào được hỗ trợ?

Postgres, Redis, MySQL và MongoDB, dùng các mẫu chính thức của Railway.

Còn các mẫu khác thì sao?

Skill nói rằng các mẫu không phải cơ sở dữ liệu, như Ghost hoặc n8n, thuộc về một skill mẫu Railway riêng.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
33k
Vị trí xếp hạng
#8903
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự