This repository has been archived on 2026-11-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
artifactapi/internal/database/postgres.go
T
unkin-agent 6fac114a56 Import golib from github.com/IUCLabs/golib (#183)
CI is moving to GitHub Actions runners that cannot reach git.unkin.net, so golib must resolve from its public path.

- Require github.com/IUCLabs/golib v0.3.0 in place of git.unkin.net/unkin/golib
- Import golib/pg from the new module path
- Drop the GOPRIVATE settings (Makefile, Dockerfile, Woodpecker, README) that only existed for golib

Reviewed-on: #183
Co-authored-by: unkin-agent <unkin-agent@unkin.net>
Co-committed-by: unkin-agent <unkin-agent@unkin.net>
2026-11-20 00:34:27 +11:00

36 lines
757 B
Go

package database
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/IUCLabs/golib/pg"
"git.unkin.net/unkin/artifactapi/migrations"
)
// migrationLockName names the cluster-wide advisory lock the migration run
// contends for; golib derives the key as FNV-1a/64 of it. Replicas starting
// together queue on it instead of racing each other through the DDL.
const migrationLockName = "artifactapi-migrations"
type DB struct {
Pool *pgxpool.Pool
}
func New(dsn string) (*DB, error) {
ctx := context.Background()
pool, err := pg.NewMigrated(ctx, dsn, migrations.FS, pg.MigrateOptions{
LockName: migrationLockName,
})
if err != nil {
return nil, err
}
return &DB{Pool: pool}, nil
}
func (db *DB) Close() {
db.Pool.Close()
}