CockroachDB Driver
CockroachDB support follows PostgreSQL-like SQL syntax, with CockroachDB's serializable transaction behavior.
Packages
import (
"database/sql"
"github.com/yaop-labs/queen"
"github.com/yaop-labs/queen/drivers/cockroachdb"
_ "github.com/jackc/pgx/v5/stdlib"
)
db, err := sql.Open("pgx", os.Getenv("DATABASE_URL"))
if err != nil {
return err
}
driver, err := cockroachdb.New(db)
if err != nil {
return err
}
q := queen.New(driver)
How it works
| Area | Implementation |
|---|---|
| Migration table | SQL table with metadata columns. |
| Lock table | Separate <table>_lock table with lock_key primary key and expires_at. |
| Identifier quoting | Double quotes. |
| Placeholders | $1, $2, ... |
| Lock owner | Generated owner ID per driver instance. |
| Locking | Table-backed lock through cleanup, check, and insert. |
| Unlock | Deletes the lock row for the current owner. |
| Execution | database/sql transaction through the shared base driver. |
| Atomic record | No. Migration body commits before Record. |
Guarantees
- Lock rows expire and are cleaned during acquisition attempts.
- Wrapped
sql.ErrNoRowsis treated as no active lock. - Queen uses natural status ordering before planning operations.
Limitations
- CockroachDB can return retryable serialization errors (
40001). - The current driver does not implement a CockroachDB retry loop around migration transactions.
- Migration metadata is not written in the same transaction as the migration body.
Operational advice
- Run one migrator job per environment.
- If a migration fails with a retryable transaction error, rerun the migrator after checking whether the migration body committed.
- Prefer PostgreSQL for the first production target when you need Queen's strongest guarantees today.