Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: use txn

d-bytebase42bbd880ccdf
diff --git a/backend/resources/postgres/sample_instance.go b/backend/resources/postgres/sample_instance.go
index 55b02463e1..5014c96915 100644
--- a/backend/resources/postgres/sample_instance.go
+++ b/backend/resources/postgres/sample_instance.go
@@ -203,15 +203,19 @@ func prepareSampleDatabaseIfNeeded(ctx context.Context, pgUser, host, port, data
sort.Strings(names)
+ tx, err := driver.GetDB().Begin()
+ if err != nil {
+ return err
+ }
+ defer tx.Rollback()
for _, name := range names {
if buf, err := fs.ReadFile(sampleFS, name); err != nil {
return errors.Wrapf(err, fmt.Sprintf("failed to read sample database data: %s", name))
- } else if _, err := driver.Execute(ctx, string(buf), false, db.ExecuteOptions{}); err != nil {
+ } else if _, err := tx.ExecContext(ctx, string(buf), false, db.ExecuteOptions{}); err != nil {
return errors.Wrapf(err, fmt.Sprintf("failed to load sample database data: %s", name))
}
}
-
- return nil
+ return tx.Commit()
}
func prepareSampleDatabase(ctx context.Context, pgUser, host, port, database string) error {