2 months ago
I tried to run it as Pre-deploy Command but it is not working. I can't find documentatino how to setup the migration process
50 Replies
2 months ago
Can you define "not working"?
2 months ago
Error logs would help
I used as command: migrate -path ./migrations -database "$DATABASE_URL" up
and it says Pre-deploy command failed
2 months ago
Can you provide logs?
snapshot] received sha256:316c1a5197f68521a3b01b52598b02bfbd939a7e8ef3c30198f702cdef83553f md5:d09e24f9d1cd37e121d702e6d7ae8bd1
receiving snapshot5.6 KB661ms
analyzing snapshot5.6 KB
scheduling build on Metal builder "builder-srzafc"
uploading snapshot5.6 KB
unpacking archive30 KB
using build driver railpack-v0.20.0
╭─────────────────╮
│ Railpack 0.20.0 │
╰─────────────────╯
↳ Detected Golang
↳ Using go mod
Packages
──────────
go │ 1.24.0 │ go.mod (1.24.0)
Steps
──────────
▸ install
$ go mod download
▸ build
$ go build -ldflags="-w -s" -o out
Deploy
──────────
$ ./out
load build definition from ./railpack-plan.json
0ms
copy / /app cached
0ms
go mod download cached
0ms
copy go.sum, go.mod, /app cached
0ms
install mise packages: go cached
0ms
install apt packages: tzdata cached
0ms
go build -ldflags=-w -s -o out cached
0ms
exporting to docker image format
190ms
containerimage.config.digest: sha256:42131894f5f06ede356e3d942fa96c5dbdc2843f417751118a001f48a8bfc557
containerimage.digest: sha256:4258b5d30de3ca2f83d010bd3be263dce41fe759af22bde5b97579d4154cf77b
containerimage.descriptor: eyJtZWRpYVR5cGUiOiJhcHBsaWNhdGlvbi92bmQub2NpLmltYWdlLm1hbmlmZXN0LnYxK2pzb24iLCJkaWdlc3QiOiJzaGEyNTY6NDI1OGI1ZDMwZGUzY2EyZjgzZDAxMGJkM2JlMjYzZGNlNDFmZTc1OWFmMjJiZGU1Yjk3NTc5ZDQxNTRjZjc3YiIsInNpemUiOjEwNTQsImFubm90YXRpb25zIjp7Im9yZy5vcGVuY29udGFpbmVycy5pbWFnZS5jcmVhdGVkIjoiMjAyNi0wMy0xOVQxNToyNzowNFoifSwicGxhdGZvcm0iOnsiYXJjaGl0ZWN0dXJlIjoiYW1kNjQiLCJvcyI6ImxpbnV4In19
image push34.1 MB2 months ago
Look at deploy logs
2 months ago
(You sent the build logs)
railway build crashed and gave /bin/bash: line 1: migrate: command not found
2 months ago
You should be migrating post-build...
2 months ago
There is your error: Railway can't find the migrate command.
It seems that first you need to install their CLI. At this point, I would recommend creating a Dockerfile (you can use AI for this) and then instructing it to install the CLI: .
Just make sure to tell your AI to not run the migrate command inside the Dockerfile and keep the post-deploy command.
2 months ago
Or you can do it by hand if you know how to do it 🙂
ahh knew that I need docker I thought I could let railway to install that before doing the migrate command
2 months ago
It might be possible via environment variables: https://railpack.com/config/environment-variables but I would recommend using a Dockerfile if you can.
I'm still improving the documentation here but you should be able to just install that binary you need with mise.
You could try a mise.toml file, but it may not work properly until next week (0.21.0 release)
packages works right now, here's an example: https://github.com/iloveitaly/dreamhost-dns-updater/blob/main/railpack.json
for migrations, you'll want that in your startCommand (builders have no DB access)
mise has a go backend that you can use to install migrate https://mise.jdx.dev/dev-tools/backends/go.html
made it with docker now and added the pre-build command again
on the docker instance added the variable DATABASE_URL and now I get error: no scheme
2 months ago
I really like Railpack. I hope you can improve the documentation on how to do basic things such as this. That's my only reason for recommending a Dockerfile.
2 months ago
Maybe you have to point to some kind of schema file? Not too familar with migrate, give me a minute
my dockerfile and railway used diff keyword for postgresql or postgre
so my command is now: migrate -path ./migrations -database "$(echo $DATABASE_URL | sed 's/^postgresql:/postgres:/')" up
While humans (and many modern drivers) treat postgres:// and postgresql:// as the same thing, the golang-migrate CLI is very picky. It looks specifically for postgres:// to identify which internal driver to load. When it sees postgresql://, it essentially throws its hands up and says, "I don't know what scheme this is."
@ThallesComH yeah, improved docs needs to happen. There's a list of some more obvious improvements that need to get landed first then I can take some time to really improve the docs, examples, etc.
@ThallesComH Same crap again failed to build. Something is wrong with that process
2 months ago
Can you send me your Dockerfile?
2 months ago
Wouldn't make sense to create a documentation for each framework IMO, pre-deploy just works in my experience (I'm on NodeJS land btw).
# Build stage
FROM golang:1.24-bookworm AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app .
# Runtime stage
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
tar \
&& rm -rf /var/lib/apt/lists/*
# Install golang-migrate binary
RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-amd64.tar.gz | tar xvz \
&& mv migrate /usr/local/bin/migrate \
&& chmod +x /usr/local/bin/migrate
WORKDIR /app
COPY --from=builder /app/app /app/app
COPY --from=builder /app/migrations /app/migrations
COPY migrate.sh /app/migrate.sh
RUN chmod +x /app/migrate.sh
EXPOSE 9090
CMD ["/bin/sh", "-c", "/app/migrate.sh && /app/app"]2 months ago
Wait, so it deploys successfully but your database is still empty?
Starting Container
1/u create_users_table (74.977159ms)
2/u create_plans_table (156.340898ms)
3/u create_monitors_table (230.98548ms)
4/u create_monitor_types_table (303.535058ms)
5/u update_monitors_typeid (383.929834ms)
6/u create_monitor_logs_table (459.396909ms)
7/u create_monitor_phases_table (540.742469ms)
8/u add_phase_id_to_monitors_table (615.202262ms)
9/u update_monitor_logs_phase_id (687.141404ms)
10/u add_role_to_users_table (761.083751ms)
11/u create_password_reset_tokens_table (836.643425ms)
12/u create_monitor_webhooks_table (831.752403ms)
13/u add_type_to_monitor_webhooks_table (821.129856ms)
14/u add_max_webhooks_to_plans (816.539071ms)
15/u create_status_pages_table (816.62487ms)
16/u remove_phase_id_from_status_page_monitors (809.498675ms)
17/u add_slug_and_published_to_status_pages (803.915179ms)
Stopping Container
Starting Container
no change
2026/03/19 17:44:10 Connected to database.
2026/03/19 17:44:10 log retention cleanup failed: failed to connect to user= database=: /tmp/.s.PGSQL.5432 (/tmp): dial error: dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory
2 months ago
For that final error, your client might not be using the database_url environment variable for some reason. IIRC Golang uses a different type of URL for their database clients.
just changed to use in my db init
connStr := os.Getenv("DATABASE_URL") as I was using my local setup
Status changed to Solved passos • 2 months ago