-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrailway.toml
More file actions
27 lines (22 loc) · 1.11 KB
/
railway.toml
File metadata and controls
27 lines (22 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[build]
builder = "RAILPACK"
[environments.pr.deploy]
# For PR deploys, reset the target database and mirror the current staging database.
# NOTE: Set DB_PULL_REQUEST_SOURCE_URL to the staging database's public URL.
# You can copy that URL from Railway, then store it in Infisical as DB_PULL_REQUEST_SOURCE_URL.
# Also the staging server needs to have a Railway generated public domain (in addition to any
# custom domain you add).
preDeployCommand = """
set -e
# Check if either variable is missing or empty
if [ -z "$DATABASE_URL" ] || [ -z "$DB_PULL_REQUEST_SOURCE_URL" ]; then
echo "❌ Error: Missing DATABASE_URL or DB_PULL_REQUEST_SOURCE_URL (expected: staging DB public URL). Aborting."
exit 1
fi
echo "🧹 Wiping existing database schema..."
mise exec -- psql "$DATABASE_URL" --command="DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
echo "📥 Cloning database from source URL..."
mise exec -- pg_dump --no-owner --no-acl --format=c "$DB_PULL_REQUEST_SOURCE_URL" | \\
mise exec -- pg_restore --no-owner --no-acl --clean --if-exists --exit-on-error --dbname="$DATABASE_URL"
echo "✅ Database mirror complete!"
"""