From ab06c9be70c2d2633317a2131375a8f8d3dba7aa Mon Sep 17 00:00:00 2001 From: Barnaby Keene Date: Sat, 21 Oct 2023 16:27:02 +0100 Subject: [PATCH] add back automatic migrations These weren't working with the test suite due to concurrency issues but it seems running them on the start hook mitigates this. --- internal/db/db.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/db/db.go b/internal/db/db.go index 1dc9008aa..5ee7df2d2 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -58,6 +58,15 @@ func newEntClient(lc fx.Lifecycle, db *sql.DB) (*ent.Client, error) { } lc.Append(fx.Hook{ + OnStart: func(ctx context.Context) error { + // Run create-only migrations after initialisation. + // This is done in tests and scripts too. + if err := client.Schema.Create(ctx); err != nil { + return fault.Wrap(err, fctx.With(ctx)) + } + + return nil + }, OnStop: func(ctx context.Context) error { defer cancel()