## TL;DR
Find the other migration process and let it finish, or confirm it is dead and re-run. Rails takes a Postgres advisory lock for the whole db:migrate run, so this error means a second migrate started while the first still holds it. Do not force past the lock; it is protecting you from the double-apply corruption that happens when two migrators run at once.

```text
ActiveRecord::ConcurrentMigrationError: Cannot run migrations because another migration process is currently running.
```

## Steps

1. Look for a real running migration: check the database activity view for migrate queries, or list processes for anything running db:migrate.
   Expected: you either find a live migrator or you find nothing.

2. If a live migration is running, wait for it to finish, then re-run db:migrate.
   Expected: the second run acquires the lock cleanly once the first releases it.

3. If no live process exists, the lock is stale from a killed deploy. Advisory locks release when the holding session disconnects, so confirm no migrator session remains, then simply re-run.
   Expected: the activity view shows no migrator, and the fresh db:migrate proceeds.

4. Re-run db:migrate and watch it complete.
   Expected: migrations apply and schema_migrations is up to date.

5. Stop the races. Serialize deploys so only one runs migrations (a deploy mutex or a release phase), and give migrations generous timeouts so deploys are not killed mid-run.
   Expected: no overlapping migrators on future deploys.

## Use this when
- ConcurrentMigrationError appears during a deploy.
- Two deploys race db:migrate against the same database.
- A killed deploy left the advisory lock held.
- An agent retried a migration while the first attempt was still running.

## Not for this skill when
- Two migrations deadlock each other (that is a lock-ordering problem).
- The migration itself fails on its own merits (fix the migration).
- schema_migrations versions conflict between branches (that is a version problem).

## Variant phrasings
- another migration process is currently running
- ConcurrentMigrationError rails deploy
- rails migration lock stuck
- cannot run migrations another process running

## Why it happens
Rails takes a Postgres advisory lock for the entire db:migrate run so that exactly one migrator touches the schema at a time. Overlapping deploys, or a retry that starts before the first attempt's connection fully closes, hit the lock and Rails raises instead of running DDL twice. The error is the protection working.

## Edge cases
- The lock holder might be a console session or a stuck CI job, not a deploy. Check broadly before assuming.
- Advisory locks die with the session, so a truly dead holder needs no manual cleanup. Just re-run.
- Never disable the advisory lock to make this go away. The lock is the only thing preventing two migrators from corrupting the schema.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_9uB5AnJ_T3BRvKdcsXZAWw
