Loading...
Loading...
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.
npx skill4agent add davila7/claude-code-templates railway-databaserailway-templatesUser 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
skillrailway status --jsonsource.imagequery environmentConfig($environmentId: String!) {
environment(id: $environmentId) {
config(decryptVariables: false)
}
}config.servicessource.imageghcr.io/railway/postgres*postgres:*ghcr.io/railway/redis*redis:*ghcr.io/railway/mysql*mysql:*ghcr.io/railway/mongo*mongo:*| Database | Template Code |
|---|---|
| PostgreSQL | |
| Redis | |
| MySQL | |
| MongoDB | |
railway status --jsonidenvironments.edges[0].node.idbash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'query getWorkspace($projectId: String!) {
project(id: $projectId) { workspaceId }
}' \
'{"projectId": "PROJECT_ID"}'
SCRIPTbash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'query template($code: String!) {
template(code: $code) {
id
name
serializedConfig
}
}' \
'{"code": "postgres"}'
SCRIPTidserializedConfigbash <<'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"
}
}'
SCRIPTserializedConfig| Database | Variable Reference |
|---|---|
| PostgreSQL | |
| Redis | |
| MySQL | |
| MongoDB | |
${{MongoDB.MONGO_PUBLIC_URL}}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 } }' '{}'
# 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": "..."}}'
SCRIPTrailway-environment{
"services": {
"<backend-service-id>": {
"variables": {
"DATABASE_URL": { "value": "${{Postgres.DATABASE_URL}}" }
}
}
}
}{
"data": {
"templateDeployV2": {
"projectId": "e63baedb-e308-49e9-8c06-c25336f861c7",
"workflowId": "deployTemplate/project/e63baedb-e308-49e9-8c06-c25336f861c7/xxx"
}
}
}| Error | Cause | Solution |
|---|---|---|
| Template not found | Invalid template code | Use: |
| Permission denied | User lacks access | Need DEVELOPER role or higher |
| Project not found | Invalid project ID | Run |
railway-environmentDATABASE_URL: { "value": "${{Postgres.DATABASE_URL}}" }DATABASE_URL=${{Postgres.DATABASE_URL}}railway-environmentrailway-servicerailway-deployment