Исправить замечания ревью кода: убрать повтор в AppendOnce за счёт запаса у чистки ключей, вынести MessagePayload и SameContent, принять X-Request-Id от балансировщика, упростить фоновые задачи сервера, сократить комментарии
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
//
|
||||
// Server-side timeouts are constants rather than settings: they bound how
|
||||
// long one request can hold a connection, and the request deadline of the API
|
||||
// is chosen against them. The pool size is a setting, because the scaling
|
||||
// study varies it.
|
||||
// is chosen against them.
|
||||
package postgres
|
||||
|
||||
import (
|
||||
@@ -75,21 +74,20 @@ func NewPool(ctx context.Context, dsn string, maxConns int32) (*pgxpool.Pool, er
|
||||
return pool, nil
|
||||
}
|
||||
|
||||
// Migrate applies pending migrations and returns the versions it applied. A
|
||||
// session advisory lock serialises concurrent starts, so several API
|
||||
// replicas may call it at once; applied versions are recorded, which makes a
|
||||
// repeated run a no-op.
|
||||
// Migrate applies pending migrations and returns their versions; a session
|
||||
// advisory lock makes overlapping runs wait for each other.
|
||||
func Migrate(ctx context.Context, pool *pgxpool.Pool) ([]int64, error) {
|
||||
db := stdlib.OpenDBFromPool(pool)
|
||||
defer db.Close()
|
||||
locker, err := lock.NewPostgresSessionLocker()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("migration lock: %w", err)
|
||||
}
|
||||
db := stdlib.OpenDBFromPool(pool)
|
||||
provider, err := goose.NewProvider(goose.DialectPostgres, db, migrations.FS, goose.WithSessionLocker(locker))
|
||||
if err != nil {
|
||||
db.Close()
|
||||
return nil, fmt.Errorf("load migrations: %w", err)
|
||||
}
|
||||
defer provider.Close()
|
||||
results, err := provider.Up(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("apply migrations: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user