Skip to content

Commit

Permalink
Do not apply schemas in a transaction. (#1369)
Browse files Browse the repository at this point in the history
Just do retries on fast failures.
  • Loading branch information
n-g authored Jan 10, 2025
1 parent 74989fe commit 65a9992
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions library/oss/postgres/prepare/database/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/cenkalti/backoff/v4"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"namespacelabs.dev/foundation/framework/resources/provider"
postgresclass "namespacelabs.dev/foundation/library/database/postgres"
"namespacelabs.dev/foundation/library/oss/postgres"
Expand Down Expand Up @@ -82,12 +81,13 @@ func main() {
}()

for _, schema := range p.Intent.Schema {
if _, err := universepg.ReturnFromReadWriteTx(ctx, db, backOff{
if err := backoff.Retry(func() error {
_, err := db.Exec(ctx, string(schema.Contents))
return err
}, backOff{
interval: 100 * time.Millisecond,
deadline: time.Now().Add(5 * time.Second),
deadline: time.Now().Add(15 * time.Second),
jitter: 100 * time.Millisecond,
}, func(ctx context.Context, tx pgx.Tx) (pgconn.CommandTag, error) {
return tx.Exec(ctx, string(schema.Contents))
}); err != nil {
log.Fatalf("unable to apply schema %q: %v", schema.Path, err)
}
Expand Down

0 comments on commit 65a9992

Please sign in to comment.